-
Notifications
You must be signed in to change notification settings - Fork 0
331 lines (320 loc) · 11.7 KB
/
integration-deployment.yml
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
name: CI/CD
on:
push:
branches:
- 'main'
env:
HUGO_VERSION: 0.125.3
DASH_CONTAINER_REGISTRY_LOCATION: europe-west1
DASH_CONTAINER_REGISTRY: cr-webapps
DASH_CONTAINER_NAME: dashboard
DASH_CR_LOCATION: europe-west1
DASH_CR_SERVICE: dashboard
jobs:
# Path Filtering
filter-paths:
name: Filter Paths
runs-on: ubuntu-latest
outputs:
homepage: ${{ steps.filter.outputs.homepage }}
dashboard: ${{ steps.filter.outputs.dashboard }}
functions: ${{ steps.filter.outputs.functions }}
permissions:
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Filter Paths
id: filter
uses: dorny/paths-filter@v3.0.2
with:
filters: |
homepage:
- 'homepage/**'
dashboard:
- 'dashboard/**'
functions:
- 'functions/**'
# START: Cloud Functions
func-lint-typecheck:
name: 'Functions: Lint & Type Check'
runs-on: ubuntu-latest
needs: filter-paths
if: needs.filter-paths.outputs.functions == 'true'
permissions:
checks: write
pull-requests: read
contents: read
defaults:
run:
working-directory: functions
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Nodejs Environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
cache-dependency-path: 'functions/yarn.lock'
- name: Install Dependencies
run: yarn --frozen-lockfile
- name: Lint
run: yarn lint:nofix --output-file eslint_report.json --format json
continue-on-error: true
- name: Type Check
run: yarn tsc --noEmit > typescript.log
continue-on-error: true
- name: Annotate Code
uses: DerLev/eslint-annotations@v2
with:
eslint-report: functions/eslint_report.json
typescript-log: functions/typescript.log
github-token: ${{ secrets.GITHUB_TOKEN }}
error-on-warn: true
status-check-name: 'Functions: Annotations'
fail-in-pr: false
add-notice-with-url: false
# END: Cloud Functions
# START: Homepage - Hugo + React
home-lint-typecheck:
name: 'Homepage: Lint & Type Check'
runs-on: ubuntu-latest
needs: filter-paths
if: needs.filter-paths.outputs.homepage == 'true'
permissions:
checks: write
pull-requests: read
contents: read
defaults:
run:
working-directory: homepage
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Nodejs Environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
cache-dependency-path: 'homepage/yarn.lock'
- name: Install Dependencies
run: yarn --frozen-lockfile
- name: Lint
run: yarn lint:nofix --output-file eslint_report.json --format json
continue-on-error: true
- name: Type Check
run: yarn tsc > typescript.log
continue-on-error: true
- name: Annotate Code
uses: DerLev/eslint-annotations@v2
with:
eslint-report: homepage/eslint_report.json
typescript-log: homepage/typescript.log
github-token: ${{ secrets.GITHUB_TOKEN }}
error-on-warn: true
status-check-name: 'Homepage: Annotations'
fail-in-pr: false
add-notice-with-url: false
home-build-deploy:
name: 'Homepage: Build & Deploy Site on Firebase Hosting'
runs-on: ubuntu-latest
needs: [home-lint-typecheck]
permissions:
contents: read
id-token: write
environment: Production
defaults:
run:
working-directory: homepage
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: false
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${{ env.HUGO_VERSION }}/hugo_extended_${{ env.HUGO_VERSION }}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Setup Nodejs Environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
cache-dependency-path: 'homepage/yarn.lock'
- name: Install Yarn Dependencies
run: yarn --frozen-lockfile
- name: Build React Client Components
run: yarn build
- name: Build Hugo Site
run: hugo --gc
- name: Delete Original Image Files
run: ./delete-droplist-content.sh
- name: Generate Workbox Service Worker
run: yarn gulp:workbox
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_SA_EMAIL }}
- name: Get GCP Credentials File
id: creds
run: echo "cerdsJson=$(cat ${{ steps.auth.outputs.credentials_file_path }})" >> "$GITHUB_OUTPUT"
- name: Deploy Site on Firebase Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ steps.creds.outputs.cerdsJson }}
channelId: live
projectId: ${{ vars.GCP_PROJECT_ID }}
entryPoint: homepage/
# END: Homepage - Hugo + React
# START: Cloud Run Service dashboard
dash-lint-typecheck:
name: 'Dashboard: Lint & Type Check'
runs-on: ubuntu-latest
needs: filter-paths
if: needs.filter-paths.outputs.dashboard == 'true'
permissions:
checks: write
pull-requests: read
contents: read
defaults:
run:
working-directory: dashboard
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Nodejs Environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
cache-dependency-path: 'dashboard/yarn.lock'
- name: Install Dependencies
run: yarn --frozen-lockfile
- name: Lint
run: yarn lint:nofix --output-file eslint_report.json --format json
continue-on-error: true
- name: Type Check
run: yarn tsc > typescript.log
continue-on-error: true
- name: Annotate Code
uses: DerLev/eslint-annotations@v2
with:
eslint-report: dashboard/eslint_report.json
typescript-log: dashboard/typescript.log
github-token: ${{ secrets.GITHUB_TOKEN }}
error-on-warn: true
status-check-name: 'Dashboard: Annotations'
fail-in-pr: false
add-notice-with-url: false
dash-delete-outdated-ar:
name: 'Dashboard: Delete outdated Container Images from Artifact Registry'
runs-on: ubuntu-latest
needs: dash-lint-typecheck
permissions:
id-token: write
steps:
- name: Prevent Auth from printing warning
run: echo "Shut up!" > dont_warn.txt
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_SA_EMAIL }}
- name: Cleanup Artifact Registry
uses: docker://europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli
with:
args: >-
-repo=${{ env.DASH_CONTAINER_REGISTRY_LOCATION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${{ env.DASH_CONTAINER_REGISTRY }}/${{ env.DASH_CONTAINER_NAME }}
-keep=6
-tag-filter-any=.*
dash-delete-outdated-cr:
name: 'Dashboard: Delete outdated Cloud Run Revisions'
runs-on: ubuntu-latest
needs: dash-lint-typecheck
permissions:
id-token: write
steps:
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_SA_EMAIL }}
token_format: access_token
access_token_lifetime: 60s
create_credentials_file: false
- name: Only leave the 2 most recent Revisions
uses: actions/github-script@v7
with:
script: |
const response = await fetch("https://run.googleapis.com/v2/projects/${{ vars.GCP_PROJECT_ID }}/locations/${{ env.DASH_CR_LOCATION }}/services/${{ env.DASH_CR_SERVICE }}/revisions", { headers: { 'Authorization': "Bearer ${{ steps.auth.outputs.access_token }}" } })
.then(res => res.json());
const toBeDeleted = response.revisions.sort((a, b) => (new Date(b.createTime) - new Date(a.createTime))).slice(2);
const deletionPromises = [];
for(const revision of toBeDeleted) {
deletionPromises.push(fetch(`https://run.googleapis.com/v2/${revision.name}`, { method: 'DELETE', headers: { 'Authorization': "Bearer ${{ steps.auth.outputs.access_token }}" } }));
}
await Promise.all(deletionPromises);
dash-build-deploy:
name: 'Dashboard: Build Container & Deploy on Cloud Run'
runs-on: ubuntu-latest
needs: [dash-delete-outdated-ar, dash-delete-outdated-cr]
permissions:
contents: read
id-token: write
environment: Production Dashboard
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_SA_EMAIL }}
token_format: access_token
access_token_lifetime: 600s
- name: Login to GCP Artifact Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DASH_CONTAINER_REGISTRY_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Extract Metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DASH_CONTAINER_REGISTRY_LOCATION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${{ env.DASH_CONTAINER_REGISTRY }}/${{ env.DASH_CONTAINER_NAME }}
tags: |
type=raw,value=latest
type=sha,prefix=,format=long
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: dashboard/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.DASH_CONTAINER_NAME }}
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ env.DASH_CONTAINER_NAME }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Get short commit SHA
id: commit_sha
uses: actions/github-script@v7
with:
script: |
const sha = "${{ github.sha }}"
const shortSha = sha.substring(0, 7)
core.setOutput('shortSha', shortSha)
- name: Create new Cloud Run Revision
run: gcloud run deploy ${{ env.DASH_CR_SERVICE }} --image ${{ env.DASH_CONTAINER_REGISTRY_LOCATION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${{ env.DASH_CONTAINER_REGISTRY }}/${{ env.DASH_CONTAINER_NAME }}:${{ github.sha }} --region ${{ env.DASH_CR_LOCATION }} --tag sha-${{ steps.commit_sha.outputs.shortSha }}
# END: Cloud Run Service dashboard