forked from google-github-actions/deploy-cloudrun
399 lines (357 loc) · 13.2 KB
/
deploy-cloudrun-it.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
name: deploy-cloudrun Integration
on:
push:
branches:
- 'main'
pull_request:
jobs:
envvars:
name: with Env Vars
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- id: service
run: echo ::set-output name=service::run-envvars-$GITHUB_SHA
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 12.x
- name: Build Javascript
run: |-
npm ci
npm run build
- name: Create Service with one env var
id: deploy_1
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: ${{ steps.service.outputs.service }}
env_vars: TEST_ENV=TEST_VAR
- name: Setup Authentication with gcloud
uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
export_default_credentials: true
- name: Integration Tests
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_1.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
ENV: TEST_ENV=TEST_VAR
- name: Update Service with second env var
id: deploy_2
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: ${{ steps.service.outputs.service }}
env_vars: TEST_ENV2=TEST_VAR2
- name: Integration Tests # Check that config isn't overwritten
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_2.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
ENV: TEST_ENV=TEST_VAR,TEST_ENV2=TEST_VAR2
COUNT: 2
secret-manager:
name: with Secret Manager
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- id: service
run: echo ::set-output name=service::run-secret-manager-$GITHUB_SHA
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 12.x
- name: Build Javascript
run: |-
npm ci
npm run build
- name: Create Service with Secret Manager
id: deploy_1
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: ${{ steps.service.outputs.service }}
secrets: |
MY_SECRET=secret_value:latest
MY_SECOND_SECRET=new_value:latest
- name: Setup Authentication with gcloud
uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
export_default_credentials: true
- name: Integration Tests
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_1.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
SECRET_ENV: MY_SECRET=secret_value:latest,MY_SECOND_SECRET=new_value:latest
- name: Update service with mounted secret
id: deploy_2
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: ${{ steps.service.outputs.service }}
secrets: /api/secrets/my-secret=secret_value:latest
- name: Integration Tests # Check that config isn't overwritten
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_2.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
SECRET_ENV: MY_SECRET=secret_value:latest,MY_SECOND_SECRET=new_value:latest
SECRET_VOLUMES: /api/secrets/my-secret=secret_value:latest
COUNT: 2
yaml:
name: with YAML metadata
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- id: service
run: echo ::set-output name=service::run-yaml-$GITHUB_SHA
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 12.x
- name: Build Javascript
run: |-
npm ci
npm run build
- name: Set service name in metadata YAML
run: sed -i "s/test-basic-yaml/${{ steps.service.outputs.service }}/" ./tests/unit/service.basic.yaml
- name: Deploy Service
id: deploy
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
metadata: ./tests/unit/service.basic.yaml
- name: Setup Authentication with gcloud
uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
export_default_credentials: true
- name: Integration Tests
run: npm run e2e-tests
env:
URL: ${{ steps.deploy.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
metadata:
name: with full YAML metadata
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- id: service
run: echo ::set-output name=service::run-full-yaml-$GITHUB_SHA
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 12.x
- name: Build Javascript
run: |-
npm ci
npm run build
- name: Set service name in metadata YAML
run: |-
sed -i "s/run-full-yaml/${{ steps.service.outputs.service }}/" ./tests/unit/service.full.yaml
- name: Create service from metadata yaml
id: deploy_1
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
metadata: ./tests/unit/service.full.yaml
- name: Setup Authentication with gcloud
uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
export_default_credentials: true
- name: Integration Tests
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_1.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
PARAMS: "{\"cpu\": 2,\"memory\": \"1Gi\", \"containerConcurrency\": 20}"
ANNOTATIONS: "{\"run.googleapis.com/cloudsql-instances\": \"test-project:us-central1:my-test-instance\"}"
LABELS: "{\"test_label\": \"test_value\"}"
- name: Update service with new image
id: deploy_2
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: ${{ steps.service.outputs.service }}
- name: Integration Tests # Check that config isn't overwritten
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_2.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
PARAMS: "{\"cpu\": 2,\"memory\": \"1Gi\", \"containerConcurrency\": 20}"
ANNOTATIONS: "{\"run.googleapis.com/cloudsql-instances\": \"test-project:us-central1:my-test-instance\"}"
LABELS: "{\"test_label\": \"test_value\"}"
COUNT: 2
revision:
name: with Revision Name
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- id: service
run: echo ::set-output name=service::run-revision-name-$GITHUB_SHA
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 12.x
- name: Build Javascript
run: |-
npm ci
npm run build
- run: |-
sed -i "s/run-revision-name/${{ steps.service.outputs.service }}/" ./tests/unit/service.namedrevision.yaml
- name: Create service from metadata yaml
id: deploy_1
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
metadata: ./tests/unit/service.namedrevision.yaml
- name: Setup Authentication with gcloud
uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
export_default_credentials: true
- name: Integration Tests
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_1.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
REVISION: ${{ steps.service.outputs.service }}-001
- name: Update service revision name
run: |-
sed -i "s/-001/-002/" ./tests/unit/service.namedrevision.yaml
- name: Update service with new revision name
id: deploy_2
uses: ./
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
metadata: ./tests/unit/service.namedrevision.yaml
- name: Integration Tests # Check that config isn't overwritten
run: npm run e2e-tests
env:
URL: ${{ steps.deploy_2.outputs.url }}
PROJECT_ID: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
SERVICE: ${{ steps.service.outputs.service }}
REVISION: ${{ steps.service.outputs.service }}-002
COUNT: 2
name:
name: with Bad Inputs
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
env:
SERVICE_NAME: test-name
IMAGE_NAME: gcr.io/cloudrun/hello
TAG: hello
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 12.x
- name: Build Javascript
run: |-
npm ci
npm run build
- name: Name with uppercase letters
id: test1
uses: ./
continue-on-error: true
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: UPPERCASE-NAME
- name: Catch failure
run: |-
if [ ${{ steps.test1.outcome }} != 'failure' ]; then exit 1; fi
- name: Name with underscore
id: test2
uses: ./
continue-on-error: true
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: under_score
- name: Catch failure
run: |-
if [ ${{ steps.test2.outcome }} != 'failure' ]; then exit 1; fi
- name: Name starts with number
id: test3
uses: ./
continue-on-error: true
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: 1-number
- name: Catch failure
run: |-
if [ ${{ steps.test3.outcome }} != 'failure' ]; then exit 1; fi
- name: Name with env var
id: test4
uses: ./
continue-on-error: true
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/hello
service: $SERVICE_NAME
- name: Catch failure
run: |-
if [ ${{ steps.test4.outcome }} != 'failure' ]; then exit 1; fi
- name: Image with env var
id: test5
uses: ./
continue-on-error: true
timeout-minutes: 1
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: gcr.io/cloudrun/$TAG
service: test-service-name
- name: Catch failure
run: |-
if [ ${{ steps.test5.outcome }} != 'failure' ]; then exit 1; fi
- name: Image name as env var
id: test6
uses: ./
continue-on-error: true
with:
credentials: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_JSON }}
image: $IMAGE_NAME
service: test-service-name
- name: Catch failure
run: |-
if [ ${{ steps.test6.outcome }} != 'failure' ]; then exit 1; fi
cleanup:
name: Clean Up
if: ${{ (github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]') && always() }}
runs-on: ubuntu-latest
needs: [envvars, secret-manager, metadata, yaml, revision, name]
steps:
- uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.DEPLOY_CLOUDRUN_SA_KEY_B64 }}
project_id: ${{ secrets.DEPLOY_CLOUDRUN_PROJECT_ID }}
- name: Delete services
continue-on-error: true
run: |-
gcloud config set run/platform managed
gcloud config set run/region us-central1
gcloud run services delete run-full-yaml-$GITHUB_SHA --quiet
gcloud run services delete run-yaml-$GITHUB_SHA --quiet
gcloud run services delete run-envvars-$GITHUB_SHA --quiet
gcloud run services delete run-secret-manager-$GITHUB_SHA --quiet
gcloud run services delete run-revision-name-$GITHUB_SHA --quiet
gcloud run services delete test-service-name --quiet