.gitlab-ci.yml 14 KB
Newer Older
1
2
3
4
variables:
  DOCKER_TLS_CERTDIR: ""
  GIT_STRATEGY: clone
  REGISTRY_USER: chembl/chembl
David Mendez's avatar
David Mendez committed
5
  SERVER_APPLICATION: main-web-interface/elasticsearch-proxy-api
6
7
8
  SERVER_IMAGE_TAG: ${CI_REGISTRY}/${REGISTRY_USER}/${SERVER_APPLICATION}:${CI_COMMIT_SHORT_SHA}
  DOCKER_DRIVER: overlay
  CONFIGS_FOLDER: run_config
9
  CONFIG_UNIT_TESTS_FILE_PATH: ${CONFIGS_FOLDER}/unit_tests.yml
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  CONFIG_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging.yml
  CONFIG_GUNICORN_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging.gunicorn.config.py
  CONFIG_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/prod_hx.yml
  CONFIG_GUNICORN_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/prod_hx.gunicorn.config.py
  CONFIG_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/prod_hh.yml
  CONFIG_GUNICORN_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/prod_hh.gunicorn.config.py

image: docker:latest

services:
  - docker:dind

stages:
  - build
24
  - prepare_config_tests
David Mendez's avatar
David Mendez committed
25
  - test_and_qa
David Mendez's avatar
David Mendez committed
26
  - prepare_config_staging
27
  - deploy_to_staging
David Mendez's avatar
David Mendez committed
28
  - test_staging
David Mendez's avatar
David Mendez committed
29
  - prepare_config_hx
30
  - deploy_to_prod_hx
31
  - test_prod_hx
32
33
34
35
36
37
38
39
40
#  - prepare_config_hh
#  - deploy_to_prod_hh
#  - test_prod_hh
#  - functional_tests_prod_public
#  - schedules

# ----------------------------------------------------------------------------------------------------------------------
# build
# ----------------------------------------------------------------------------------------------------------------------
41
build_docker_image:
David Mendez's avatar
David Mendez committed
42
43
44
45
46
47
48
49
50
51
52
  image:
    name: docker/compose:1.24.1
    entrypoint: ["/bin/sh", "-c"]
  stage: build
  variables:
    DOCKER_HOST: tcp://docker:2375
  script:
    - set -x
    - 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
David Mendez's avatar
David Mendez committed
53
    - docker-compose build elasticsearch-proxy-api-prod
David Mendez's avatar
David Mendez committed
54
55
    - echo Deploying $SERVER_IMAGE_TAG
    - docker push $SERVER_IMAGE_TAG
David Mendez's avatar
David Mendez committed
56

57
58
59
## ----------------------------------------------------------------------------------------------------------------------
## QA
## ----------------------------------------------------------------------------------------------------------------------
David Mendez's avatar
David Mendez committed
60
61
62
63
64
65
pylint:
  stage: test_and_qa
  image:
    name: $SERVER_IMAGE_TAG
    entrypoint: [""]
  script:
David Mendez's avatar
David Mendez committed
66
    - set -x
David Mendez's avatar
David Mendez committed
67
68
    - find . -iname "*.py" | xargs pylint

69
## ---------------------------------------------------------------------------------------------------------------------
70
## Tests
71
72
73
74
75
76
77
## ---------------------------------------------------------------------------------------------------------------------
prepare_config_tests:
  stage: prepare_config_tests
  image:
    name: alpine/git
    entrypoint: ["/bin/sh", "-c"]
  script:
David Mendez's avatar
David Mendez committed
78
    - set -x
79
80
81
82
83
84
    - 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}

David Mendez's avatar
David Mendez committed
85
86
87
88
89
90
unit_tests:
  stage: test_and_qa
  image:
    name: $SERVER_IMAGE_TAG
    entrypoint: [""]
  script:
David Mendez's avatar
David Mendez committed
91
    - set -x
