This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcircle.yml
512 lines (498 loc) · 16.2 KB
/
circle.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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
version: 2.1
orbs:
aws-s3: circleci/[email protected]
jobs:
frontend-test:
docker:
- image: circleci/node:12
working_directory: ~/project/frontend
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- frontend-deps-{{ .Branch }}-
- frontend-deps-
- run:
name: Build and install Ocim API client
command: ./scripts/build-api-client.sh
- run:
name: Installing frontend dependencies
command: npm install
- save_cache:
paths:
- node_modules
key: frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- run:
name: Run frontend tests
command: npm test -- --reporters=default --reporters=jest-junit --ci --runInBand
- store_test_results:
path: .
frontend-quality:
docker:
- image: circleci/node:12
working_directory: ~/project/frontend
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- frontend-deps-{{ .Branch }}-
- frontend-deps-
- run:
name: Build and install Ocim API client
command: ./scripts/build-api-client.sh
- run:
name: Installing frontend dependencies
command: npm install
- save_cache:
paths:
- node_modules
key: frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- run:
name: Run frontend quality tests
command: npm run lint
- store_test_results:
path: .
frontend-coverage:
docker:
- image: circleci/node:12
working_directory: ~/project/frontend
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- frontend-deps-{{ .Branch }}-
- frontend-deps-
- run:
name: Build and install Ocim API client
command: ./scripts/build-api-client.sh
- run:
name: Installing frontend dependencies
command: npm install
- save_cache:
paths:
- node_modules
key: frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- run:
name: Generate frontend coverage report
command: npm run coverage || true
- store_test_results:
path: ~/project/frontend/coverage/clover.xml
frontend-build:
docker:
- image: circleci/node:12
working_directory: ~/project/frontend
steps:
- checkout:
path: ~/project
- restore_cache:
keys:
- frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- frontend-deps-{{ .Branch }}-
- frontend-deps-
- run:
name: Build and install Ocim API client
command: ./scripts/build-api-client.sh
- run:
name: Installing frontend dependencies
command: npm install
- save_cache:
paths:
- node_modules
key: frontend-deps-{{ .Branch }}-{{ checksum "package-lock.json" }}
- run:
name: Rebuild node-sass to generate bindings
command: npm rebuild node-sass
- run:
name: Render environment variables to .env file
command: |
echo $(env | grep REACT_APP) >> .env
- run:
name: Build React frontend
command: npm run build
- persist_to_workspace:
root: build
paths:
- .
frontend-deploy:
docker:
- image: circleci/python:3.8
steps:
- attach_workspace:
at: frontend-build
- aws-s3/sync:
from: frontend-build/
to: "s3://$AWS_S3_BUCKET/frontend"
overwrite: true
# `acl public-read` is needed to make the objects in the bucket publicly accesible.
arguments: |
--acl public-read
- run:
name: Invalidate CloudFront cache
command: |
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths '/*'
build:
docker:
- image: circleci/python:3.6-stretch-node-browsers
environment:
DEBUG: 'true'
DEFAULT_FORK: 'open-craft/edx-platform'
LOAD_BALANCER_FRAGMENT_NAME_PREFIX: 'integration-'
SIMPLE_THEME_SKELETON_THEME_VERSION: 'master'
- image: redis
- image: mongo:3.2-jessie
- image: "circleci/mysql:5"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: True
- image: circleci/postgres:10.1-alpine
environment:
PG_HOST: 127.0.0.1
POSTGRES_USER: circleci
POSTGRES_DB: circle_test
parameters:
tests_group:
type: integer
tests_type:
type: string
environment:
TEST_GROUP: <<parameters.tests_group>>
steps:
- checkout
- restore_cache:
key: dependencies-{{ checksum "requirements.txt" }}
- run:
name: Wait for Redis
command: dockerize -wait tcp://localhost:6379 -timeout 10s
- run:
name: Wait for Postgres
command: dockerize -wait tcp://localhost:5432 -timeout 10s
- run:
name: Wait for MySQL
command: dockerize -wait tcp://localhost:3306 -timeout 10s
- run:
name: Wait for MongoDB
command: dockerize -wait tcp://localhost:27017 -timeout 10s
- run:
name: Install Dependencies
command: |
sed -i 's/libmysqlclient/default-libmysqlclient/' debian_packages.lst
make install_system_dependencies
sudo ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
bin/install-supported-firefox
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install --upgrade virtualenv
pip install -r requirements.txt
pip install -r cleanup_utils/requirements.txt
npm install
- run:
name: Run Consul
command: |
sudo wget -P /tmp https://releases.hashicorp.com/consul/1.2.1/consul_1.2.1_linux_amd64.zip
sudo unzip /tmp/consul_1.2.1_linux_amd64.zip -d /usr/local/bin
mkdir -p /tmp/consul-data
if [[ "<< parameters.tests_type >>" == "test.integration" ]] ; then
echo Running consul agent to connect to the integration consul server
consul agent -retry-join $CONSUL_SERVERS -encrypt $CONSUL_ENCRYPT -data-dir /tmp/consul-data
else
echo Running a local consul agent
consul agent -dev
fi
background: true
- save_cache:
key: dependencies-{{ checksum "requirements.txt" }}
paths:
- "venv"
- run:
name: Create Database
command: make create_db
- run:
name: Run Tests
command: |
. venv/bin/activate
mkdir -p /tmp/coverage
make << parameters.tests_type >>
if [ -e .coverage.* ]; then
cp -v .coverage.* /tmp/coverage/.
fi
if [ -d coverage ]; then
cp -vR coverage/* /tmp/coverage/.
fi
no_output_timeout: 2h
environment:
ANSIBLE_HOST_KEY_CHECKING: False
- persist_to_workspace:
root: /tmp
paths:
- coverage
e2e-tests:
docker:
- image: circleci/python:3.6-stretch-node-browsers
environment:
DEBUG: 'true'
DEFAULT_FORK: 'open-craft/edx-platform'
LOAD_BALANCER_FRAGMENT_NAME_PREFIX: 'integration-'
- image: redis
- image: mongo:3.2-jessie
- image: "circleci/mysql:5"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: True
- image: circleci/postgres:10.1-alpine
environment:
PG_HOST: 127.0.0.1
POSTGRES_USER: circleci
POSTGRES_DB: circle_test
environment:
REACT_APP_OCIM_API_BASE: http://localhost:5000
steps:
- checkout
- restore_cache:
key: dependencies-{{ checksum "requirements.txt" }}
- run:
name: Wait for Redis
command: dockerize -wait tcp://localhost:6379 -timeout 10s
- run:
name: Wait for Postgres
command: dockerize -wait tcp://localhost:5432 -timeout 10s
- run:
name: Wait for MySQL
command: dockerize -wait tcp://localhost:3306 -timeout 10s
- run:
name: Wait for MongoDB
command: dockerize -wait tcp://localhost:27017 -timeout 10s
- run:
name: Install Dependencies
command: |
sed -i 's/libmysqlclient/default-libmysqlclient/' debian_packages.lst
make install_system_dependencies
sudo ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
bin/install-supported-firefox
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install --upgrade virtualenv
pip install -r requirements.txt
pip install -r cleanup_utils/requirements.txt
npm install
- run:
name: Run Consul
command: |
sudo wget -P /tmp https://releases.hashicorp.com/consul/1.2.1/consul_1.2.1_linux_amd64.zip
sudo unzip /tmp/consul_1.2.1_linux_amd64.zip -d /usr/local/bin
mkdir -p /tmp/consul-data
consul agent -dev
background: true
- save_cache:
key: dependencies-{{ checksum "requirements.txt" }}
paths:
- "venv"
- run:
name: Create Database
command: make create_db
- run:
name: Run Tests
command: |
. venv/bin/activate
mkdir -p /tmp/coverage
make test.e2e
if [ -e .coverage.* ]; then
cp -v .coverage.* /tmp/coverage/.
fi
if [ -d coverage ]; then
cp -vR coverage/* /tmp/coverage/.
fi
no_output_timeout: 2h
environment:
ANSIBLE_HOST_KEY_CHECKING: False
- persist_to_workspace:
root: /tmp
paths:
- coverage
coverage:
docker:
- image: circleci/python:3.6-stretch-node
steps:
- checkout
- restore_cache:
key: dependencies-{{ checksum "requirements.txt" }}
- run:
name: Install Dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install --upgrade virtualenv
sudo apt-get update; sudo apt-get install python2.7-dev
sudo apt-get install mysql-client
pip install -r requirements.txt
pip install -r cleanup_utils/requirements.txt
sudo apt-get install postgresql-client
sudo apt-get install unzip
sudo wget -P /tmp https://releases.hashicorp.com/consul/1.2.1/consul_1.2.1_linux_amd64.zip
sed -i 's/libmysqlclient/default-libmysqlclient/' debian_packages.lst
make install_system_dependencies
npm install
- attach_workspace:
at: /tmp/workspace
- run:
command: |
. venv/bin/activate
coverage combine --append /tmp/workspace/coverage/
make cov.html
if [ -e /tmp/workspace/coverage/text/coverage.txt ]; then cat /tmp/workspace/coverage/text/coverage.txt; fi
cleanup:
docker:
- image: circleci/python:3.6-stretch
environment:
LOAD_BALANCER_FRAGMENT_NAME_PREFIX: 'integration-'
DJANGO_SETTINGS_MODULE: 'opencraft.settings'
- image: redis
steps:
- checkout
- restore_cache:
key: dependencies-{{ checksum "requirements.txt" }}
- run:
name: Install Dependencies
command: |
python3 -m venv venv
. venv/bin/activate
sudo apt-get install libpython2.7-dev
pip install -r cleanup_utils/requirements.txt
- run:
name: Run Consul
command: |
echo Running consul agent to connect to the integration consul server
sudo wget -P /tmp https://releases.hashicorp.com/consul/1.2.1/consul_1.2.1_linux_amd64.zip
sudo unzip /tmp/consul_1.2.1_linux_amd64.zip -d /usr/local/bin
mkdir -p /tmp/consul-data
consul agent -retry-join $CONSUL_SERVERS -encrypt $CONSUL_ENCRYPT -data-dir /tmp/consul-data
background: true
- run:
name: Wait for Redis
command: dockerize -wait tcp://localhost:6379 -timeout 10s
- run:
name: Cleanup
command: |
. venv/bin/activate
make test.integration_cleanup
no_output_timeout: 20m
when: always
workflows:
version: 2
build-test-and-deploy:
jobs:
- build:
name: quality_migrations_tests
tests_group: 0
tests_type: TEST_ENV_FILE=.env.test.ci clean test.quality test.migrations_missing
- build:
name: python_unit_tests
tests_group: 0
tests_type: TEST_ENV_FILE=.env.test.ci clean test.unit
- build:
name: browser_tests
tests_group: 0
tests_type: TEST_ENV_FILE=.env.test.ci clean test.browser
- e2e-tests
- build:
name: js_tests
tests_group: 0
tests_type: TEST_ENV_FILE=.env.test.ci clean test.js
- build:
name: integration_tests_group_1
tests_group: 1
tests_type: test.integration
requires:
- quality_migrations_tests
- python_unit_tests
- browser_tests
- js_tests
- build:
name: integration_tests_group_2
tests_group: 2
tests_type: test.integration
requires:
- quality_migrations_tests
- python_unit_tests
- browser_tests
- js_tests
- coverage:
name: coverage
requires:
- integration_tests_group_1
- integration_tests_group_2
frontend-build-test-and-deploy:
jobs:
- frontend-quality:
filters:
tags:
only: /^release\-\w+\-\w+$/
- frontend-coverage:
filters:
tags:
only: /^release\-\w+\-\w+$/
- frontend-test:
requires:
- frontend-quality
filters:
tags:
only: /^release\-\w+\-\w+$/
- frontend-build:
context: ocim-frontend-stage
requires:
- frontend-test
# Frontend deployment (only on stage branch)
- frontend-deploy:
name: frontend-deploy-stage
context: ocim-frontend-stage
requires:
- frontend-build
filters:
branches:
only:
- stage
# Deploy production
- frontend-build:
name: frontend-build-production
context: ocim-frontend-production
requires:
- frontend-test
filters:
branches:
ignore: /.*/
tags:
only: /^release\-\w+\-\w+$/
- frontend-deploy:
name: frontend-deploy-production
context: ocim-frontend-production
requires:
- frontend-build-production
filters:
branches:
ignore: /.*/
tags:
only: /^release\-\w+\-\w+$/
# used for periodically cleaning up left-over resources
scheduled-cleanup:
triggers:
- schedule:
cron: "0 1 * * *"
filters:
branches:
only:
- master
jobs:
- cleanup
on-demand-cleanup:
jobs:
- cleanup:
filters:
branches:
only:
- ci-cleanup