-
Notifications
You must be signed in to change notification settings - Fork 14
418 lines (403 loc) · 14.8 KB
/
deploy-happy-stack.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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
name: Deploy Happy
on: deployment
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_REPO: ${{ secrets.ECR_REPO }}/
permissions:
id-token: write
contents: write
deployments: write
jobs:
upgrade:
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-node@v2
with:
node-version: 15
- name: Configure AWS Prod Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment == 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_PROD_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment != 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
# Login to ECR needed solely to be able to retrieve cached layers
- name: Login to Prod ECR
uses: docker/login-action@v1
if: github.event.deployment.environment == 'prod'
with:
registry: ${{ secrets.ECR_REPO_PROD }}
- name: Login to ECR
uses: docker/login-action@v1
with:
registry: ${{ secrets.ECR_REPO }}
- uses: actions/checkout@v2
with:
ref: ${{ github.event.deployment.sha }}
fetch-depth: 1
- uses: avakar/set-deployment-status@v1
with:
state: in_progress
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update deployment
uses: chanzuckerberg/github-actions/.github/actions/deploy-happy-stack@deploy-happy-stack-v1.7.2
with:
tfe-token: ${{ secrets.TFE_TOKEN }}
stack-name: ${{ github.event.deployment.environment }}stack
operation: update
tag: ${{ github.event.deployment.payload.tag }}
env: ${{ github.event.deployment.environment }}
happy_version: "0.92.0"
- name: Invalidate CloudFront
env:
DEPLOYMENT_STAGE: ${{ github.event.deployment.environment }}
run: |
if [ "${DEPLOYMENT_STAGE}" == "stage" ]; then
DOMAIN_NAME=frontend.stage.single-cell.czi.technology
ALIAS=cellxgene.staging.single-cell.czi.technology
elif [ "${DEPLOYMENT_STAGE}" == "prod" ]; then
DOMAIN_NAME=frontend.production.single-cell.czi.technology
ALIAS=cellxgene.cziscience.com
else
DOMAIN_NAME=frontend.${DEPLOYMENT_STAGE}.single-cell.czi.technology
ALIAS=cellxgene.${DEPLOYMENT_STAGE}.single-cell.czi.technology
fi
DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[*].{id:Id,domain_name:Origins.Items[*].DomainName,alias:Aliases.Items[0]}[?contains(domain_name,'${DOMAIN_NAME}')&&alias=='${ALIAS}'].id" --output text)
aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION_ID} --paths /index.html
### Need to write success failure way because Github API doesn't allow doing
### "if: always(), state: ${{ success() }}:
- name: Set deployment status to failure if errors
uses: avakar/set-deployment-status@v1
if: failure()
with:
state: failure
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,commit,author,eventName,workflow,job,mention
mention: "here"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
if: failure() && github.ref == 'refs/heads/main'
github-tag-and-release:
runs-on: ubuntu-22.04
if: github.event.deployment.environment == 'prod'
needs:
- upgrade
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.deployment.sha }}
- name: Get most recent tag
id: "fetch_tag"
run: |
git config user.name github-actions
git config user.email github-actions@github.com
echo "PREVIOUS_TAG=$(git describe --tags $(git rev-list --tags=sha\* --max-count=1))" >> $GITHUB_OUTPUT
- name: Push Tag with latest prod commit SHA
uses: rickstaa/action-create-tag@v1
id: "tag_create"
with:
tag: ${{ github.event.deployment.payload.tag }}
tag_exists_error: false
- name: Build Changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v4
with:
fromTag: ${{ steps.fetch_tag.outputs.PREVIOUS_TAG }}
- name: Produce Github Release for Prod Deployments
uses: softprops/action-gh-release@v1
if: steps.tag_create.outputs.tag_exists == 'false'
with:
tag_name: ${{ github.event.deployment.payload.tag }}
body: ${{steps.build_changelog.outputs.changelog}}
e2e-logged-in-test:
timeout-minutes: 30
runs-on: ubuntu-22.04
needs:
- upgrade
steps:
- uses: actions/setup-node@v2
with:
node-version: "16.14.2"
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/checkout@v2
with:
ref: ${{ github.event.deployment.sha }}
fetch-depth: 1
- name: Configure AWS Prod Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment == 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_PROD_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment != 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- name: Run E2E Logged In tests
env:
DEPLOYMENT_STAGE: ${{ github.event.deployment.environment }}
### config.js set-up required due to transient test dependencies on API_URL
run: |
if [ "${DEPLOYMENT_STAGE}" == "stage" ]; then
export DEPLOYMENT_STAGE=staging
fi
if [ "${DEPLOYMENT_STAGE}" != "prod" ]; then
pip3 install -r scripts/smoke_tests/requirements.txt
python3 -m scripts.smoke_tests.setup
fi
cd frontend
npm ci
npx playwright install --with-deps
cp src/configs/${DEPLOYMENT_STAGE}.js src/configs/configs.js
DEBUG=pw:api npm run e2e-${DEPLOYMENT_STAGE}-logged-in
- uses: actions/upload-artifact@v2
if: always()
with:
name: logged-in-test-results
path: frontend/playwright-report/
retention-days: 30
### Need to write success failure way because Github API doesn't allow doing
### "if: always(), state: ${{ success() }}:
- name: Set deployment status to success if no errors
uses: avakar/set-deployment-status@v1
with:
state: success
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set deployment status to failure if errors
uses: avakar/set-deployment-status@v1
if: failure()
with:
state: failure
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run-e2e-tests:
timeout-minutes: 30
name: e2e-tests ${{ matrix.project }} ${{ matrix.shardCurrent }} of ${{ matrix.shardTotal }}
runs-on: ubuntu-22.04
needs:
- upgrade
strategy:
fail-fast: false
matrix:
# Only run Chrome for now, since GHA only has 250 workers and will cancel jobs if it runs out
project: [chromium]
shardCurrent: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
shardTotal: [10]
defaults:
run:
working-directory: frontend
steps:
- uses: actions/setup-node@v3
with:
node-version: "16.14.2"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 1800
- name: Login to ECR
uses: docker/login-action@v2
with:
registry: ${{ secrets.ECR_REPO }}
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install dependencies
run: |
npm ci
npx playwright install --with-deps
cp src/configs/local.js src/configs/configs.js
# Run E2E tests
- name: Run E2E tests
env:
CI: true
PROJECT: ${{ matrix.project }}
SHARD: ${{ matrix.shardCurrent }}/${{ matrix.shardTotal }}
DEPLOYMENT_STAGE: ${{ github.event.deployment.environment }}
run: |
if [ "${DEPLOYMENT_STAGE}" == "stage" ]; then
export DEPLOYMENT_STAGE=staging
fi
DEBUG=pw:api npm run e2e-${DEPLOYMENT_STAGE}-ci
- name: Upload FE test results as an artifact
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report ${{ matrix.project }} ${{ matrix.shardCurrent }} of ${{ matrix.shardTotal }}
path: /home/runner/work/single-cell-data-portal/single-cell-data-portal/frontend/playwright-report
retention-days: 14
- name: Upload blob report to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: all-blob-reports
path: /home/runner/work/single-cell-data-portal/single-cell-data-portal/frontend/blob-report
retention-days: 1
e2e-test:
if: always()
runs-on: ubuntu-latest
needs:
- run-e2e-tests
steps:
- name: Check result
run: |
passed="${{ needs.run-e2e-tests.result }}"
if [[ $passed == "success" ]]; then
echo "Shards passed"
exit 0
else
echo "Shards failed"
exit 1
fi
### Need to write success failure way because Github API doesn't allow doing
### "if: always(), state: ${{ success() }}:
- name: Set deployment status to success if no errors
uses: avakar/set-deployment-status@v1
with:
state: success
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set deployment status to failure if errors
uses: avakar/set-deployment-status@v1
if: failure()
with:
state: failure
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
functional-test:
runs-on: ubuntu-22.04
timeout-minutes: 30
needs:
- upgrade
steps:
- name: Configure AWS Prod Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment == 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_PROD_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment != 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- uses: actions/checkout@v2
with:
ref: ${{ github.event.deployment.sha }}
fetch-depth: 1
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Run functional test
env:
TFE_TOKEN: ${{ secrets.TFE_TOKEN }}
DEPLOYMENT_STAGE: ${{ github.event.deployment.environment }}
if: github.event.deployment.environment != 'prod'
run: |
if [ "${DEPLOYMENT_STAGE}" == "stage" ]; then
export DEPLOYMENT_STAGE=staging
fi
echo DEPLOYMENT_STAGE ${DEPLOYMENT_STAGE}
pip3 install -r tests/functional/requirements.txt
make functional-test
### Need to write success failure way because Github API doesn't allow doing
### "if: always(), state: ${{ success() }}:
- name: Set deployment status to success if no errors
uses: avakar/set-deployment-status@v1
with:
state: success
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set deployment status to failure if errors
uses: avakar/set-deployment-status@v1
if: failure()
with:
state: failure
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
performance-test:
runs-on: ubuntu-22.04
timeout-minutes: 30
needs:
- upgrade
steps:
- name: Configure AWS Prod Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment == 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_PROD_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
if: github.event.deployment.environment != 'prod'
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
# Login to ECR needed solely to be able to retrieve cached layers
- name: Login to Prod ECR
uses: docker/login-action@v1
if: github.event.deployment.environment == 'prod'
with:
registry: ${{ secrets.ECR_REPO_PROD }}
- name: Login to ECR
uses: docker/login-action@v1
with:
registry: ${{ secrets.ECR_REPO }}
- uses: actions/checkout@v2
with:
ref: ${{ github.event.deployment.sha }}
fetch-depth: 1
- name: Run performance test
env:
TFE_TOKEN: ${{ secrets.TFE_TOKEN }}
DEPLOYMENT_STAGE: ${{ github.event.deployment.environment }}
if: github.event.deployment.environment == 'prod'
run: |
echo "DOCKER_REPO=${DOCKER_REPO}" > .env.ecr
echo DEPLOYMENT_STAGE ${DEPLOYMENT_STAGE}
make prod-performance-test
status:
runs-on: ubuntu-22.04
if: ${{ always() }} # Ensures status is run after post-deploy tests, even if they fail
needs:
- performance-test
- e2e-logged-in-test
- e2e-test
- functional-test
steps:
- uses: martialonline/workflow-status@v4
id: check
- uses: 8398a7/action-slack@v3
with:
status: ${{ steps.check.outputs.status }}
fields: repo,commit,author,eventName,workflow,job,mention
mention: "here"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
if: steps.check.outputs.status == 'failure' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/prod')