test git action #41
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' | |
| cache: gradle # Gradle 캐싱 활성화 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
| - name: Cache Gradle dependencies | |
| uses: actions/cache@v4 # Gradle 의존성 캐시 설정 | |
| with: | |
| path: ~/.gradle/caches # Gradle 캐시 경로 | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} # Gradle 파일 해시값 기반 키 | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - 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-json | |
| # id: create-json | |
| # uses: jsdaniell/create-json@v1.2.2 | |
| # with: | |
| # name: "gce_sa_key.json" | |
| # json: ${{ secrets.GCE_SA_KEY }} | |
| - id: 'auth' | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| credentials_json: ${{ secrets.GCE_SA_KEY }} | |
| # Google Cloud CLI 설정 | |
| - name: Set up Google Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| with: | |
| project_id: ${{ secrets.GCE_PROJECT }} | |
| # Docker 인증 | |
| - name: Authenticate Docker to Google Cloud Container Registry (GCR) | |
| run: | | |
| gcloud auth configure-docker gcr.io | |
| # gcloud auth activate-service-account --key-file=./gce_sa_key.json | |
| # 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 |