.gitlab-ci.yml 9.33 KB
Newer Older
1
# DEploy feature branch
2
3
4
5
6
stages:
  - test
  - test_build_static
  - build_docker_images
  - deploy
Andrey Azov's avatar
Andrey Azov committed
7

8
9
variables:
  CONTAINER_IMAGE: $GITLAB_REGISTRY_URL/$GITLAB_REGISTRY_NAMESPACE/ensembl-client:${CI_COMMIT_SHORT_SHA}
10
  CONTAINER_INTERNAL_IMAGE: $GITLAB_REGISTRY_URL/$GITLAB_REGISTRY_NAMESPACE/ensembl-client:${CI_COMMIT_SHORT_SHA}-internal
11
12
13
  KUBECONFIG: /etc/deploy/config
  KUBECONTEXT: ens-dev-ctx
  DEPLOYENV: dev
14
  ENVIRONMENT: production
15
  DOCKER_TLS_CERTDIR: ""
Andrey Azov's avatar
Andrey Azov committed
16

17
Test:
18
  image: node:10.16.0
19
  stage: test
Andrey Azov's avatar
Andrey Azov committed
20

21
22
23
24
25
  before_script:
  - cd src/ensembl
  - npm ci

  script:
26
  - npm run check-types
27
28
29
30
31
  - npm run test

  except:
  - dev
  - master
32
  - /^feature\/.*$/
33

34
Test_N_Build:
35
  image: node:10.16.0
36
37
38
39
40
41
42
43
44
  stage: test_build_static

  before_script:
  - cd src/ensembl
  - npm ci

  script:
  - npm run test
  - export NODE_ENV=production
45
46
47
  - export GOOGLE_ANALYTICS_KEY=${GA_KEY}
  - export ENVIRONMENT=production
  - export API_HOST=""
48
49
50
51
52
53
54
55
56
57
58
  - npm run build

  artifacts:
    name: static_assets
    paths:
    - src/ensembl/dist/

  only:
  - dev
  - master

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Test_N_Build:internal:
  image: node:10.16.0
  stage: test_build_static

  before_script:
  - cd src/ensembl
  - npm ci

  script:
  - npm run test
  - export NODE_ENV=development
  - export GOOGLE_ANALYTICS_KEY=${GA_KEY}
  - export ENVIRONMENT=internal
  - export API_HOST=""
  - npm run build

  artifacts:
    name: static_assets_internal
    paths:
    - src/ensembl/dist/

  only:
  - master

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Test_N_Build:feature:
  image: node:10.16.0
  stage: test_build_static

  before_script:
  - cd src/ensembl
  - npm ci

  script:
  - npm run test
  - export NODE_ENV=development
  - export GOOGLE_ANALYTICS_KEY=${GA_KEY}
  - export ENVIRONMENT=development
  - export API_HOST=""
  - npm run build

  artifacts:
    name: static_assets_feature
    paths:
    - src/ensembl/dist/

  only:
  - /^feature\/.*$/

107
108
Nginx:
  image: docker
109

110
111
  services:
    - docker:dind
112

113
114
115
  stage: build_docker_images

  before_script:
116
  - case "${CI_COMMIT_REF_NAME}" in dev) DEPLOYENV="staging" ;; master) DEPLOYENV="prod" ;; cicd-test) DEPLOYENV="staging" ;; *) DEPLOYENV="dev" ;; esac
117
118
119
120

  script:
  - apk update && apk add git
  - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git
121
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git
122
123
124
  - cd ensembl-client-nginx
  - git checkout june-release
  - cd ..
125
  - sed -i "s/<DEPLOYMENT_ENV>/${DEPLOYENV}/g" ensembl-client-nginx/config/conf.d/local.conf
126
  - docker build -t ${CONTAINER_IMAGE}-${DEPLOYENV} -f ensembl-client-nginx/Dockerfile --no-cache .
127
  - echo "$GITLAB_REGISTRY_TOKEN" | docker login -u "$GITLAB_REGISTRY_USER" --password-stdin https://"$GITLAB_REGISTRY_URL"
128
129
  - docker push ${CONTAINER_IMAGE}-${DEPLOYENV}
  - docker rmi ${CONTAINER_IMAGE}-${DEPLOYENV}
130
131
132
133
134
135
  - docker logout "$GITLAB_REGISTRY_URL"

  only:
  - dev
  - master

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
  dependencies:
  - Test_N_Build

Nginx:internal:
  image: docker

  services:
    - docker:dind

  stage: build_docker_images

  before_script:
  - case "${CI_COMMIT_REF_NAME}" in dev) DEPLOYENV="staging" ;; master) DEPLOYENV="prod" ;; cicd-test) DEPLOYENV="staging" ;; *) DEPLOYENV="dev" ;; esac

  script:
  - apk update && apk add git
  - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git
  - cd ensembl-client-nginx
  - git checkout june-release
  - cd ..
  - sed -i "s/<DEPLOYMENT_ENV>/internal/g" ensembl-client-nginx/config/conf.d/local.conf
  - cat ensembl-client-nginx/config/conf.d/local.conf
  - docker build -t ${CONTAINER_INTERNAL_IMAGE} -f ensembl-client-nginx/Dockerfile --no-cache .
  - echo "$GITLAB_REGISTRY_TOKEN" | docker login -u "$GITLAB_REGISTRY_USER" --password-stdin https://"$GITLAB_REGISTRY_URL"
