-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
executable file
·204 lines (188 loc) · 6.17 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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
204
#
# See the NOTICE file distributed with this work for additional information
# regarding copyright ownership.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
NFS_SERVER: ${HL_NFS_SERVER_CODON}
NFS_PATH: ${HL_NFS_OPPATH_CODON}
stages:
- setup
- test
- build
- deploy-preview
- deploy
# Templates
.branch-rules-main:
rules:
- if: $CI_DEPLOY_FREEZE == null && $CI_COMMIT_BRANCH == "main"
when: on_success
.branch-rules-review:
rules:
- if: $CI_COMMIT_BRANCH != "main"
when: on_success
.deploy:
image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:latest
before_script:
- kubectl config use-context ${AGENT}
- kubectl config set-context --current --namespace=${NS}
script:
- git clone https://gitlab.ebi.ac.uk/ensembl-web/ensembl-k8s-manifests.git
- git -C ensembl-k8s-manifests/ checkout k8s123-migration
- cd ensembl-k8s-manifests/ensembl-web-tools-api
- sed -i "s#<NFS_SERVER>#${NFS_SERVER}#g" deployment.yaml
- sed -i "s#<NFS_PATH>#${NFS_PATH}#g" deployment.yaml
- kustomize edit set image DOCKER_IMAGE=${DOCKER_IMAGE}
- kubectl apply -k ./
.deploy-main:
extends:
- .deploy
- .branch-rules-main
# Run tests
Test:
stage: test
image: python:3.10
before_script:
- pip install -r requirements-dev.txt
- cp -r ./data /data
- cd app/
- cp .env.sample .env
- ls -al ../
script:
- python -m pytest --ignore=tests/test_vep.py --cov --junitxml=report.xml
coverage: '/^TOTAL.+?(\d+\%)$/'
artifacts:
when: always
reports:
junit: app/report.xml
# Build the docker image
Docker:
stage: build
image: docker
services:
- docker:dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build -t ${DOCKER_IMAGE} --no-cache .
- docker push ${DOCKER_IMAGE}
- docker rmi ${DOCKER_IMAGE}
- docker logout $CI_REGISTRY
# Deploy feature branch (for custom backend review apps)
Setup-review:
stage: setup
image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:latest
environment:
name: development
variables:
GIT_STRATEGY: none # ToolsAPI repo not needed here
AGENT: ${DEV_AGENT}
NS: ${CI_COMMIT_REF_SLUG}
rules: # Run once (when a feature branch is created)
- if: $CI_COMMIT_BRANCH != "main" &&
$CI_PIPELINE_SOURCE == "push" &&
$CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
when: always
script:
- kubectl config use-context ${AGENT}
# When needed: remove existing ingress, add review namespace & envvars
- kubectl config set-context --current --namespace=${DEV_NS}
- kubectl delete ingress ensembl-web-tools-api-ingress-${NS} || true
- kubectl create namespace ${NS} || true
- kubectl config set-context --current --namespace=${NS}
- kubectl create secret docker-registry ensemblweb-pull-secret --docker-server=${GITLAB_REGISTRY_URL}
--docker-username=${WEB_PULL_DOCKER_USER} --docker-password=${WEB_PULL_DOCKER_SECRET} --docker-email=${WEB_PULL_DOCKER_EMAIL} || true
# Setup ToolsAPI resources in review namespace (service, ingress, secret) + proxy config
- git clone --depth 1 --branch k8s123-migration https://gitlab.ebi.ac.uk/ensembl-web/ensembl-k8s-manifests.git
- cd ensembl-k8s-manifests/ensembl-web-tools-api
- kubectl apply -f service.yaml
- sed -i "s#HOST#${NS}.review.ensembl.org#" ingress.yaml
- kubectl apply -f ingress.yaml
- git clone https://config-ro-user:${CONFIG_RO_TOKEN}@gitlab.ebi.ac.uk/ensembl-web/newsite-api-config-setup.git
- cd newsite-api-config-setup
- kubectl create secret generic ensembl-web-tools-api-secret --from-env-file=review/tools-api.secret --dry-run=client -o yaml | kubectl apply -f -
- kubectl create configmap proxy-configmap --from-env-file=dev/hl/http-proxy.config --dry-run=client -o yaml | kubectl apply -f -
Review:
extends:
- .deploy
- .branch-rules-review
stage: deploy-preview
environment:
name: development
url: http://${NS}.review.ensembl.org
variables:
AGENT: ${DEV_AGENT}
NS: ${CI_COMMIT_REF_SLUG}
# Stop review app (cleanup backend resources)
Stop_review:
stage: deploy-preview
image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:latest
when: manual
rules:
- if: $CI_COMMIT_BRANCH != "main"
environment:
name: development
variables:
GIT_STRATEGY: none
AGENT: ${DEV_AGENT}
NS: ${CI_COMMIT_REF_SLUG}
script:
- kubectl config use-context ${AGENT}
- kubectl config set-context --current --namespace=${DEV_NS}
- kubectl delete ingress ensembl-web-tools-api-ingress
- kubectl delete service ensembl-web-tools-api-svc
- kubectl delete deploy ensembl-web-tools-api-deployment
- kubectl delete secret ensembl-web-tools-api-secret
- kubectl -n ${DEV_NS} delete namespace ${NS} || echo "Please delete ${NS} branch in Ensembl-client to cleanup the review namespace"
# Deploy main branch to dev/staging
Dev:
extends:
- .deploy-main
stage: deploy-preview
environment:
name: development
variables:
AGENT: ${DEV_AGENT}
NS: ${DEV_NS}
Staging:
extends:
- .deploy-main
stage: deploy-preview
environment:
name: staging
variables:
AGENT: ${STAGING_AGENT}
NS: ${STAGING_NS}
# Deploy main branch to production
Production:
extends:
- .deploy-main
stage: deploy
environment:
name: production
when: manual
variables:
AGENT: ${PROD_AGENT}
NS: ${PROD_NS}
Fallback:
extends:
- .deploy-main
stage: deploy
environment:
name: fallback
when: manual
variables:
AGENT: ${FALLBACK_AGENT}
NS: ${FALLBACK_NS}