Repository navigation
76 lines (68 loc) · 2.07 KB
/
Copy pathcloudrun-rollback.yml
File metadata and controls
76 lines (68 loc) · 2.07 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
---
name: Cloud Run Deploy with Auto Rollback
on:
workflow_call:
inputs:
gcp_registry_host:
required: true
type: string
IMAGE_NAME:
required: true
type: string
IMAGE_TAG:
required: true
type: string
GCP_REPOSITORY:
required: true
type: string
SERVICE_NAME:
required: true
type: string
REGION:
required: true
type: string
secrets:
GCP_PROJECT_ID:
required: true
GCP_SA_KEY:
required: true
outputs:
revision:
description: "Previous revision"
value: ${{ jobs.deploy.outputs.revision }}
service_name:
description: "Service name"
value: ${{ inputs.SERVICE_NAME }}
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
revision: ${{ steps.prev.outputs.revision }}
steps:
- name: Authenticate to GCP
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1
- name: Get current revision
id: prev
run: |
REVISION=$(gcloud run services describe ${{ inputs.SERVICE_NAME }} \
--region ${{ inputs.REGION }} \
--format="value(status.traffic[0].revisionName)")
echo "Current revision: $REVISION"
# Set for parent workflow (Environment file)
echo "revision=$REVISION" >> $GITHUB_OUTPUT
# 2️⃣ Deploy new image
- name: Deploy new image
id: deploy
run: |
IMAGE_URI="${{ inputs.gcp_registry_host }}/${{ secrets.GCP_PROJECT_ID }}/${{ inputs.GCP_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ inputs.IMAGE_TAG }}"
echo "🚀 Deploying $IMAGE_URI"
gcloud run deploy ${{ inputs.SERVICE_NAME }} \
--image "$IMAGE_URI" \
--region ${{ inputs.REGION }} \
--platform managed \
--quiet
...