161
162
  - docker push ${CONTAINER_IMAGE}-internal
  - docker rmi ${CONTAINER_IMAGE}-internal
163
164
165
166
167
168
169
170
  - docker logout "$GITLAB_REGISTRY_URL"

  only:
  - master

  dependencies:
  - Test_N_Build:internal

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
Nginx:feature:
  image: docker

  services:
    - docker:dind

  stage: build_docker_images

  before_script:
  - case "${CI_COMMIT_REF_NAME}" in dev) DEPLOYENV="staging" ;; master) DEPLOYENV="prod" ;; cicd-test) DEPLOYENV="staging" ;; *) DEPLOYENV="dev" ;; esac

  script:
  - feature_branch=${CI_COMMIT_REF_NAME}
  - feature_tag=${feature_branch#"feature/"}
  - apk update && apk add git
  - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git
  - cd ensembl-client-nginx
  - git checkout june-release
  - cd ..
  - sed -i "s/<DEPLOYMENT_ENV>/internal/g" ensembl-client-nginx/config/conf.d/local.conf
  - cat ensembl-client-nginx/config/conf.d/local.conf
  - docker build -t ${CONTAINER_IMAGE}-$feature_tag -f ensembl-client-nginx/Dockerfile --no-cache .
  - echo "$GITLAB_REGISTRY_TOKEN" | docker login -u "$GITLAB_REGISTRY_USER" --password-stdin https://"$GITLAB_REGISTRY_URL"
  - docker push ${CONTAINER_IMAGE}-$feature_tag
  - docker rmi ${CONTAINER_IMAGE}-$feature_tag
  - docker logout "$GITLAB_REGISTRY_URL"

  only:
  - /^feature\/.*$/

  dependencies:
  - Test_N_Build:feature
204
205

Staging:
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}
  script:
  - apk update && apk add --no-cache curl git
  - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  - chmod +x ./kubectl
  - mv ./kubectl /usr/local/bin/kubectl
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git
  - cd ensembl-client-caas-deploy
  - git checkout refactor-manifest
  - cd ..
220
  - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}-staging/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
221
  - sed -i "s/<DEPLOYMNET_ENV>/staging/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
222
223
  - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - kubectl config view
224
  - kubectl config use-context ens-stage-ctx
225
226
227
  - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml

  only:
228
  - dev
229
230

  dependencies:
231
  - Nginx
232

233
Live:
234
235
236
237
238
239
240
241
242
243
244
245
246
247
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}
  script:
  - apk update && apk add --no-cache curl git
  - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  - chmod +x ./kubectl
  - mv ./kubectl /usr/local/bin/kubectl
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git
  - cd ensembl-client-caas-deploy
  - git checkout refactor-manifest
  - cd ..
248
  - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}-prod/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
249
  - sed -i "s/<DEPLOYMNET_ENV>/prod/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
250
251
  - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - kubectl config view
252
  - kubectl config use-context ens-prod-ctx
253
  - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml
254

255
  only:
256
  - master
257

258
259
260
  dependencies:
  - Nginx

261
Deploy:internal:
262
263
264
265
266
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}
267

Andrey Azov's avatar
Andrey Azov committed
268
  script:
269
270
271
272
273
274
275
276
  - apk update && apk add --no-cache curl git
  - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  - chmod +x ./kubectl
  - mv ./kubectl /usr/local/bin/kubectl
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git
  - cd ensembl-client-caas-deploy
  - git checkout refactor-manifest
  - cd ..
277
278
  - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}-internal/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - sed -i "s/<DEPLOYMNET_ENV>/internal/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
279
280
  - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - kubectl config view
281
  - kubectl config use-context ens-dev-ctx
282
  - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml
283

284
285
  only:
  - master
286
287

  dependencies:
288
  - Nginx:internal
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

Deploy:feature:
  stage: deploy
  image: alpine
  before_script:
  - mkdir -p /etc/deploy
  - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG}

  script:
  - feature_branch=${CI_COMMIT_REF_NAME}
  - feature_tag=${feature_branch#"feature/"}
  - apk update && apk add --no-cache curl git
  - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  - chmod +x ./kubectl
  - mv ./kubectl /usr/local/bin/kubectl
  - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git
  - cd ensembl-client-caas-deploy
  - git checkout refactor-manifest
  - cd ..
  - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}-$feature_tag/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - sed -i "s/<DEPLOYMNET_ENV>/$feature_tag/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml
  - kubectl config view
  - kubectl config use-context ens-dev-ctx
  - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml

  only:
  - /^feature\/.*$/

  dependencies:
  - Nginx:feature