forked from chembl/chembl_webservices_py3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
121 lines (109 loc) · 5.18 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
variables:
DOCKER_TLS_CERTDIR: ""
GIT_STRATEGY: clone
REGISTRY_USER: chembl/chembl
APPLICATION: chembl_webservices_py3
RELEASE_IMAGE: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION:$CI_BUILD_REF_NAME
DOCKER_IMAGE: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION
DOCKER_DRIVER: overlay
image: docker:latest
services:
- docker:dind
stages:
- build
- deploy-staging
- deploy-production
# build image ----------------------------------------------------------------------------------------------------------
build-dockerfile:
only:
- master
stage: build
variables:
DOCKER_HOST: tcp://docker:2375
script:
- 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 $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA}
- echo CBL_ADM_USERNAME:${CBL_ADM_USERNAME}
- echo CBL_ADM_UID:${CBL_ADM_UID}
- echo CBL_PUB_GID:${CBL_PUB_GID}
- docker build --build-arg USERNAME=${CBL_ADM_USERNAME} --build-arg UID=${CBL_ADM_UID} --build-arg GID=${CBL_PUB_GID} -t $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA} .
- echo Deploying $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA}
- docker push ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
when: manual
# Deployment in staging ------------------------------------------------------------------------------------------------
deploy-staging:
only:
- master
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy-staging
needs:
- build-dockerfile
script:
- echo $KUBE_URL_HX
- 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}
- sed -i "s~<RUN_AS_UID>~${CBL_ADM_UID}~" k8s-deployment.yml
- sed -i "s~<RUN_AS_GID>~${CBL_PUB_GID}~" k8s-deployment.yml
- sed -i "s~<VERSION>~${CI_COMMIT_SHORT_SHA}~" k8s-deployment.yml
- sed -i "s~<DOCKER_IMAGE>~${DOCKER_IMAGE}~" k8s-deployment.yml
- kubectl apply -n ${CHEMBL_NS_STAGING} -f k8s-deployment.yml
# Deployment in production ---------------------------------------------------------------------------------------------
deploy-prod-hx:
only:
- master
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy-production
needs:
- deploy-staging
script:
- echo $KUBE_URL_HX
- 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}
- sed -i "s~<RUN_AS_UID>~${CBL_ADM_UID}~" k8s-deployment.yml
- sed -i "s~<RUN_AS_GID>~${CBL_PUB_GID}~" k8s-deployment.yml
- sed -i "s~<VERSION>~${CI_COMMIT_SHORT_SHA}~" k8s-deployment.yml
- sed -i "s~<DOCKER_IMAGE>~${DOCKER_IMAGE}~" k8s-deployment.yml
- kubectl apply -n ${CHEMBL_NS_PROD} -f k8s-deployment.yml
when: manual
deploy-prod-hh:
only:
- master
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy-production
needs:
- deploy-staging
script:
- echo $KUBE_URL_HH
- 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}
- sed -i "s~<RUN_AS_UID>~${CBL_ADM_UID}~" k8s-deployment.yml
- sed -i "s~<RUN_AS_GID>~${CBL_PUB_GID}~" k8s-deployment.yml
- sed -i "s~<VERSION>~${CI_COMMIT_SHORT_SHA}~" k8s-deployment.yml
- sed -i "s~<DOCKER_IMAGE>~${DOCKER_IMAGE}~" k8s-deployment.yml
- kubectl apply -n ${CHEMBL_NS_PROD} -f k8s-deployment.yml
when: manual
# end ------------------------------------------------------------------------------------------------------------------
after_script:
- echo "End of script"