-
Notifications
You must be signed in to change notification settings - Fork 18
238 lines (209 loc) · 7.32 KB
/
deploy.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
# This workflow deploys Napari Hub to staging and production and runs lighthouse-ci on the production deployment.
name: Deploy Changes to Cluster
on:
push:
branches:
- main
tags:
- 'v*'
# https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
permissions:
id-token: write
contents: read
env:
FIXTURES_CACHE_KEY: e2e-fixtures-${{ github.run_id }}-${{ github.run_attempt }}
jobs:
prod:
name: deploy to production
runs-on: ubuntu-latest
if: github.repository == 'chanzuckerberg/napari-hub' && startsWith(github.ref, 'refs/tags/v')
steps:
- 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: 1200
- name: Login to ECR
uses: docker/login-action@v1
with:
registry: ${{ secrets.ECR_REPO }}
- name: Set up docker build environment
run: |
echo DOCKER_TAG=${GITHUB_REF_NAME} >> $GITHUB_ENV
- name: Deploy Changes to Prod
uses: chanzuckerberg/github-actions/.github/actions/[email protected]
env:
ENV: prod
with:
stack-name: 'prod'
create-tag: 'true'
tag: ${{ env.DOCKER_TAG }}
tfe-token: ${{ secrets.TFE_TOKEN }}
env: 'prod'
operation: 'create-or-update'
staging:
name: deploy to staging
runs-on: ubuntu-latest
if: github.repository == 'chanzuckerberg/napari-hub' && github.ref == 'refs/heads/main'
steps:
- 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: 1200
- name: Login to ECR
uses: docker/login-action@v1
with:
registry: ${{ secrets.ECR_REPO }}
- name: Set up docker build environment
run: |
echo STACK_NAME=${GITHUB_REF_NAME} >> $GITHUB_ENV
echo DOCKER_TAG=${GITHUB_REF_NAME} >> $GITHUB_ENV
- name: Deploy Changes to Staging
uses: chanzuckerberg/github-actions/.github/actions/[email protected]
env:
ENV: staging
with:
stack-name: 'staging'
create-tag: 'true'
tag: ${{ env.DOCKER_TAG }}
tfe-token: ${{ secrets.TFE_TOKEN }}
env: 'staging'
operation: 'create-or-update'
lighthouse-ci:
runs-on: ubuntu-latest
needs: prod
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20.5.x
- run: npm install -g @lhci/[email protected]
- name: Run Lighthouse
run: lhci autorun --collect.url=https://www.napari-hub.org/ --output-dir=./.lighthouseci --upload.artifacts.ignoreFailure=true
- name: Upload Lighthouse reports
uses: actions/upload-artifact@v3
with:
name: lighthouse-reports
path: ./.lighthouseci/
prod-e2e-setup:
name: Production E2E Tests Setup
defaults:
run:
working-directory: frontend/
runs-on: ubuntu-latest
needs: prod # Needs the production deploy to happen first before E2E tests can be ran
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.5.x
- name: Get Yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
# cache both yarn-lock and node_modules
- name: Setup Yarn cache
uses: actions/cache@v3
id: yarn-cache
with:
path: |
**/node_modules
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
# --prefer-offline forces yarn to use cache if available
- name: Install dependencies with yarn
# if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --prefer-offline --frozen-lockfile
- name: Cache playwright binaries
uses: actions/cache@v3
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: playwright-${{ hashFiles('**/yarn.lock') }}
- name: Install playwright
# if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
- name: Setting up local build cache
uses: actions/cache@v3
with:
path: frontend/.next
key: local-build-${{ hashFiles('**/next.config.js') }}-${{ hashFiles('frontend/src') }}-${{ hashFiles('**/yarn.lock') }}
- name: Setting up fixture cache
uses: actions/cache@v3
with:
path: frontend/e2e/fixtures
key: ${{ env.FIXTURES_CACHE_KEY }}
- name: Fetch fixture data
env:
ENV: prod
run: node scripts/fetch-e2e-fixtures
prod-e2e:
name: E2E tests ${{ matrix.browser }} ${{ matrix.shardCurrent }} / ${{ matrix.shardTotal }}
defaults:
run:
working-directory: frontend/
runs-on: ubuntu-latest
needs: prod-e2e-setup
concurrency:
group: ${{ github.ref }}-${{ matrix.browser }}-${{ matrix.shardCurrent }}-${{ matrix.shardTotal }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
# browser: [chrome, firefox, safari]
browser: [chrome]
shardCurrent: [1, 2, 3, 4, 5]
shardTotal: [5]
steps:
- name: 25 minutes wait # Wait 25 mins before running E2E tests to let deployment changes on AWS propigate
run: sleep 1500 # Sleep time in seconds (25 minutes * 60 seconds = 1500 seconds)
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.5.x
- name: Get Yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
# cache both yarn-lock and node_modules
- name: Load yarn cache
uses: actions/cache@v3
id: yarn-cache
with:
path: |
**/node_modules
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Load cached playwright binaries
uses: actions/cache@v3
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: playwright-${{ hashFiles('**/yarn.lock') }}
- name: Load fixtures cache
uses: actions/cache@v3
with:
path: frontend/e2e/fixtures
key: ${{ env.FIXTURES_CACHE_KEY }}
- name: Run E2E Tests
env:
BROWSER: ${{ matrix.browser }}
ENV: prod
run: yarn e2e:ci --shard ${{ matrix.shardCurrent }}/${{ matrix.shardTotal }}
- name: Upload artifacts
if: ${{ failure() }}
uses: actions/[email protected]
with:
name: e2e-artifacts
path: frontend/e2e/report
retention-days: 1