-
Notifications
You must be signed in to change notification settings - Fork 11
/
.gitlab-ci.yml
251 lines (220 loc) · 7.79 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
stages:
- test
- docker-build
- deploy
# Use the acc-py-devtools templates found at
# https://gitlab.cern.ch/-/ide/project/acc-co/devops/python/acc-py-devtools/blob/master/-/acc_py_devtools/templates/gitlab-ci/python.yml.
include:
- project: acc-co/devops/python/acc-py-devtools
file: acc_py_devtools/templates/gitlab-ci/python.yml
variables:
PY_VERSION: "3.11"
# ###################################################################################################
# Test code - CAiMIRA (model) and CERN CAiMIRA (CERN's UI)
.test-base:
image: registry.cern.ch/docker.io/library/python:${PY_VERSION}
stage: test
rules:
# do not run tests on live/caimira-test branch or tags
- if: $CI_COMMIT_BRANCH != "live/caimira-test"
- if: $CI_COMMIT_TAG
when: never
.test-run:
extends:
- .test-base
script:
- cd ./${PROJECT_ROOT}
- pip install -e .[test]
- python -m pytest
test-caimira-py311:
variables:
PROJECT_ROOT: "caimira"
extends:
- .test-run
test-cern-caimira-py311:
before_script:
- cd ./caimira
- pip install -e .[test]
- cd ../
variables:
PROJECT_ROOT: "cern_caimira"
extends:
- .test-run
test-caimira-py39:
variables:
PY_VERSION: "3.9"
PROJECT_ROOT: "caimira"
extends:
- test-caimira-py311
test-cern-caimira-py39:
variables:
PY_VERSION: "3.9"
PROJECT_ROOT: "cern_caimira"
extends:
- test-cern-caimira-py311
# ###################################################################################################
# Test OpenShift config
.test_openshift_config:
stage: test
allow_failure: true
image: registry.cern.ch/docker.io/mambaorg/micromamba
before_script:
- micromamba create --yes -p $HOME/env python=3.9 ruamel.yaml wget -c conda-forge
- export PATH=$HOME/env/bin/:$PATH
- wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
- tar xzf ./openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
- mv openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/oc $HOME/env/bin/
script:
- cd ./app-config/openshift
- oc login ${OC_SERVER} --token="${OC_TOKEN}"
- python ./config-fetch.py ${CAIMIRA_INSTANCE} --output-directory ./${CAIMIRA_INSTANCE}/actual
- python ./config-generate.py ${CAIMIRA_INSTANCE} --output-directory ./${CAIMIRA_INSTANCE}/expected
- python ./config-normalise.py ./${CAIMIRA_INSTANCE}/actual ./${CAIMIRA_INSTANCE}/actual-normed
- python ./config-normalise.py ./${CAIMIRA_INSTANCE}/expected ./${CAIMIRA_INSTANCE}/expected-normed
- diff -u ./${CAIMIRA_INSTANCE}/actual-normed/ ./${CAIMIRA_INSTANCE}/expected-normed/
artifacts:
paths:
- ./app-config/openshift/${CAIMIRA_INSTANCE}/actual
- ./app-config/openshift/${CAIMIRA_INSTANCE}/expected
check_openshift_config_test:
extends: .test_openshift_config
variables:
CAIMIRA_INSTANCE: 'caimira-test'
OC_SERVER: https://api.paas.okd.cern.ch
OC_TOKEN: "${OPENSHIFT_CAIMIRA_TEST_CONFIG_CHECKER_TOKEN}"
rules:
- if: $CI_COMMIT_BRANCH == "live/caimira-test"
check_openshift_config_prod:
extends: .test_openshift_config
variables:
CAIMIRA_INSTANCE: 'caimira-prod'
OC_SERVER: https://api.paas.okd.cern.ch
OC_TOKEN: "${OPENSHIFT_CAIMIRA_PROD_CONFIG_CHECKER_TOKEN}"
rules:
- if: $CI_COMMIT_BRANCH == "master"
# ###################################################################################################
# Build docker images
# base
.docker-build:
stage: docker-build
image:
# Based on guidance at https://gitlab.cern.ch/gitlabci-examples/build_docker_image.
# The kaniko debug image is recommended because it has a shell, and a shell is required for an image to be used with GitLab CI/CD.
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "Building image for ${CI_COMMIT_REF_NAME} branch with tag ${IMAGE_TAG} and latest"
# Prepare Kaniko configuration file
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
# Build and push the image from the Dockerfile
- /kaniko/executor --context ${CI_PROJECT_DIR}/${DOCKER_CONTEXT_DIRECTORY} --dockerfile ${CI_PROJECT_DIR}/${DOCKERFILE_DIRECTORY}/Dockerfile --destination ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG} --destination ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:latest
# Print the full registry path of the pushed image
- echo "Image pushed successfully to ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}"
.docker-build-auth-service:
variables:
IMAGE_NAME: auth-service
DOCKERFILE_DIRECTORY: app-config/auth-service
DOCKER_CONTEXT_DIRECTORY: app-config/auth-service
extends: .docker-build
.docker-build-calculator-app:
variables:
IMAGE_NAME: calculator-app
DOCKERFILE_DIRECTORY: app-config/calculator-app
DOCKER_CONTEXT_DIRECTORY: ""
extends: .docker-build
.docker-build-docs:
variables:
IMAGE_NAME: caimira-docs
DOCKERFILE_DIRECTORY: "caimira/docs"
DOCKER_CONTEXT_DIRECTORY: "caimira"
extends: .docker-build
# on push to live/caimira-test
.docker-build-test:
variables:
IMAGE_TAG: caimira-test-latest
docker-build-auth-service-test:
extends:
- .docker-build-test
- .docker-build-auth-service
rules:
- if: $CI_COMMIT_BRANCH == "live/caimira-test"
docker-build-calculator-app-test:
extends:
- .docker-build-test
- .docker-build-calculator-app
rules:
- if: $CI_COMMIT_BRANCH == "live/caimira-test"
docker-build-docs-test:
extends:
- .docker-build-docs
variables:
IMAGE_TAG: caimira-test-docs-latest
rules:
- if: $CI_COMMIT_BRANCH == "live/caimira-test"
# on release
.docker-build-release:
before_script:
# Extract version number without 'v' prefix as IMAGE_TAG
- IMAGE_TAG=$(echo "$CI_COMMIT_REF_NAME" | sed 's/^v//')
- echo "Version is $IMAGE_TAG"
docker-build-auth-service-release:
extends:
- .docker-build-release
- .docker-build-auth-service
rules:
- if: $CI_COMMIT_TAG
docker-build-calculator-app-release:
extends:
- .docker-build-release
- .docker-build-calculator-app
rules:
- if: $CI_COMMIT_TAG
docker-build-docs-release:
extends:
- .docker-build-release
- .docker-build-docs
variables:
IMAGE_TAG: caimira-docs-latest
rules:
- if: $CI_COMMIT_TAG
# ###################################################################################################
# Deploy to OpenShift
.deploy:
stage: deploy
image: gitlab-registry.cern.ch/paas-tools/openshift-client
variables:
IMAGE_TAG: caimira-test-latest
OPENSHIFT_SERVER: https://api.paas.okd.cern.ch
OPENSHIFT_PROJECT: caimira-test
script:
- echo "Deploying ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG} to OpenShift"
- oc login $OPENSHIFT_SERVER --token=$OPENSHIFT_CAIMIRA_TEST_DEPLOY_TOKEN
- oc project $OPENSHIFT_PROJECT
- oc set image deployment/$OPENSHIFT_DEPLOYMENT $OPENSHIFT_CONTAINER_NAME=${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}
- oc rollout status deployment/$OPENSHIFT_DEPLOYMENT
rules:
- if: $CI_COMMIT_BRANCH == "live/caimira-test"
deploy-auth-service-test:
extends: .deploy
variables:
IMAGE_NAME: auth-service
OPENSHIFT_DEPLOYMENT: auth-service
OPENSHIFT_CONTAINER_NAME: auth-service
deploy-calculator-app-test:
extends: .deploy
variables:
IMAGE_NAME: calculator-app
OPENSHIFT_DEPLOYMENT: calculator-app
OPENSHIFT_CONTAINER_NAME: calculator-app
deploy-calculator-open-app-test:
extends: .deploy
variables:
IMAGE_NAME: calculator-app
OPENSHIFT_DEPLOYMENT: calculator-open-app
OPENSHIFT_CONTAINER_NAME: calculator-open-app
deploy-docs-test:
extends: .deploy
variables:
IMAGE_NAME: caimira-docs
OPENSHIFT_DEPLOYMENT: caimira-test-docs
OPENSHIFT_CONTAINER_NAME: caimira-test-docs