-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (57 loc) · 2.81 KB
/
deploy.yml
File metadata and controls
70 lines (57 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Deploy to Cloud Run
on:
workflow_run:
workflows: ["Backend CI (Gradle Test)"]
types: [completed]
permissions:
contents: read
id-token: write
concurrency:
group: backend-deploy-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'dev' }}
runs-on: ubuntu-latest
steps:
- name: Checkout (same commit as CI)
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Setup Java 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: gradle
- name: Grant execute permission for Gradle
run: chmod +x ./gradlew
- name: Build (bootJar, skip tests)
run: ./gradlew clean bootJar -x test
- name: Authenticate to GCP
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_DEPLOYER_SA }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{ secrets.GCP_REGION }}-docker.pkg.dev --quiet
- name: Build and push Docker image
run: |
SHA="${{ github.event.workflow_run.head_sha }}"
IMAGE="${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.AR_REPO }}/${{ secrets.SERVICE_NAME }}:${SHA}"
echo "IMAGE=$IMAGE" >> $GITHUB_ENV
docker build -t "$IMAGE" .
docker push "$IMAGE"
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ secrets.SERVICE_NAME }} \
--image "${{ env.IMAGE }}" \
--region ${{ secrets.GCP_REGION }} \
--platform managed \
--allow-unauthenticated \
--min-instances 1 \
--set-env-vars "SPRING_PROFILES_ACTIVE=prod" \
--set-secrets "DB_HOST=db-host:latest,DB_PORT=db-port:latest,DB_NAME=db-name:latest,DB_USERNAME=db-username:latest,DB_PASSWORD=db-password:latest,REDIS_HOST=redis-host:latest,REDIS_PORT=redis-port:latest,JWT_SECRET=jwt-secret:latest,KAKAO_CLIENT_ID=kakao-client-id:latest,KAKAO_CLIENT_SECRET=kakao-client-secret:latest,NAVER_CLIENT_ID=naver-client-id:latest,NAVER_CLIENT_SECRET=naver-client-secret:latest,GOOGLE_CLIENT_ID=google-client-id:latest,GOOGLE_CLIENT_SECRET=google-client-secret:latest,GCS_PROJECT_ID=gcs-project-id:latest,GCS_BUCKET=gcs-bucket:latest,GCS_CREDENTIALS_JSON=gcs-credentials-json:latest,INTERNAL_API_TOKEN=internal-api-token:latest,OPENROUTER_API_KEY=openrouter-api-key:latest" \
--project ${{ secrets.GCP_PROJECT_ID }}