Merge pull request #8 from swyp-app-team-4/feat#3 #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: boombimapi CI/CD | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # (1) 깃 체크아웃 | |
| - name: Check out repository | |
| uses: actions/checkout@v2 | |
| # (2) .env 파일 생성 | |
| - name: Create env files | |
| run: | | |
| mkdir -p env | |
| echo "${{ secrets.ENV_VARS }}" > env/prod.env | |
| # (3) JDK 17 설치 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v2 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| # (4) gradlew 실행 권한 부여 | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| # (5) Gradle 빌드 (테스트 제외) | |
| - name: Build with Gradle (skip tests) | |
| run: ./gradlew clean build -x test | |
| # (6) Docker 이미지 빌드 | |
| - name: Build Docker Image | |
| run: | | |
| docker build -t ${{ secrets.DOCKERFILE_USERNAME }}/${{ secrets.DOCKERFILE_REPO_NAME }}:latest . | |
| # (7) DockerHub 로그인 | |
| - name: DockerHub Login | |
| run: | | |
| echo "${{ secrets.DOCKERFILE_PASSWORD }}" | docker login -u "${{ secrets.DOCKERFILE_USERNAME }}" --password-stdin | |
| # (8) Docker 이미지 푸시 | |
| - name: Push Docker Image | |
| run: | | |
| docker push ${{ secrets.DOCKERFILE_USERNAME }}/${{ secrets.DOCKERFILE_REPO_NAME }}:latest | |
| # (9) NCP 인스턴스에 boombim 디렉토리 생성 | |
| - name: Create directory on NCP Instance | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| mkdir -p /home/ubuntu/boombim | |
| # (10) docker-compose.yml 복사 | |
| - name: Copy docker-compose.yml to NCP Instance | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| source: "docker-compose.yml" | |
| target: "/home/ubuntu/boombim" | |
| # (11) .env 파일 복사 | |
| - name: Copy .env file to NCP Instance | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| source: "env/prod.env" | |
| target: "/home/ubuntu/boombim/.env" | |
| # (12) Docker 컨테이너 실행 | |
| - name: Deploy on NCP Instance | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| cd /home/ubuntu/boombim | |
| docker-compose down || true | |
| docker image prune -a -f | |
| docker pull ${{ secrets.DOCKERFILE_USERNAME }}/${{ secrets.DOCKERFILE_REPO_NAME }}:latest | |
| docker-compose up -d |