-
Notifications
You must be signed in to change notification settings - Fork 32
/
config.yml
372 lines (360 loc) · 12.1 KB
/
config.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
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2.1
orbs:
slack: circleci/[email protected]
aws-cli: circleci/[email protected]
executors:
py312:
docker:
- image: cimg/python:3.12
environment:
CIRCLECI: true
PGHOST: 127.0.0.1
- image: cimg/postgres:16.3
environment:
POSTGRES_USER: postgres
POSTGRES_DB: test
jobs:
build_and_test:
parameters:
python_version:
type: executor
docker:
# specify the version you desire here
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
- image: cimg/python:3.12.4
environment:
CIRCLECI: true
PGHOST: 127.0.0.1
- image: cimg/postgres:16.3
environment:
POSTGRES_USER: wcivf
POSTGRES_DB: wcivf
- image: cimg/redis:7.0.5
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v6-dependencies-{{ checksum "requirements/base.txt" }}-{{ checksum "requirements/testing.txt" }}
- run:
name: install dependencies
command: |
python -m venv .venv
. .venv/bin/activate
pip install --upgrade pip coveralls
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
sudo apt install gettext
pip install -r requirements/testing.txt
- save_cache:
paths:
- ./.venv
key: v6-dependencies-{{ checksum "requirements/base.txt" }}-{{ checksum "requirements/testing.txt" }}
- run:
name: Install HTML Tidy
command: wget https://github.com/htacg/tidy-html5/releases/download/5.8.0/tidy-5.8.0-Linux-64bit.deb && sudo dpkg -i tidy-5.8.0-Linux-64bit.deb
# run tests!
- run:
name: Django version
command: |
. .venv/bin/activate
python manage.py --version
- run:
name: Django Check
command: |
. .venv/bin/activate
python manage.py check
python manage.py makemigrations --check
- run:
name: Ruff
command: |
. .venv/bin/activate
ruff format . --check
ruff check .
- run:
name: Pip Check
command: |
. .venv/bin/activate
pip check
- run:
name: Djhtml
command: |
. .venv/bin/activate
git ls-files '*.html' | xargs djhtml --check
- run:
name: Compile Messages
command: |
. .venv/bin/activate
bash -ec 'cd wcivf && python ../manage.py compilemessages -l cy'
- run:
name: run pytest
command: |
. .venv/bin/activate
pytest -sx --cov-report= --cov=wcivf --junitxml=test-results/junit.xml
- run: |
if [ -n "$COVERALLS_REPO_TOKEN" ]; then
. .venv/bin/activate
coveralls
else
echo "skipping coverage for forked PR"
fi
- store_artifacts:
path: test-results
destination: test-results
sam_build:
docker:
- image: public.ecr.aws/sam/build-python3.12:latest
working_directory: ~/repo
steps:
- checkout
- run:
name: sam build
command: |
pip install setuptools wheel
make build clean
- persist_to_workspace:
root: ~/repo/
paths: [ .aws-sam/build/ ]
sam_deploy:
docker:
- image: public.ecr.aws/sam/build-python3.12:latest
working_directory: ~/repo
parameters:
dc-environment:
type: enum
enum: [ development, staging, production ]
vpc-id:
type: string
ssl-certificate-arn:
type: string
instance-type:
type: string
subnet-ids:
type: string
domain:
type: string
environment:
DC_ENVIRONMENT: <<parameters.dc-environment>>
steps:
- checkout
- restore_cache:
keys:
- v6-dependencies-{{ checksum "requirements/base.txt" }}-{{ checksum "requirements/testing.txt" }}
- attach_workspace:
at: ~/repo/
- run: echo <<parameters.instance-type>>
- run:
name: deploy
command: |
sam deploy \
--no-confirm-changeset \
--config-file ~/repo/samconfig.toml \
--config-env $DC_ENVIRONMENT \
--template-file ~/repo/.aws-sam/build/template.yaml \
--parameter-overrides " \
AppDjangoSettingsModule=wcivf.settings.lambda \
AppRdsHost='$RDS_HOST' \
AppRdsDbName='$RDS_DB_NAME' \
AppRdsDbPassword='$RDS_DB_PASSWORD' \
AppSentryDsn='$SENTRY_DSN' \
AppSecretKey='$SECRET_KEY' \
AppSlackFeedbackWebhookUrl='$SLACK_FEEDBACK_WEBHOOK_URL' \
AppDcEnvironment='$DC_ENVIRONMENT' \
AppYnrApiKey='$YNR_API_KEY' \
VpcIdParameter=<<parameters.vpc-id>> \
SubnetIdsParameter=<<parameters.subnet-ids>> \
SSLCertificateArn=<<parameters.ssl-certificate-arn>> \
InstanceType='<<parameters.instance-type>>' \
Domain='<<parameters.domain>>'
"
post_deploy_tests:
docker:
- image: cimg/python:3.12.4
working_directory: ~/repo
parameters:
dc-environment:
type: enum
enum: [ development, staging, production ]
environment:
DC_ENVIRONMENT: <<parameters.dc-environment>>
steps:
- checkout
- restore_cache:
keys:
- v6-dependencies-{{ checksum "requirements/base.txt" }}-{{ checksum "requirements/testing.txt" }}
- attach_workspace:
at: ~/repo/
- run: printenv DC_ENVIRONMENT
- aws-cli/setup
- run:
name: post deploy tests
command: |
. .venv/bin/activate
pytest ~/repo/.circleci/
- run:
name: migrate the database
command: |
. .venv/bin/activate
make lambda-migrate
# In the event the deployment has failed, alert the dev team
- slack/notify:
event: fail
template: basic_fail_1
code_deploy:
docker:
- image: cimg/python:3.12.4
working_directory: ~/repo
parameters:
min-size:
type: integer
max-size:
type: integer
desired-capacity:
type: integer
dc-environment:
type: enum
enum: [ development, staging, production ]
environment:
DC_ENVIRONMENT: <<parameters.dc-environment>>
steps:
- checkout
- restore_cache:
keys:
- v6-dependencies-{{ checksum "requirements/base.txt" }}-{{ checksum "requirements/testing.txt" }}
- attach_workspace:
at: ~/repo/
- run: printenv DC_ENVIRONMENT
- run:
name: ensure the deployment group ready
command: |
. .venv/bin/activate
python deploy/create_deployment_group.py
- run:
name: create deployment with codedeploy
command: |
. .venv/bin/activate
COMMIT_SHA=$CIRCLE_SHA1 python deploy/create_deployment.py
- run:
name: Update auto scaling group
command: |
. .venv/bin/activate
MIN_SIZE=<<parameters.min-size>> \
MAX_SIZE=<<parameters.max-size>> \
DESIRED_CAPACITY=<<parameters.desired-capacity>> \
python deploy/update_auto_scaling_group.py
no_output_timeout: 15m # TODO reduce/discuss what is suitable?
# In the event the deployment has failed, alert the dev team
- slack/notify:
event: fail
template: basic_fail_1
workflows:
main:
jobs:
- build_and_test:
matrix:
parameters:
python_version: [ py312 ]
- sam_build:
requires:
- build_and_test
- sam_deploy:
name: sam_deploy_development
dc-environment: development
vpc-id: vpc-fa2e0792
subnet-ids: "subnet-890877f3,subnet-be093ad7,subnet-3524a679"
ssl-certificate-arn: arn:aws:acm:us-east-1:061126312678:certificate/ece58cd4-6192-474a-a8ed-84e3635d9180
instance-type: t3a.small
domain: "dev.wcivf.club"
requires:
- build_and_test
- sam_build
context: [ deployment-development-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master, staging, development ] } }
- post_deploy_tests:
name: post_deploy_tests_development
dc-environment: development
requires:
- sam_deploy_development
context: [ deployment-development-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master, staging, development ] } }
- code_deploy:
name: code_deploy_development
dc-environment: development
min-size: 1
max-size: 1
desired-capacity: 1
requires:
- post_deploy_tests_development
context: [ deployment-development-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master, staging, development ] } }
- sam_deploy:
name: sam_deploy_staging
dc-environment: staging
vpc-id: vpc-69cef901
subnet-ids: "subnet-e2b4f198,subnet-5a911a16,subnet-818bb2e8"
ssl-certificate-arn: arn:aws:acm:us-east-1:897471774344:certificate/b7580cc7-4e31-49ad-a08c-3bf9ae43e328
instance-type: t3a.medium
domain: "wcivf.club"
requires:
- build_and_test
# NB should this be dependent on successful sam_deploy_development job?
- sam_build
context: [ deployment-staging-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master, staging ] } }
- post_deploy_tests:
name: post_deploy_tests_staging
dc-environment: staging
requires:
- sam_deploy_staging
context: [ deployment-staging-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master, staging ] } }
- code_deploy:
name: code_deploy_staging
dc-environment: staging
min-size: 1
max-size: 1
desired-capacity: 1
requires:
- build_and_test
- sam_deploy_staging
context: [ deployment-staging-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master, staging ] } }
- sam_deploy:
name: sam_deploy_production
dc-environment: production
vpc-id: vpc-0d23d243e8bff4415
subnet-ids: "subnet-04caf1309c0ab8f94,subnet-06475e48c36b4aece,subnet-0895b7d4795fbb1f4"
ssl-certificate-arn: arn:aws:acm:us-east-1:705594574410:certificate/31f3f746-fd90-4c69-964d-091e8fa0cbfe
instance-type: c6a.large
domain: "whocanivotefor.co.uk"
requires:
- build_and_test
# NB should this be dependent on successful sam_deploy_development job?
- sam_build
- code_deploy_staging
context: [ deployment-production-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master ] } }
- post_deploy_tests:
name: post_deploy_tests_production
dc-environment: production
requires:
- sam_deploy_production
context: [ deployment-production-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master, staging ] } }
- code_deploy:
name: code_deploy_production
dc-environment: production
min-size: 1
max-size: 20
desired-capacity: 1
requires:
- build_and_test
- sam_deploy_staging
- sam_deploy_production
context: [ deployment-production-wcivf, slack-secrets ]
filters: { branches: { only: [ main, master ] } }