-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy path.gitlab-ci.yml
149 lines (133 loc) · 5.26 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
variables:
DOCKER_TLS_CERTDIR: ""
GIT_STRATEGY: clone
REGISTRY_USER: chembl/chembl
APPLICATION: chembl_beaker
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
- test
- deploy
# --------------------------- STAGING --------------------------------------------
build-staging:
stage: build
only:
- staging
before_script:
- mkdir -p $HOME/.docker
- echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
- cat $HOME/.docker/config.json
script:
- docker version # verify docker cli is there. Also prints server info
- echo Building $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA}
- docker build -t $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA} .
- echo Deploying $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA}
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- docker push ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
test-staging:
stage: test
only:
- staging
dependencies:
- build-staging
script:
- docker run --entrypoint python ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA} chembl_beaker/test_beaker.py
- echo "done"
deploy-staging:
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy
dependencies:
- test-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_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~<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
only:
- staging
# --------------------------- PROD -------------------------------------------
build-prod:
stage: build
only:
- master
variables:
DOCKER_HOST: tcp://docker:2375
before_script:
- mkdir -p $HOME/.docker
- echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
- cat $HOME/.docker/config.json
script:
- docker version # verify docker cli is there. Also prints server info
- echo Building $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA}
- docker build -t $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA} .
- echo Deploying $DOCKER_IMAGE:${CI_COMMIT_SHORT_SHA}
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- docker push ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
test-prod:
only:
- master
dependencies:
- build-prod
script:
- docker run --entrypoint python ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA} chembl_beaker/test_beaker.py
- echo "done"
deploy-prod-hx:
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy
dependencies:
- test-prod
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~<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
only:
- master
deploy-prod-hh:
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy
dependencies:
- test-prod
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~<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
only:
- master
after_script:
- echo "End of script"