-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
executable file
·169 lines (150 loc) · 3.99 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
#
# 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}
stages:
- test
- build
- deploy
.deploy-rules:
rules:
- if: '$CI_DEPLOY_FREEZE == null && $CI_COMMIT_BRANCH == "main"'
when: always
.deploy-branch-rules:
rules:
- if: '$CI_DEPLOY_FREEZE == null && ($CI_COMMIT_BRANCH != "main" || $CI_COMMIT_BRANCH != "dev")'
when: always
.deploy:
stage: 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
- kustomize edit set image DOCKER_IMAGE=${DOCKER_IMAGE}
- kubectl apply -k ./
rules:
- if: '$CI_DEPLOY_FREEZE == null && $CI_COMMIT_BRANCH == "main"'
when: manual
# Run Tests
Test:
stage: test
image: python:3.10
before_script:
- pip install -r app/tests/requirements.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: report.xml
except:
- /^skiptest\/.*$/
# 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 specific review apps)
Review:
extends:
- .deploy
- .deploy-branch-rules
environment:
name: development
variables:
AGENT: ${DEV_AGENT}
NS: ${CI_COMMIT_REF_SLUG}
after_script:
- kubectl -n ${NS} set env deployment/ensembl-tools-api-deployment --from configmap/ensembl-tools-api-configmap
# Stop feature branch review app (cleanup resources)
Stop_review:
extends: .deploy-branch-rules
stage: deploy
image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:latest
environment:
name: development
variables:
GIT_STRATEGY: none
AGENT: ${DEV_AGENT}
NS: ${CI_COMMIT_REF_SLUG}
script:
- kubectl -n ${NS} delete service ensembl-tools-api-svc
- kubectl -n ${NS} delete deploy ensembl-tools-api-deployment
Production:
extends:
- .deploy
- .deploy-rules
environment:
name: production
variables:
AGENT: ${PROD_AGENT}
NS: ${PROD_NS}
Fallback:
extends:
- .deploy
- .deploy-rules
environment:
name: fallback
variables:
AGENT: ${FALLBACK_AGENT}
NS: ${FALLBACK_NS}
Staging:
extends:
- .deploy
- .deploy-rules
environment:
name: staging
rules:
- if: '$CI_DEPLOY_FREEZE == null && $CI_COMMIT_BRANCH == "dev"'
variables:
AGENT: ${STAGING_AGENT}
NS: ${STAGING_NS}
Internal:
extends:
- .deploy
- .deploy-rules
environment:
name: internal
variables:
AGENT: ${INTERNAL_AGENT}
NS: ${INTERNAL_NS}
Dev:
extends:
- .deploy
- .deploy-rules
environment:
name: development
variables:
AGENT: ${DEV_AGENT}
NS: ${DEV_NS}