Test: Rest Docs가 생성되지 않는 문제 테스트 #14
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 Stiky | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| env: | |
| PROJECT_ID: stiky-prod | |
| REGION: asia-northeast3 | |
| REPO_NAME: stiky-repo | |
| IMAGE_NAME: stiky-api | |
| jobs: | |
| build-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: 'read' | |
| id-token: 'write' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| # 1. Gradle 빌드 (Test -> RestDocs 생성 -> BootJar) | |
| - name: Build with Gradle | |
| run: | | |
| chmod +x gradlew | |
| ./gradlew clean bootJar | |
| # 2. GCP 인증 (Workload Identity Federation) | |
| - id: 'auth' | |
| name: 'Authenticate to Google Cloud' | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| workload_identity_provider: 'projects/795796283394/locations/global/workloadIdentityPools/stiky-pool/providers/stiky-provider' | |
| service_account: '[email protected]' | |
| # 3. Docker 인증 (Artifact Registry) | |
| - name: Docker Auth | |
| run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev | |
| # 4. Terraform Setup | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| # 5. Terraform 초기화 및 적용 (인프라 생성) | |
| # 주의: 첫 실행 시 Artifact Registry가 없으면 Docker Push가 실패할 수 있음. | |
| # 따라서 순서를: Terraform(Repo생성) -> Docker Push -> Terraform(Run배포) 로 하거나, | |
| # 로컬에서 Terraform을 한 번 돌려놓는 것이 가장 안전함. | |
| - name: Terraform Apply | |
| working-directory: ./infra | |
| run: | | |
| terraform init | |
| terraform apply -auto-approve \ | |
| -var="project_id=${{ env.PROJECT_ID }}" \ | |
| -var="region=${{ env.REGION }}" | |
| # 6. 이미지 빌드 & 푸시 | |
| # Terraform이 Repo를 만든 후 실행됨 | |
| - name: Build and Push Docker Image | |
| run: | | |
| docker build -t ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }} . | |
| docker build -t ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:latest . | |
| docker push ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
| docker push ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:latest | |
| # 7. Cloud Run 서비스 업데이트 (새 이미지 배포) | |
| - name: Deploy to Cloud Run | |
| uses: google-github-actions/deploy-cloudrun@v2 | |
| with: | |
| service: stiky-api | |
| region: ${{ env.REGION }} | |
| image: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }} |