92
    - CONFIG_FILE_PATH=${CONFIG_UNIT_TESTS_FILE_PATH} python -m unittest
David Mendez's avatar
David Mendez committed
93

94
95
96
## ----------------------------------------------------------------------------------------------------------------------
## Deployment to staging
## ----------------------------------------------------------------------------------------------------------------------
David Mendez's avatar
David Mendez committed
97
98
99
100
101
prepare_config_staging:
  stage: prepare_config_staging
  image:
    name: alpine/git
    entrypoint: ["/bin/sh", "-c"]
102
103
  only:
    - staging
David Mendez's avatar
David Mendez committed
104
105
  script:
    - set -x
106
    - rm -rf ${CONFIGS_FOLDER} || true
David Mendez's avatar
David Mendez committed
107
108
109
110
111
112
113
    - 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}

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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}
David Mendez's avatar
David Mendez committed
133
134
  - 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 -
135
136
137
138
139
140
141
142
143
144
  - cat ${CONFIG_STAGING_FILE_PATH}
  - cat ${CONFIG_GUNICORN_STAGING_FILE_PATH}
  - sed -i "s~<NAMESPACE>~${CHEMBL_NS_STAGING}~" k8s-deployment.yaml
  - sed -i "s~<NUM_REPLICAS>~${NUM_REPLICAS_STAGING}~" k8s-deployment.yaml
  - sed -i "s~<SERVER_IMAGE_TAG>~${SERVER_IMAGE_TAG}~" k8s-deployment.yaml
  - sed -i "s~<RUN_CONFIG_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_STAGING}~" k8s-deployment.yaml
  - sed -i "s~<GUNICORN_CONFIG_SECRET_NAME>~${GUNICORN_CONFIG_SECRET_NAME_STAGING}~" k8s-deployment.yaml
  - cat k8s-deployment.yaml
  - kubectl apply -n ${CHEMBL_NS_STAGING} -f k8s-deployment.yaml
  - kubectl get pods -n ${CHEMBL_NS_STAGING}
145
146
147
148
#
## ----------------------------------------------------------------------------------------------------------------------
## Test staging
## ----------------------------------------------------------------------------------------------------------------------
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
functional_tests:
  stage: test_staging
  image:
    name: $SERVER_IMAGE_TAG
    entrypoint: [""]
  only:
    - staging
  environment:
    name: staging
    url: ${SERVER_URL_STAGING}
  script:
  - set -x
  - exit 0 # disabled temporarily
  - sleep 30 # Give some time for the deployment to take effect.
  - functional_tests/run_functional_tests.py ${SERVER_URL_STAGING} ${DJ_SERVER_ADMIN_USERNAME_STAGING} ${DJ_SERVER_ADMIN_PASSWORD_STAGING}
164
165
166
167
#
## ----------------------------------------------------------------------------------------------------------------------
## Deployment to prod hx
## ----------------------------------------------------------------------------------------------------------------------
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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}
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

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}
202
    - 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 -
203
    - 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 -
204
205
206
207
208
209
210
211
212
213
214
    - 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~<UID>~${CBL_ADM_UID}~" k8s-deployment.yaml
    - sed -i "s~<GID>~${CBL_PUB_GID}~" k8s-deployment.yaml
    - sed -i "s~<SERVER_IMAGE_TAG>~${SERVER_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}

