-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
130 lines (96 loc) · 2.66 KB
/
.gitlab-ci.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
image: docker:latest
stages:
- build
- deploy
- test
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
Build and deploy staging:
stage: deploy
image: python:3.6-stretch
variables:
MEDICALCALCS_FQDN: ${STAGING_MEDICALCALCS_FQDN}
AWS_ACCESS_KEY_ID: ${STAGING_AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${STAGING_AWS_SECRET_ACCESS_KEY}
S3_BUCKET_NAME: ${STAGING_S3_BUCKET_NAME}
before_script: &build_before
- pip install awscli
- curl -sL https://deb.nodesource.com/setup_9.x | bash -
- apt-get install -y nodejs jq
- npm install
script: &build_script
- npm run build
- aws s3 sync ./build s3://${S3_BUCKET_NAME}/ --delete --acl public-read
- export DISTRIBUTION_ID=$(aws cloudfront list-distributions | jq -r ".DistributionList.Items[] | select(.Aliases.Items[] | contains(\"$MEDICALCALCS_FQDN\")) | .Id")
- aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /index.html
- aws s3 cp src/data/list.json s3://${S3_BUCKET_NAME}/calculators-list.json --acl private
environment:
name: staging
url: https://${MEDICALCALCS_FQDN}
artifacts:
paths:
- build/
only:
- staging
when: on_success
#end Build
Build only:
stage: build
image: python:3.6-stretch
before_script: *build_before
script:
- npm run build
except:
- staging
- production
- master
when: on_success
#end Build
Build and deploy production:
stage: deploy
image: python:3.6-stretch
variables:
MEDICALCALCS_FQDN: ${PRODUCTION_MEDICALCALCS_FQDN}
AWS_ACCESS_KEY_ID: ${PRODUCTION_AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${PRODUCTION_AWS_SECRET_ACCESS_KEY}
S3_BUCKET_NAME: ${PRODUCTION_S3_BUCKET_NAME}
before_script: *build_before
script: *build_script
environment:
name: production
url: https://${MEDICALCALCS_FQDN}
artifacts:
paths:
- build/
only:
- production
when: on_success
#end Build
Test staging deployment:
stage: test
image: alpine:3.6
variables:
MEDICALCALCS_FQDN: ${STAGING_MEDICALCALCS_FQDN}
before_script: &test_before
- apk add --no-cache curl grep
script: &test_script
- cd build
- echo "MEDICALCALCS_FQDN is ${MEDICALCALCS_FQDN}"
- find static/js -name 'main.*.js' -exec curl "https://${MEDICALCALCS_FQDN}/{}" -o _main.js \;
- cat static/js/main.*.js | sha512sum > _main.sha512
- cat _main.js | sha512sum -c _main.sha512
only:
- staging
#end Test
Test production deployment:
stage: test
image: alpine:3.6
variables:
MEDICALCALCS_FQDN: ${PRODUCTION_MEDICALCALCS_FQDN}
before_script: *test_before
script: *test_script
only:
- production
#end Test