-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (99 loc) · 3.2 KB
/
Copy pathapp-deploy-to.yaml
File metadata and controls
109 lines (99 loc) · 3.2 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Reusable Cloud Run Deploy
on:
workflow_call:
inputs:
environment:
required: true
type: string
image-tag:
required: true
type: string
deployment-tag:
required: true
type: string
tag-only:
required: false
type: boolean
default: false
working-directory:
required: false
type: string
default: "."
service-name-prefix:
required: false
type: string
default: ""
version:
required: false
type: string
default: "not-set"
deployment-env:
required: false
type: string
default: "not-set"
regions:
required: false
type: string
description: "Comma-separated regions to deploy to (overrides the default regions)"
default: ""
outputs:
urls:
description: "Deployed service URLs"
value: ${{ jobs.deploy.outputs.urls }}
primary_url:
description: "Primary service URL"
value: ${{ jobs.deploy.outputs.urls }}
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
contents: read
id-token: write
outputs:
urls: ${{ steps.deploy.outputs.urls }}
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- name: Google Auth
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ vars.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GOOGLE_SERVICE_ACCOUNT }}
token_format: 'access_token'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- name: Deploy
id: deploy
run: |
SERVICE_PREFIX="${{ inputs.service-name-prefix }}"
BASE_NAME="${{vars.SERVICE_NAME}}"
COMBINED_SERVICE_NAME="${SERVICE_PREFIX:+$SERVICE_PREFIX-}${BASE_NAME}"
# Use provided regions if available, otherwise fall back to vars.REGIONS
DEPLOY_REGIONS="${{ inputs.regions }}"
if [[ -z "$DEPLOY_REGIONS" ]]; then
DEPLOY_REGIONS="${{ vars.REGIONS }}"
fi
URLS=""
for region in $DEPLOY_REGIONS; do
SERVICE_URL=$(gcloud run deploy ${COMBINED_SERVICE_NAME} \
--image ${{ inputs.image-tag }} \
--update-env-vars "ENVIRONMENT=${{ inputs.deployment-env }},NEXT_PUBLIC_APP_ENV=${{ inputs.deployment-env }},NEXT_PUBLIC_RELEASE=${{ inputs.version }}" \
--region $region \
--project ${{ vars.PROJECT_ID }} \
--platform managed \
--tag ${{ inputs.deployment-tag }} \
--format="value(status.url)")
# Add URL to the list
URLS="${URLS}${URLS:+,}${SERVICE_URL}"
if [[ "${{ inputs.tag-only }}" != "true" ]]; then
gcloud run services update-traffic ${COMBINED_SERVICE_NAME} \
--region $region \
--project ${{ vars.PROJECT_ID }} \
--platform managed \
--to-tags ${{ inputs.deployment-tag }}=100
fi
done
# Output the URLs
echo "urls=${URLS}" >> $GITHUB_OUTPUT