-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (51 loc) · 1.9 KB
/
deploy.yaml
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
name: Push Backend Image to GAR
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
token_format: access_token
workload_identity_provider: 'projects/660544013770/locations/global/workloadIdentityPools/gh-pool/providers/provider-github'
service_account: 'gh-actions@yorisoi.iam.gserviceaccount.com'
- name: Authorize Docker
id: docker-auth
uses: docker/login-action@v3
with:
username: 'oauth2accesstoken'
password: ${{ steps.auth.outputs.access_token }}
registry: asia-northeast1-docker.pkg.dev
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: asia-northeast1-docker.pkg.dev/yorisoi/yorisoi-backend/main:latest
file: ./cloudrun/Dockerfile
context: ./
- name: Download Cloud Run Service YAML
run: |
gcloud run services describe yorisoi-backend --format yaml --region asia-northeast1 > ./service.yaml
# replace github_sha field to latest commit sha. Changing spec.template is required to deploy new revision.
# reference: https://cloud.google.com/run/docs/deploying?hl=ja#revision -- check yaml tab.
- name: Change some property of service.yaml
run: |
sed -i "s/github_sha: .*/github_sha: ${{ github.sha }}/g" ./service.yaml
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
region: "asia-northeast1"
metadata: "./service.yaml"