-
Notifications
You must be signed in to change notification settings - Fork 7
81 lines (70 loc) · 3.21 KB
/
Copy pathgoogle-cloudrun-docker.yml
File metadata and controls
81 lines (70 loc) · 3.21 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
71
72
73
74
75
76
77
78
79
80
81
# This workflow build and push a Docker container to Google Artifact Registry
# and deploy it on Cloud Run when a commit is pushed to the "main"
# branch.
#
# To configure this workflow:
#
# 1. Enable the following Google Cloud APIs:
#
# - Artifact Registry (artifactregistry.googleapis.com)
# - Cloud Run (run.googleapis.com)
# - IAM Credentials API (iamcredentials.googleapis.com)
#
# You can learn more about enabling APIs at
# https://support.google.com/googleapi/answer/6158841.
#
# 2. Create and configure a Workload Identity Provider for GitHub:
# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation.
#
# Depending on how you authenticate, you will need to grant an IAM principal
# permissions on Google Cloud:
#
# - Artifact Registry Administrator (roles/artifactregistry.admin)
# - Cloud Run Developer (roles/run.developer)
#
# You can learn more about setting IAM permissions at
# https://cloud.google.com/iam/docs/manage-access-other-resources
#
# 3. Change the values in the "env" block to match your values.
name: 'Build and Deploy to Cloud Run'
on:
push:
branches: [main]
jobs:
deploy:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/auth@v2
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' # 또는 WIF 방식
- uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.GCP_PROJECT }}
# BEGIN - Docker auth and build
#
# If you already have a container image, you can omit these steps.
- name: 'Docker Auth'
run: |
gcloud auth configure-docker ${{ secrets.GCP_REGION }}-docker.pkg.dev --quiet
- name: 'Build and Push Container'
run: |
IMAGE=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPOSITORY }}/${{ secrets.SERVICE_NAME }}:${{ github.sha }}
docker build -t $IMAGE .
docker push $IMAGE
- name: 'Deploy to Cloud Run'
run: |
IMAGE=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPOSITORY }}/${{ secrets.SERVICE_NAME }}:${{ github.sha }}
gcloud run deploy ${{ secrets.SERVICE_NAME }} \
--image $IMAGE \
--platform managed \
--region ${{ secrets.GCP_REGION }} \
--allow-unauthenticated \
--set-env-vars "JWT_SECRET=${{ secrets.JWT_SECRET }},REDIS_SECRET=${{ secrets.REDIS_SECRET }},POSTGRESQL_SECRET=${{ secrets.POSTGRESQL_SECRET }},SPRING_MAIL_SECRET=${{ secrets.SPRING_MAIL_SECRET }},GEMINI_SECRET=${{ secrets.GEMINI_SECRET }},GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }},GOOGLE_SECRET=${{ secrets.GOOGLE_SECRET }},NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }},NAVER_SECRET=${{ secrets.NAVER_SECRET }},KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }},KAKAO_SECRET=${{ secrets.KAKAO_SECRET }}"
# END - Docker auth and build
- name: Show Cloud Run URL
run: |
gcloud run services describe ${{ secrets.SERVICE_NAME }} \
--platform managed \
--region ${{ secrets.GCP_REGION }} \
--format="value(status.url)"