-
Notifications
You must be signed in to change notification settings - Fork 10
398 lines (390 loc) · 13.6 KB
/
deploy-experimental.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
name: "Deploy Experimental"
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
id-token: write
contents: read
actions: read
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
deploy-static:
environment:
name: "dev"
url: ${{ steps.deploy-regulations-site-server.outputs.url }}
runs-on: ubuntu-22.04
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# should build first and save the artifact
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.14
# setup python
- uses: actions/setup-python@v4
if: success() && steps.findPr.outputs.number
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./solution/static-assets/requirements.txt
# build the static assets for the website
- name: build static assets
if: success() && steps.findPr.outputs.number
env:
STATIC_URL: http://localhost:8888/
STATIC_ROOT: ../static-assets/regulations
VITE_ENV: dev${{ steps.findPr.outputs.pr }}
run: |
pushd solution/backend
python manage.py collectstatic --noinput
cd ..
popd
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# deploy static assets to AWS
- name: deploy static assets
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/static-assets
npm install serverless@">=3.38.0 <4" -g
npm install
serverless deploy --stage dev${PR}
popd
deploy-text-extractor:
environment:
name: "dev"
runs-on: ubuntu-22.04
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# Deploy the text extractor lambda to AWS
- name: Deploy text extractor lambda
id: deploy-text-extractor
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
RUN_ID: ${{ github.run_id }}
run: |
pushd solution/text-extractor
npm install serverless@">=3.38.0 <4" -g
serverless deploy --stage dev${PR}
popd
deploy-django:
environment:
name: "dev"
outputs:
url: ${{ steps.deploy-regulations-site-server.outputs.url }}
runs-on: ubuntu-22.04
needs: [deploy-static, deploy-text-extractor]
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# should build first and save the artifact
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.14
# setup python
- uses: actions/setup-python@v4
if: success() && steps.findPr.outputs.number
with:
python-version: "3.12"
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# Deploy the regulation site to AWS
- name: deploy regulations site server
id: deploy-regulations-site-server
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
RUN_ID: ${{ github.run_id }}
run: |
pushd solution/backend
npm install serverless@">=3.38.0 <4" -g
npm install
serverless deploy --config ./serverless-experimental.yml --stage dev${PR} | tee output.log
serverless invoke --config ./serverless-experimental.yml --function create_database --stage dev${PR}
serverless invoke --config ./serverless-experimental.yml --function reg_core_migrate --stage dev${PR}
serverless invoke --config ./serverless-experimental.yml --function create_su --stage dev${PR}
url=$(cat output.log | grep -m1 'ANY -' | cut -c 9-)
url=${url%/}
echo "url=$(echo $url)" >> $GITHUB_OUTPUT
popd
test-python:
needs: [deploy-django]
runs-on: ubuntu-22.04
env:
STATIC_URL: http://localhost:8888/
DB_HOST: localhost
DB_NAME: eregs
DB_USER: eregs
DB_PASSWORD: sgere
DB_PORT: 5432
HTTP_AUTH_USER: ${{ secrets.HTTP_AUTH_USER }}
HTTP_AUTH_PASSWORD: ${{ secrets.HTTP_AUTH_PASSWORD }}
services:
postgres:
image: postgres
env:
STATIC_URL: http://localhost:8888/
POSTGRES_HOST: localhost
POSTGRES_DB: eregs
POSTGRES_USER: eregs
POSTGRES_PASSWORD: sgere
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
# checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# setup Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./solution/static-assets/requirements.txt
# run Python unit tests
- name: Run Python unit tests
working-directory: ./solution/backend
run: |
DJANGO_SETTINGS_MODULE="cmcs_regulations.settings.test_settings" pytest -vv
build-and-deploy-vue:
environment:
name: "dev"
runs-on: ubuntu-22.04
needs: deploy-django
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existing action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Setup node environment
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version:
18.14
# setup python
- uses: actions/setup-python@v4
if: success() && steps.findPr.outputs.number
with:
python-version: "3.12"
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_VITE_API_URL: ${{ needs.deploy-django.outputs.url }}
directory: solution/ui/regulations/eregs-vite
file_name: .env
# build the static assets for the website
- name: build static assets
if: success() && steps.findPr.outputs.number
env:
STATIC_URL: http://localhost:8888/
STATIC_ROOT: ../static-assets/regulations
VITE_ENV: dev${{ steps.findPr.outputs.pr }}
run: |
pushd solution
make regulations
popd
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# deploy static assets to AWS
- name: deploy static assets
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/static-assets
npm install serverless@">=3.38.0 <4" -g
npm install
serverless deploy --stage dev${PR}
popd
deploy-go:
environment:
name: "dev"
runs-on: ubuntu-22.04
needs: deploy-django
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# deploy and run eCFR parser
- name: deploy and run eCFR parser
id: deploy-run-ecfr-parser
timeout-minutes: 20
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/parser
npm install serverless@">=3.38.0 <4" -g
serverless deploy --stage dev${PR} --config ./serverless-ecfr.yml
AWS_CLIENT_TIMEOUT=360000 serverless invoke --function ecfr_parser --stage dev${PR} --config ./serverless-ecfr.yml
popd
# deploy and run Federal Register parser
- name: deploy and run FR parser
id: deploy-run-fr-parser
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/parser
npm install serverless@">=3.38.0 <4" -g
serverless deploy --stage dev${PR} --config ./serverless-fr.yml
AWS_CLIENT_TIMEOUT=360000 serverless invoke --function fr_parser --stage dev${PR} --config ./serverless-fr.yml
popd
notify:
permissions:
pull-requests: write
runs-on: ubuntu-22.04
needs: [deploy-go, deploy-django]
steps:
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Notify github that this is deployed and ready to look at
- name: Create deployment comment
uses: peter-evans/create-or-update-comment@v2
env:
django_url: ${{ needs.deploy-django.outputs.url }}
with:
issue-number: ${{ steps.findPr.outputs.pr }}
body: |
:sparkles: See the Django Site [in action][1] :sparkles:
[1]: ${{ env.django_url }}
reactions: "+1"
test-cypress:
environment:
name: "dev"
runs-on: ubuntu-22.04
needs: [deploy-django, build-and-deploy-vue]
#needs: [deploy-go, deploy-django, build-and-deploy-vue]
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# Get test user credentials from AWS Parameter Store
- name: Get test user credentials
uses: dkershner6/aws-ssm-getparameters-action@v1
with:
parameterPairs: "/eregulations/http/user = CYPRESS_TEST_USERNAME,
/eregulations/http/password = CYPRESS_TEST_PASSWORD,
/eregulations/http/reader_user = CYPRESS_READER_USERNAME,
/eregulations/http/reader_password = CYPRESS_READER_PASSWORD"
withDecryption: "true" # defaults to true
# Setup node environment
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.14
# Run the cypress tests
- name: end-to-end tests
uses: cypress-io/github-action@v5
with:
working-directory: solution/ui/e2e
config: baseUrl=${{ needs.deploy-django.outputs.url }}
env:
CYPRESS_DEPLOYING: true
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: /home/runner/work/cmcs-eregulations/cmcs-eregulations/solution/ui/e2e/cypress/screenshots/*/*
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-videos
path: /home/runner/work/cmcs-eregulations/cmcs-eregulations/solution/ui/e2e/cypress/videos/*