-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
382 lines (361 loc) · 16.3 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
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
variables:
DOCKER_TLS_CERTDIR: ""
GIT_STRATEGY: clone
REGISTRY_USER: chembl/chembl
SERVER_APPLICATION: main-web-interface/glados-frontend-chembl-main-interface
SERVER_IMAGE_TAG: ${CI_REGISTRY}/${REGISTRY_USER}/${SERVER_APPLICATION}:${CI_COMMIT_SHORT_SHA}
DOCKER_DRIVER: overlay
CONFIGS_FOLDER: run_config
LATEST_BUILD_IMAGE_TAG: $CI_REGISTRY/$REGISTRY_USER/${SERVER_APPLICATION}:latest_build
LATEST_PROD_IMAGE_TAG: $CI_REGISTRY/$REGISTRY_USER/${SERVER_APPLICATION}:${CI_COMMIT_SHORT_SHA}_latest_prod
# Config unit tests
CONFIG_UNIT_TESTS_FILE_PATH: ${CONFIGS_FOLDER}/unit_tests.yml
# Config staging
CONFIG_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging.yml
CONFIG_GUNICORN_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging.gunicorn.config.py
INGRESS_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/ingress-staging.yml
AUTOSCALER_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/autoscaler-staging.yml
# Config prod_hx
CONFIG_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/prod_hx.yml
CONFIG_GUNICORN_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/prod_hx.gunicorn.config.py
INGRESS_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/ingress-prod_hx.yml
AUTOSCALER_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/autoscaler-prod_hx.yml
# Config prod_hh
CONFIG_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/prod_hh.yml
CONFIG_GUNICORN_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/prod_hh.gunicorn.config.py
INGRESS_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/ingress-prod_hh.yml
AUTOSCALER_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/autoscaler-prod_hh.yml
image: docker:latest
services:
- docker:dind
stages:
- build_for_staging
- prepare_config_tests
- test_and_qa
- prepare_config_staging
- deploy_to_staging
- test_staging
- prepare_config_hx
- deploy_to_prod_hx
- test_prod_hx
- prepare_config_hh
- deploy_to_prod_hh
- test_prod_hh
- functional_tests_prod_public
# ----------------------------------------------------------------------------------------------------------------------
# build
# ----------------------------------------------------------------------------------------------------------------------
build_docker_image_for_staging:
image:
name: docker:latest
entrypoint: ["/bin/sh", "-c"]
stage: build_for_staging
variables:
DOCKER_HOST: tcp://docker:2375
script:
- set -x
- echo 'building!'
- docker version # verify docker cli is there. Also prints server info
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- echo building ${SERVER_IMAGE_TAG}
- sed -i "s~<UID>~${STATIC_FILES_UID}~g" Dockerfile-Staging
- sed -i "s~<GID>~${STATIC_FILES_GID}~g" Dockerfile-Staging
- docker build --tag ${SERVER_IMAGE_TAG} -f Dockerfile-Staging .
- docker push ${SERVER_IMAGE_TAG}
- sed -i "s~<UID>~${STATIC_FILES_UID}~g" Dockerfile-Prod
- sed -i "s~<GID>~${STATIC_FILES_GID}~g" Dockerfile-Prod
- docker build --tag ${LATEST_PROD_IMAGE_TAG} --cache-from ${SERVER_IMAGE_TAG} -f Dockerfile-Prod .
- docker push ${LATEST_PROD_IMAGE_TAG}
## ----------------------------------------------------------------------------------------------------------------------
## QA
## ----------------------------------------------------------------------------------------------------------------------
prepare_config_tests:
stage: prepare_config_tests
image:
name: alpine/git
entrypoint: ["/bin/sh", "-c"]
script:
- set -x
- mkdir -p ${CONFIGS_FOLDER}
- git clone https://${CONFIG_DEPLOY_GITLAB_USERNAME}:${CONFIG_DEPLOY_GITLAB_TOKEN}@${CONFIGURATIONS_REPO} ${CONFIGS_FOLDER}
artifacts:
paths:
- ${CONFIG_UNIT_TESTS_FILE_PATH}
pylint:
stage: test_and_qa
image:
name: $SERVER_IMAGE_TAG
entrypoint: [""]
script:
- set -x
- echo 'activate these tests some day'
- exit 0
# - find . -iname "*.py" | xargs pylint
## ---------------------------------------------------------------------------------------------------------------------
## Tests
## ---------------------------------------------------------------------------------------------------------------------
unit_tests:
stage: test_and_qa
image:
name: $SERVER_IMAGE_TAG
entrypoint: [""]
script:
- set -x
- CONFIG_FILE_PATH=${CONFIG_UNIT_TESTS_FILE_PATH} python manage.py test
javascript_tests:
stage: test_and_qa
only:
- staging
image:
name: $SERVER_IMAGE_TAG
entrypoint: [""]
script:
- set -x
- echo 'activate these tests some day'
- exit 0
#
### ----------------------------------------------------------------------------------------------------------------------
### Deployment to staging
### ----------------------------------------------------------------------------------------------------------------------
prepare_config_staging:
stage: prepare_config_staging
image:
name: alpine/git
entrypoint: ["/bin/sh", "-c"]
only:
- staging
script:
- set -x
- rm -rf ${CONFIGS_FOLDER} || true
- mkdir -p ${CONFIGS_FOLDER}
- git clone https://${CONFIG_DEPLOY_GITLAB_USERNAME}:${CONFIG_DEPLOY_GITLAB_TOKEN}@${CONFIGURATIONS_REPO} ${CONFIGS_FOLDER}
artifacts:
paths:
- ${CONFIG_STAGING_FILE_PATH}
- ${CONFIG_GUNICORN_STAGING_FILE_PATH}
- ${INGRESS_STAGING_FILE_PATH}
- ${AUTOSCALER_STAGING_FILE_PATH}
deploy_to_staging:
stage: deploy_to_staging
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
only:
- staging
environment:
name: staging
url: ${SERVER_URL_STAGING}
script:
- set -x
- echo "$KUBE_CA_PEM_HX" > "$(pwd)/kube.ca.pem"
- kubectl config set-cluster ${KUBE_CLUS_NAME_HX} --server="${KUBE_URL_HX}" --certificate-authority="$(pwd)/kube.ca.pem"
- kubectl config set-credentials ${KUBE_USER_HX} --token="${KUBE_TOKEN_HX}"
- kubectl config set-context ${CHEMBL_NS_STAGING} --cluster=${KUBE_CLUS_NAME_HX} --user=${KUBE_USER_HX}
- kubectl config use-context ${CHEMBL_NS_STAGING}
- echo ${CHEMBL_NS_STAGING} ${KUBE_URL_HX} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
- kubectl get pods -n ${CHEMBL_NS_STAGING}
- kubectl create secret generic ${RUN_CONFIG_SECRET_NAME_STAGING} --from-file=RUN_CONFIG.yml=${CONFIG_STAGING_FILE_PATH} -o yaml -n ${CHEMBL_NS_STAGING} --dry-run=client | kubectl replace -f -
- kubectl create secret generic ${GUNICORN_CONFIG_SECRET_NAME_STAGING} --from-file=GUNICORN_CONFIG.py=${CONFIG_GUNICORN_STAGING_FILE_PATH} -o yaml -n ${CHEMBL_NS_STAGING} --dry-run=client | kubectl replace -f -
- cat ${CONFIG_STAGING_FILE_PATH}
- cat ${CONFIG_GUNICORN_STAGING_FILE_PATH}
- sed -i "s~<NAMESPACE>~${CHEMBL_NS_STAGING}~g" k8s-deployment.yaml
- sed -i "s~<NUM_REPLICAS>~${NUM_REPLICAS_STAGING}~g" k8s-deployment.yaml
- sed -i "s~<STATICS_UID>~${STATIC_FILES_UID}~g" k8s-deployment.yaml
- sed -i "s~<STATICS_GID>~${STATIC_FILES_GID}~g" k8s-deployment.yaml
- sed -i "s~<HTTP_PROXY>~${HTTP_PROXY_HX}~g" k8s-deployment.yaml
- sed -i "s~<HTTPS_PROXY>~${HTTPS_PROXY_HX}~g" k8s-deployment.yaml
- sed -i "s~<NO_PROXY>~${NO_PROXY_HX_DEFAULT}~g" k8s-deployment.yaml
- sed -i "s~<CPU_LIMIT>~${CPU_LIMIT_STAGING}~g" k8s-deployment.yaml
- sed -i "s~<CPU_REQUESTED>~${CPU_REQUESTED_STAGING}~g" k8s-deployment.yaml
- sed -i "s~<SERVER_IMAGE_TAG>~${SERVER_IMAGE_TAG}~g" k8s-deployment.yaml
- sed -i "s~<RUN_CONFIG_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_STAGING}~g" k8s-deployment.yaml
- sed -i "s~<GUNICORN_CONFIG_SECRET_NAME>~${GUNICORN_CONFIG_SECRET_NAME_STAGING}~g" k8s-deployment.yaml
- cat k8s-deployment.yaml
- kubectl apply -n ${CHEMBL_NS_STAGING} -f k8s-deployment.yaml
- kubectl get pods -n ${CHEMBL_NS_STAGING}
- cat ${INGRESS_STAGING_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_STAGING} -f ${INGRESS_STAGING_FILE_PATH}
- kubectl describe ingress -n ${CHEMBL_NS_STAGING}
- cat ${AUTOSCALER_STAGING_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_STAGING} -f ${AUTOSCALER_STAGING_FILE_PATH}
## ----------------------------------------------------------------------------------------------------------------------
## Test staging
## ----------------------------------------------------------------------------------------------------------------------
functional_tests:
stage: test_staging
image:
name: $SERVER_IMAGE_TAG
entrypoint: [""]
only:
- staging
environment:
name: staging
url: ${SERVER_URL_STAGING}
script:
- set -x
- echo 'Implement this soon!'
- exit 0
### ----------------------------------------------------------------------------------------------------------------------
### Deployment to prod hx
### ----------------------------------------------------------------------------------------------------------------------
prepare_config_prod_hx:
stage: prepare_config_hx
image:
name: alpine/git
entrypoint: ["/bin/sh", "-c"]
only:
- master
script:
- rm -rf ${CONFIGS_FOLDER} || true
- mkdir -p ${CONFIGS_FOLDER}
- git clone https://${CONFIG_DEPLOY_GITLAB_USERNAME}:${CONFIG_DEPLOY_GITLAB_TOKEN}@${CONFIGURATIONS_REPO} ${CONFIGS_FOLDER}
artifacts:
paths:
- ${CONFIG_PROD_HX_FILE_PATH}
- ${CONFIG_GUNICORN_PROD_HX_FILE_PATH}
- ${INGRESS_PROD_HX_FILE_PATH}
- ${AUTOSCALER_PROD_HX_FILE_PATH}
deploy_to_prod_hx:
stage: deploy_to_prod_hx
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
only:
- master
environment:
name: prod_hx
script:
- set -x
- echo "$KUBE_CA_PEM_HX" > "$(pwd)/kube.ca.pem"
- kubectl config set-cluster ${KUBE_CLUS_NAME_HX} --server="${KUBE_URL_HX}" --certificate-authority="$(pwd)/kube.ca.pem"
- kubectl config set-credentials ${KUBE_USER_HX} --token="${KUBE_TOKEN_HX}"
- kubectl config set-context ${CHEMBL_NS_PROD} --cluster=${KUBE_CLUS_NAME_HX} --user=${KUBE_USER_HX}
- kubectl config use-context ${CHEMBL_NS_PROD}
- echo ${CHEMBL_NS_PROD} ${KUBE_URL_HX} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
- kubectl get pods -n ${CHEMBL_NS_PROD}
- kubectl create secret generic ${RUN_CONFIG_SECRET_NAME_PROD_HX} --from-file=RUN_CONFIG.yml=${CONFIG_PROD_HX_FILE_PATH} -o yaml -n ${CHEMBL_NS_PROD} --dry-run=client | kubectl replace -f -
- kubectl create secret generic ${GUNICORN_CONFIG_SECRET_NAME_PROD_HX} --from-file=GUNICORN_CONFIG.py=${CONFIG_GUNICORN_PROD_HX_FILE_PATH} -o yaml -n ${CHEMBL_NS_PROD} --dry-run=client | kubectl replace -f -
- cat ${CONFIG_PROD_HX_FILE_PATH}
- cat ${CONFIG_GUNICORN_PROD_HX_FILE_PATH}
- sed -i "s~<NAMESPACE>~${CHEMBL_NS_PROD}~" k8s-deployment.yaml
- sed -i "s~<NUM_REPLICAS>~${NUM_REPLICAS_PROD_HX}~" k8s-deployment.yaml
- sed -i "s~<STATICS_UID>~${STATIC_FILES_UID}~g" k8s-deployment.yaml
- sed -i "s~<STATICS_GID>~${STATIC_FILES_GID}~g" k8s-deployment.yaml
- sed -i "s~<HTTP_PROXY>~${HTTP_PROXY_HX}~g" k8s-deployment.yaml
- sed -i "s~<HTTPS_PROXY>~${HTTPS_PROXY_HX}~g" k8s-deployment.yaml
- sed -i "s~<NO_PROXY>~${NO_PROXY_HX_DEFAULT}~g" k8s-deployment.yaml
- sed -i "s~<CPU_LIMIT>~${CPU_LIMIT_PROD_HX}~" k8s-deployment.yaml
- sed -i "s~<CPU_REQUESTED>~${CPU_REQUESTED_PROD_HX}~" k8s-deployment.yaml
- sed -i "s~<SERVER_IMAGE_TAG>~${LATEST_PROD_IMAGE_TAG}~" k8s-deployment.yaml
- sed -i "s~<RUN_CONFIG_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_PROD_HX}~" k8s-deployment.yaml
- sed -i "s~<GUNICORN_CONFIG_SECRET_NAME>~${GUNICORN_CONFIG_SECRET_NAME_PROD_HX}~" k8s-deployment.yaml
- cat k8s-deployment.yaml
- kubectl apply -n ${CHEMBL_NS_PROD} -f k8s-deployment.yaml
- kubectl get pods -n ${CHEMBL_NS_PROD}
- cat ${INGRESS_PROD_HX_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_PROD} -f ${INGRESS_PROD_HX_FILE_PATH}
- kubectl describe ingress -n ${CHEMBL_NS_PROD}
- cat ${AUTOSCALER_PROD_HX_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_PROD} -f ${AUTOSCALER_PROD_HX_FILE_PATH}
functional_tests_prod_hx:
stage: test_prod_hx
image:
name: $SERVER_IMAGE_TAG
entrypoint: [""]
only:
- master
script:
- set -x
- sleep 30 # Give some time for the deployment to take effect.
- echo 'Enable this soon!'
# - functional_tests/run_functional_tests.py ${SERVER_URL_PROD_HX} https://wwwdev.ebi.ac.uk/chembl/interface_api/delayed_jobs
## ----------------------------------------------------------------------------------------------------------------------
## Deployment to prod hh
## ----------------------------------------------------------------------------------------------------------------------
prepare_config_prod_hh:
stage: prepare_config_hh
image:
name: alpine/git
entrypoint: ["/bin/sh", "-c"]
only:
- master
script:
- rm -rf ${CONFIGS_FOLDER} || true
- mkdir -p ${CONFIGS_FOLDER}
- git clone https://${CONFIG_DEPLOY_GITLAB_USERNAME}:${CONFIG_DEPLOY_GITLAB_TOKEN}@${CONFIGURATIONS_REPO} ${CONFIGS_FOLDER}
- ls ${CONFIGS_FOLDER}
artifacts:
paths:
- ${CONFIG_PROD_HH_FILE_PATH}
- ${CONFIG_GUNICORN_PROD_HH_FILE_PATH}
- ${INGRESS_PROD_HH_FILE_PATH}
- ${AUTOSCALER_PROD_HH_FILE_PATH}
deploy_to_prod_hh:
stage: deploy_to_prod_hh
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
only:
- master
environment:
name: prod_hh
script:
- set -x
- echo "$KUBE_CA_PEM_HH" > "$(pwd)/kube.ca.pem"
- kubectl config set-cluster ${KUBE_CLUS_NAME_HH} --server="${KUBE_URL_HH}" --certificate-authority="$(pwd)/kube.ca.pem"
- kubectl config set-credentials ${KUBE_USER_HH} --token="${KUBE_TOKEN_HH}"
- kubectl config set-context ${CHEMBL_NS_PROD} --cluster=${KUBE_CLUS_NAME_HH} --user=${KUBE_USER_HH}
- kubectl config use-context ${CHEMBL_NS_PROD}
- echo ${CHEMBL_NS_PROD} ${KUBE_URL_HH} ${KUBE_CLUS_NAME_HH} ${KUBE_USER_HH}
- kubectl get pods -n ${CHEMBL_NS_PROD}
- kubectl create secret generic ${RUN_CONFIG_SECRET_NAME_PROD_HH} --from-file=RUN_CONFIG.yml=${CONFIG_PROD_HH_FILE_PATH} -o yaml -n ${CHEMBL_NS_PROD} --dry-run=client | kubectl replace -f -
- kubectl create secret generic ${GUNICORN_CONFIG_SECRET_NAME_PROD_HH} --from-file=GUNICORN_CONFIG.py=${CONFIG_GUNICORN_PROD_HH_FILE_PATH} -o yaml -n ${CHEMBL_NS_PROD} --dry-run=client | kubectl replace -f -
- cat ${CONFIG_PROD_HH_FILE_PATH}
- cat ${CONFIG_GUNICORN_PROD_HH_FILE_PATH}
- sed -i "s~<NAMESPACE>~${CHEMBL_NS_PROD}~" k8s-deployment.yaml
- sed -i "s~<NUM_REPLICAS>~${NUM_REPLICAS_PROD_HH}~" k8s-deployment.yaml
- sed -i "s~<STATICS_UID>~${STATIC_FILES_UID}~g" k8s-deployment.yaml
- sed -i "s~<STATICS_GID>~${STATIC_FILES_GID}~g" k8s-deployment.yaml
- sed -i "s~<HTTP_PROXY>~${HTTP_PROXY_HH}~g" k8s-deployment.yaml
- sed -i "s~<HTTPS_PROXY>~${HTTPS_PROXY_HH}~g" k8s-deployment.yaml
- sed -i "s~<NO_PROXY>~${NO_PROXY_HH_DEFAULT}~g" k8s-deployment.yaml
- sed -i "s~<CPU_LIMIT>~${CPU_LIMIT_PROD_HH}~" k8s-deployment.yaml
- sed -i "s~<CPU_REQUESTED>~${CPU_REQUESTED_PROD_HH}~" k8s-deployment.yaml
- sed -i "s~<SERVER_IMAGE_TAG>~${LATEST_PROD_IMAGE_TAG}~" k8s-deployment.yaml
- sed -i "s~<RUN_CONFIG_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_PROD_HH}~" k8s-deployment.yaml
- sed -i "s~<GUNICORN_CONFIG_SECRET_NAME>~${GUNICORN_CONFIG_SECRET_NAME_PROD_HH}~" k8s-deployment.yaml
- cat k8s-deployment.yaml
- kubectl apply -n ${CHEMBL_NS_PROD} -f k8s-deployment.yaml
- kubectl get pods -n ${CHEMBL_NS_PROD}
- cat ${INGRESS_PROD_HH_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_PROD} -f ${INGRESS_PROD_HH_FILE_PATH}
- kubectl describe ingress -n ${CHEMBL_NS_PROD}
- cat ${AUTOSCALER_PROD_HH_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_PROD} -f ${AUTOSCALER_PROD_HH_FILE_PATH}
functional_tests_prod_hh:
stage: test_prod_hh
image:
name: $SERVER_IMAGE_TAG
entrypoint: [""]
only:
- master
script:
- set -x
- echo 'Enable this soon!'
# - sleep 30 # Give some time for the deployment to take effect.
# - functional_tests/run_functional_tests.py ${SERVER_URL_PROD_HH} https://www.ebi.ac.uk/chembl/interface_api/delayed_jobs
# ----------------------------------------------------------------------------------------------------------------------
# Test prod public url
# ----------------------------------------------------------------------------------------------------------------------
functional_tests_prod_public:
stage: functional_tests_prod_public
image:
name: $SERVER_IMAGE_TAG
entrypoint: [""]
only:
- master
script:
- set -x
- echo 'enable this soon!'
# - sleep 30 # Give some time for the deployment to take effect.
# - functional_tests/run_functional_tests.py ${SERVER_URL_PROD_PUBLIC} https://www.ebi.ac.uk/chembl/interface_api/delayed_jobs