Hotfix : gcp로 서버 변경 #177
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: Deploy to GCP | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| # Java 설정 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| # .env / FCM 파일 생성 (빌드 전에 먼저 생성) | |
| - name: Create .env file | |
| run: echo "${{ secrets.ENV_FILE }}" > .env | |
| - name: Create FCM key file | |
| run: echo "${{ secrets.FCM_SERVICE_ACCOUNT }}" > src/main/resources/firebase-adminsdk.json | |
| # Gradle 빌드 (테스트 스킵) | |
| - name: Build with Gradle | |
| run: | | |
| chmod +x gradlew | |
| ./gradlew clean build -x test | |
| # GCP 인증 | |
| - name: Authenticate to GCP | |
| uses: google-github-actions/auth@v1 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| # Docker 이미지 빌드 & 푸시 | |
| - name: Build and Push Docker image | |
| run: | | |
| gcloud auth configure-docker | |
| docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/my-app:${{ github.sha }} . | |
| docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/my-app:${{ github.sha }} | |
| # 배포 | |
| - name: Deploy to Compute Engine | |
| run: | | |
| gcloud compute ssh [VM이름] --zone=[존] --command=" | |
| docker pull gcr.io/${{ secrets.GCP_PROJECT_ID }}/my-app:${{ github.sha }} && | |
| docker stop my-app || true && | |
| docker rm my-app || true && | |
| docker run -d --name my-app -p 8080:8080 \ | |
| gcr.io/${{ secrets.GCP_PROJECT_ID }}/my-app:${{ github.sha }} | |
| " |