.gitlab-ci.yml 5.23 KB
Newer Older
1
2
3
variables:
  DOCKER_TLS_CERTDIR: ""
  GIT_STRATEGY: clone
4
  REGISTRY_USER: chembl/chembl
David Mendez's avatar
David Mendez committed
5
  APPLICATION: delayed-jobs/delayed-jobs-api/delayed-jobs-server
6
  IMAGE_TAG: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION:${CI_COMMIT_SHORT_SHA}
7
8
9
  DOCKER_IMAGE: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION
  DOCKER_DRIVER: overlay

10
image: docker:latest
David Mendez's avatar
David Mendez committed
11

12
13
14
services:
  - docker:dind

David Mendez's avatar
David Mendez committed
15
stages:
16
17
  - build
  - test_and_qa
18
  - deploy_to_staging
David Mendez's avatar
David Mendez committed
19

20
# ----------------------------------------------------------------------------------------------------------------------
21
# build
22
# ----------------------------------------------------------------------------------------------------------------------
23
build_docker_image:
24
  image:
25
    name: docker/compose:1.24.1
26
    entrypoint: ["/bin/sh", "-c"]
27
  stage: build
28
29
  variables:
    DOCKER_HOST: tcp://docker:2375
30
  script:
31
    - set -x
32
33
    - 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
34
    - echo building $IMAGE_TAG
35
36
37
    - docker-compose build delayed-jobs-server-prod
    - echo Deploying $IMAGE_TAG
    - docker push $IMAGE_TAG
38

39
40
41
# ----------------------------------------------------------------------------------------------------------------------
# QA
# ----------------------------------------------------------------------------------------------------------------------
42
pylint:
43
  stage: test_and_qa
44
45
  image:
    name: $IMAGE_TAG
46
    entrypoint: [""]
47
  script:
48
  - pwd
49
  - ls
50
  - echo 'disabled temporarily'
51

David Mendez's avatar
David Mendez committed
52
53
54
# ----------------------------------------------------------------------------------------------------------------------
# Tests
# ----------------------------------------------------------------------------------------------------------------------
55
unit_tests:
56
  stage: test_and_qa
57
58
  image:
    name: $IMAGE_TAG
59
    entrypoint: [""]
60
  script:
David Mendez's avatar
David Mendez committed
61
  - env
62
  # Reminder for David: put here all tests that should be ready until you finish and then run all
63
64
  - CONFIG_FILE_PATH='./configurations/ci_unit_tests_config.yml' python -m unittest app.models.test.test_models.TestModels
  - CONFIG_FILE_PATH='./configurations/ci_unit_tests_config.yml' python -m unittest app.models.test.test_expired_job_deletion.TestExpiredJobDeletion
65
  - CONFIG_FILE_PATH='./configurations/ci_unit_tests_config.yml' python -m unittest app.namespaces.job_submission.services.test.test_job_submission.TestJobSubmitter
David Mendez's avatar
David Mendez committed
66
#  - CONFIG_FILE_PATH='./configurations/ci_unit_tests_config.yml' python -m unittest
67
68
69
70
71

functional_tests:
  stage: test_and_qa
  image:
    name: $IMAGE_TAG
72
    entrypoint: [""]
73
  script:
74
75
76
77
78
79
80
81
82
83
84
85
86
  - echo 'Disabled temporarily'
#  - rm -rf app/static/jobs_output || true
#  - rm -rf jobs_run || true
#  - CONFIG_FILE_PATH='./configurations/ci_functional_tests_config.yml' FLASK_APP=app flask run > functional_tests_run.log 2>&1 &
#  - sleep 5
#  - head functional_tests_run.log
#  - SERVER_PID=$!
#  - pushd app/functional_tests
#  - ./run_functional_tests.py
#  - popd
#  - kill $SERVER_PID
#  - rm -rf app/static/jobs_output
#  - rm -rf jobs_run
87

David Mendez's avatar
David Mendez committed
88
89
90
# ----------------------------------------------------------------------------------------------------------------------
# Deployment to staging
# ----------------------------------------------------------------------------------------------------------------------
91
deploy_to_staging:
92
  stage: deploy_to_staging
93
94
  image:
    name: lachlanevenson/k8s-kubectl:latest
95
    entrypoint: ["/bin/sh", "-c"]
96
97
98
99
100
  when: manual
  only:
  - staging
  environment:
    name: staging
David Mendez's avatar
David Mendez committed
101
    url: http://hx-rke-wp-webadmin-04-worker-3.caas.ebi.ac.uk:31688/chembl/interface_api/delayed_jobs/
102
103
  script:
  - set -x
104
105
106
  - 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}"
David Mendez's avatar
David Mendez committed
107
108
109
110
  - 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}
111
  - kubectl create secret generic ${ID_RSA_SECRET_NAME_STAGING} --from-file=ID_RSA_LSF=${ID_RSA_LSF_HX} -o yaml -n ${CHEMBL_NS_STAGING} --dry-run | kubectl replace -f -
David Mendez's avatar
David Mendez committed
112
  - kubectl create secret generic ${RUN_CONFIG_SECRET_NAME_STAGING} --from-file=RUN_CONFIG=${RUN_CONFIG_STAGING} -o yaml -n ${CHEMBL_NS_STAGING} --dry-run | kubectl replace -f -
113
  - cat ${RUN_CONFIG_STAGING}
David Mendez's avatar
David Mendez committed
114
  - sed -i "s~<NAMESPACE>~${CHEMBL_NS_STAGING}~" k8s-deployment.yaml
David Mendez's avatar
David Mendez committed
115
116
  - sed -i "s~<UID>~${CBL_ADM_UID_HX}~" k8s-deployment.yaml
  - sed -i "s~<GID>~${CBL_PUB_GID_HX}~" k8s-deployment.yaml
117
  - sed -i "s~<IMAGE_TAG>~${IMAGE_TAG}~" k8s-deployment.yaml
David Mendez's avatar
David Mendez committed
118
  - sed -i "s~<NFS_MOUNT_PATH>~${NFS_MOUNT_PATH_STAGING}~" k8s-deployment.yaml
David Mendez's avatar
David Mendez committed
119
  - sed -i "s~<NFS_FQDN>~${NFS_FQDN_HX}~" k8s-deployment.yaml
David Mendez's avatar
David Mendez committed
120
  - sed -i "s~<NFS_PATH>~${NFS_PATH_HX}~" k8s-deployment.yaml
121
  - sed -i "s~<ID_RSA_SECRET_NAME>~${ID_RSA_SECRET_NAME_STAGING}~" k8s-deployment.yaml
David Mendez's avatar
David Mendez committed
122
  - sed -i "s~<RUN_CONFIG_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_STAGING}~" k8s-deployment.yaml
123
  - cat k8s-deployment.yaml
David Mendez's avatar
David Mendez committed
124
  - kubectl apply -n ${CHEMBL_NS_STAGING} -f k8s-deployment.yaml
David Mendez's avatar
David Mendez committed
125
  - kubectl get pods -n ${CHEMBL_NS_STAGING}