-
Notifications
You must be signed in to change notification settings - Fork 5
179 lines (129 loc) · 6.34 KB
/
dev_deployment.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Build and Deploy to Cloud Run
on:
push:
branches:
- 'dev'
# paths:
# - 'Chart.yaml'
# workflow_call:
# outputs:
# GITHB_SHA:
# value: ${{ github.sha }} # Map the workflow outputs to job outputs
env:
PROJECT_ID: '${{ secrets.PROJECT_ID }}' # TODO: update Google Cloud project id.
GAR_LOCATION: '${{ secrets.GAR_LOCATION }}' # TODO: update Artifact Registry location
SLACK_WEBHOOK_URL: '${{ secrets.SLACK_WEBHOOK_URL}}'
SLACK_CHANNEL: '${{ secrets.GITHUBACTIONS_SLACK_CHANNEL }}'
jobs:
build:
# Add 'id-token' with the intended permissions for workload identity federation
permissions:
contents: write
id-token: write
runs-on: ubuntu-latest
# outputs:
# run: echo ${{ github.sha }}
environment: legacy-dev
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: dev
- name: Read VERSION file
id: getversion
# run: echo "::set-output name=version::$(cat Chart.yaml)"
run: echo "version=$(cat Chart.yaml)" >> $GITHUB_OUTPUT
# To be used in Production pipeline
# - uses: "marvinpinto/action-automatic-releases@latest"
# with:
# repo_token: "${{ secrets.GITHUB_TOKEN }}"
# automatic_release_tag: ${{ steps.getversion.outputs.version }}
# prerelease: false
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v0'
with:
token_format: 'access_token'
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}'
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}'
- name: Login to GAR
id: garlogin
uses: docker/login-action@v2
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.PROJECT_ID }}
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Build and Push Container
id: build
shell: bash
env:
GAR_LOCATION: ${{ secrets.GAR_LOCATION }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
GAR_NAME: ${{ secrets.GAR_NAME_WEB }}
SKIP_PREFLIGHT_CHECK: ${{ secrets.SKIP_PREFLIGHT_CHECK }}
NODE_ENV: ${{ secrets.NODE_ENV }}
REACT_APP_HOTJAR_CODE: ${{ secrets.REACT_APP_HOTJAR_CODE }}
REACT_APP_HOTJAR_CODE_VERSION: ${{ secrets.REACT_APP_HOTJAR_CODE_VERSION }}
REACT_APP_METADATA_CATALOG_URL: ${{ secrets.REACT_APP_METADATA_CATALOG_URL }}
REACT_APP_NEWSLETTER_EXAMPLE_URL: ${{ secrets.REACT_APP_NEWSLETTER_EXAMPLE_URL }}
REACT_APP_TERMS_AND_CONDITIONS_URL: ${{ secrets.REACT_APP_TERMS_AND_CONDITIONS_URL }}
REACT_APP_GATEWAY_PRIVACY_POLICY_URL: ${{ secrets.REACT_APP_GATEWAY_PRIVACY_POLICY_URL }}
REACT_APP_FIVE_SAFES_URL: ${{ secrets.REACT_APP_FIVE_SAFES_URL }}
run: |-
docker build -t '${{ env.GAR_LOCATION }}'-docker.pkg.dev/'${{ env.PROJECT_ID }}'/'${{ env.GAR_NAME }}'/${{ steps.getversion.outputs.version }}:${{ github.sha }} -t '${{ env.GAR_LOCATION }}'-docker.pkg.dev/'${{ env.PROJECT_ID }}'/'${{ env.GAR_NAME }}'/${{ steps.getversion.outputs.version }}:latest --build-arg SKIP_PREFLIGHT_CHECK='${{ env.SKIP_PREFLIGHT_CHECK }}' --build-arg NODE_ENV='${{ env.NODE_ENV }}' --build-arg REACT_APP_HOTJAR_CODE='${{ env.REACT_APP_HOTJAR_CODE }}' --build-arg REACT_APP_HOTJAR_CODE_VERSION='${{ env.REACT_APP_HOTJAR_CODE_VERSION }}' --build-arg REACT_APP_METADATA_CATALOG_URL='${{ env.REACT_APP_METADATA_CATALOG_URL }}' --build-arg REACT_APP_NEWSLETTER_EXAMPLE_URL='${{ env.REACT_APP_NEWSLETTER_EXAMPLE_URL }}' --build-arg REACT_APP_TERMS_AND_CONDITIONS_URL='${{ env.REACT_APP_TERMS_AND_CONDITIONS_URL }}' --build-arg REACT_APP_GATEWAY_PRIVACY_POLICY_URL='${{ env.REACT_APP_GATEWAY_PRIVACY_POLICY_URL }}' --build-arg REACT_APP_FIVE_SAFES_URL='${{ env.REACT_APP_FIVE_SAFES_URL }}' --cache-from gcr.io/hdruk-gateway-dev/hdruk-gateway-web:dev ./
docker push --all-tags '${{ env.GAR_LOCATION }}'-docker.pkg.dev/'${{ env.PROJECT_ID }}'/'${{ env.GAR_NAME }}'/${{ steps.getversion.outputs.version }}
- name: Build Notification
id: buildnotificationsent
uses: act10ns/slack@v2
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: ${{ env.SLACK_CHANNEL }}
message: Building {{ env.GITHUB_REF_NAME }} branch
if: always()
# END - Docker auth and build
# Deployment please don't modify anything here as the infrastructure is controlled by terraform any changes here please agree with chris and reuben
deploy:
needs: build
permissions:
contents: write
id-token: write
runs-on: ubuntu-latest
environment: legacy-dev
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: dev
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v0'
with:
token_format: 'access_token'
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}'
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}'
- name: Read VERSION file
id: getversion
# run: echo "::set-output name=version::$(cat Chart.yaml)"
run: echo "version=$(cat Chart.yaml)" >> $GITHUB_OUTPUT
- name: Deploy to Cloud Run
uses: actions-hub/gcloud@master
id: deploy
env:
PROJECT_ID: '${{ secrets.PROJECT_ID }}'
GAR_LOCATION: '${{ secrets.GAR_LOCATION }}'
GAR_NAME: '${{ secrets.GAR_NAME_WEB }}'
SERVICE_NAME: '${{ secrets.SERVICE_NAME_WEB }}'
SERVICE_REGION: '${{ secrets.SERVICE_REGION_WEB }}'
with:
args: run services update '${{ env.SERVICE_NAME }}' --image='${{ env.GAR_LOCATION }}'-docker.pkg.dev/'${{ env.PROJECT_ID }}'/'${{ env.GAR_NAME }}'/${{ steps.getversion.outputs.version }}:${{ github.sha }} --region='${{ env.SERVICE_REGION }}' --project='${{ env.PROJECT_ID }}'
- name: Deploy Notification
id: deploynotificationsent
uses: act10ns/slack@v2
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: ${{ env.SLACK_CHANNEL }}
message: Deploying {{ env.GITHUB_REF_NAME }} branch
if: always()
# If required, use the Cloud Run url output in later steps