215
216
217
218
219
220
221
222
223
224
225
226
227
functional_tests_prod_hx:
  stage: test_prod_hx
  image:
    name: $SERVER_IMAGE_TAG
    entrypoint: [""]
  only:
  - master
  script:
  - set -x
  - exit 0 # disabled temporarily
  - sleep 30 # Give some time for the deployment to take effect.
  - functional_tests/run_functional_tests.py ${SERVER_URL_PROD_HX} ${DJ_SERVER_ADMIN_USERNAME_PROD_HX} ${DJ_SERVER_ADMIN_PASSWORD_PROD_HX}

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
## ----------------------------------------------------------------------------------------------------------------------
## Deployment to prod hh
## ----------------------------------------------------------------------------------------------------------------------
#prepare_config_prod_hh:
#  stage: prepare_config_hh
#  image:
#    name: alpine/git
#    entrypoint: ["/bin/sh", "-c"]
#  only:
#    - master
#  except:
#    - schedules
#  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_HH_FILE_PATH}
#      - ${CONFIG_GUNICORN_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
#  except:
#    - schedules
#  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 ${ID_RSA_SECRET_NAME_PROD_HH} --from-file=ID_RSA_LSF=${ID_RSA_LSF_HH} -o yaml -n ${CHEMBL_NS_PROD} --dry-run | kubectl apply -f -
#    - 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 | kubectl apply -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 | kubectl apply -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~<UID>~${CBL_ADM_UID}~" k8s-deployment.yaml
#    - sed -i "s~<GID>~${CBL_PUB_GID}~" k8s-deployment.yaml
#    - sed -i "s~<SERVER_IMAGE_TAG>~${SERVER_IMAGE_TAG}~" k8s-deployment.yaml
#    - sed -i "s~<STATUS_DAEMON_IMAGE_TAG>~${STATUS_DAEMON_IMAGE_TAG}~" k8s-deployment.yaml
#    - sed -i "s~<NFS_MOUNT_PATH>~${NFS_MOUNT_PATH_PROD_HH}~" k8s-deployment.yaml
#    - sed -i "s~<NFS_FQDN>~${NFS_FQDN_HH}~" k8s-deployment.yaml
#    - sed -i "s~<NFS_PATH>~${NFS_PATH_HH}~" k8s-deployment.yaml
#    - sed -i "s~<ID_RSA_SECRET_NAME>~${ID_RSA_SECRET_NAME_PROD_HH}~" 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}
#
#functional_tests_prod_hh:
#  stage: test_prod_hh
#  image:
#    name: $SERVER_IMAGE_TAG
#    entrypoint: [""]
#  only:
#  - master
#  except:
#    - schedules
#  script:
#  - set -x
#  - sleep 30 # Give some time for the deployment to take effect.
#  - functional_tests/run_functional_tests.py ${SERVER_URL_PROD_HH} ${DJ_SERVER_ADMIN_USERNAME_PROD_HH} ${DJ_SERVER_ADMIN_PASSWORD_PROD_HH}
#
## ----------------------------------------------------------------------------------------------------------------------
## Test prod public url
## ----------------------------------------------------------------------------------------------------------------------
#functional_tests_prod_public:
#  stage: functional_tests_prod_public
#  image:
#    name: $SERVER_IMAGE_TAG
#    entrypoint: [""]
#  only:
#  - master
#  except:
#    - schedules
#  script:
#  - set -x
#  - sleep 30 # Give some time for the deployment to take effect.
#  - functional_tests/run_functional_tests.py ${SERVER_URL_PROD_PUBLIC} ${DJ_SERVER_ADMIN_USERNAME_PROD_HX} ${DJ_SERVER_ADMIN_PASSWORD_PROD_PUBLIC}
#
## ----------------------------------------------------------------------------------------------------------------------
## Schedules
## ----------------------------------------------------------------------------------------------------------------------
#delete_expired_jobs:
#  stage: schedules
#  image: 'python:3.7'
#  only:
#    - schedules
#  script:
#    - set -x
#    - pip install requests
#    - admin_tasks/delete_expired_jobs.py ${SERVER_URL_STAGING} ${DJ_SERVER_ADMIN_USERNAME_STAGING} ${DJ_SERVER_ADMIN_PASSWORD_STAGING}
#    - admin_tasks/delete_expired_jobs.py ${SERVER_URL_PROD_PUBLIC} ${DJ_SERVER_ADMIN_USERNAME_PROD_HX} ${DJ_SERVER_ADMIN_PASSWORD_PROD_PUBLIC}