refactor code #35
Workflow file for this run
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: develop server CD with Gradle | |
| on: | |
| push: | |
| branches: | |
| - develop/be | |
| - chore/#82-zero-downtime-deployment | |
| paths: | |
| - backend/** | |
| - .github/workflows/** | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
| - name: make application.properties | |
| run: | | |
| cd ./backend/src/main/resources | |
| echo "${{ secrets.APPLICATION_PROD_DEV }}" > ./application.properties | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./backend/gradlew | |
| - name: Build with Gradle | |
| run: | | |
| cd backend | |
| ./gradlew clean build -x test | |
| - name: create GCE json key | |
| run: | | |
| echo "${{ secrets.GCE_SA_KEY }}" > ./gce_sa_key.json | |
| # Google Cloud CLI 설정 | |
| - name: Set up Google Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v1 | |
| with: | |
| service_account_key: ./gce_sa_key.json | |
| project_id: ${{ secrets.GCE_PROJECT }} | |
| # Docker 인증 | |
| - name: Authenticate Docker to Google Cloud Container Registry (GCR) | |
| run: | | |
| gcloud auth activate-service-account --key-file=./gce_sa_key.json | |
| gcloud auth configure-docker gcr.io | |
| # Docker 이미지 빌드 및 GCR 업로드 | |
| - name: Build and Push Docker Image | |
| run: | | |
| cd backend | |
| docker build -t ${{ secrets.DOCKER_IMAGE_DEV }} . | |
| docker push ${{ secrets.DOCKER_IMAGE_DEV }} | |
| # VM에서 컨테이너 실행 | |
| - name: Update Container on VM | |
| run: | | |
| gcloud compute ssh ${{ secrets.GCE_INSTANCE_DEV }} --zone=${{ secrets.GCP_REGION }} --command=" | |
| gcloud auth configure-docker | |
| gcloud auth activate-service-account --key-file=/home/wabi241202/gce_sa_key.json | |
| sudo usermod -aG docker $USER | |
| newgrp docker | |
| docker pull ${{ secrets.DOCKER_IMAGE_DEV }} | |
| docker rm -f moadong | |
| docker run -d --name moadong -v /home/wabi241202/gce_sa_key.json:/app/gce_sa_key.json -p 8080:8080 ${{ secrets.DOCKER_IMAGE_DEV }}" | |
| - name: Docker remove unused images | |
| run: docker image prune -af | |
| - name: Check running containers | |
| run: docker ps -a | |
| # - name: Docker build | |
| # run: | | |
| # cd backend | |
| # docker login -u ${{ secrets.SERVER_DOCKER_USERNAME }} -p ${{ secrets.SERVER_DOCKER_PASSWORD }} | |
| # docker build -t app . | |
| # docker tag app ${{ secrets.SERVER_DOCKER_USERNAME }}/moadong_be:latest | |
| # docker push ${{ secrets.SERVER_DOCKER_USERNAME }}/moadong_be:latest |