-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
283 lines (248 loc) · 7.9 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
image: gitlab-registry.cern.ch/fts/fts-rest-flask:ci
stages:
- static_code_analysis
- build
- docker
- tests
- publish
variables:
MYSQL_DATABASE: ftsflask
MYSQL_ROOT_PASSWORD: ftsflaskroot
#---------------------------------
# Static Code Analysis
#---------------------------------
.pylint_template: &pylint_definition
# Check for Python syntax errors
stage: static_code_analysis
script:
- PY="PY${CI_JOB_NAME##pylint}"
- VENV="VENV_${CI_JOB_NAME##pylint}"
- source ~/.bashrc
- pyenv global ${!PY}
- source ${!VENV}/bin/activate
- pylint --version
- pylint --output-format colorized --disable C,R,W src/ --ignored-modules=sqlalchemy
variables:
PYTHONPATH: ./src:./src/fts3rest
black:
# Check that every file has been formatted with black
stage: static_code_analysis
script:
- black --version
- black --check --fast --diff --target-version py39 src/
# The latest "fts/fts-rest-flask:ci" image is based on Alma9 + Python3.9 - Python3.11
pylint39:
<<: *pylint_definition
pylint310:
<<: *pylint_definition
pylint311:
<<: *pylint_definition
radon:
# Check metrics for every file
stage: static_code_analysis
script:
- radon --version
- source .gitlab-ci/radon.sh
bandit:
# Find potential security issues in file.
# It's allowed to fail as it may detect false positives.
allow_failure: true
stage: static_code_analysis
script:
- bandit --version
- bandit --ini .gitlab-ci/bandit.ini
#--------------------------
# Build templates
#--------------------------
.server-build-template: &server-build-template_definition
stage: build
script:
- ./packaging/fedora-packages.sh
- ./packaging/server/fts-rest-server.sh
- mkdir ${CI_JOB_NAME}
- cp -rv build/server/RPMS build/server/SRPMS ${CI_JOB_NAME}
- tree ${CI_JOB_NAME}
variables:
BRANCH: ${CI_COMMIT_REF_NAME}
artifacts:
when: on_success
paths:
- "$CI_JOB_NAME"
.client-build-template: &client-build-template_definition
stage: build
script:
- ./packaging/fedora-packages.sh
- ./packaging/client/fts-rest-client.sh
- mkdir ${CI_JOB_NAME}
- cp -r build/client/RPMS build/client/SRPMS ${CI_JOB_NAME}
- tree ${CI_JOB_NAME}
variables:
BRANCH: ${CI_COMMIT_REF_NAME}
artifacts:
when: on_success
paths:
- "$CI_JOB_NAME"
#--------------------------
# Build jobs
#--------------------------
client_wheel_sdist:
image: gitlab-registry.cern.ch/linuxsupport/alma9-base
stage: build
script:
- dnf install -y python3 python3-wheel
- python3 setup.py bdist_wheel
- python3 setup.py sdist
artifacts:
when: on_success
paths:
- dist/
client_rpm:
image: gitlab-registry.cern.ch/linuxsupport/alma9-base
<<: *client-build-template_definition
server_rpm:
image: gitlab-registry.cern.ch/linuxsupport/alma9-base
<<: *server-build-template_definition
#--------------------------
# Docker build templates
#--------------------------
.kaniko_build: &kaniko_build-template
stage: docker
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- if [[ -z "$CI_COMMIT_TAG" ]]; then CACHE="true"; else CACHE="false"; fi
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --dockerfile .gitlab-ci/docker/Dockerfile-ci --context "${CI_PROJECT_DIR}" --cache=${CACHE} --destination ${DESTINATION} --build-arg dmcrepo=${DMC_REPO}
retry: 1
#--------------------------
# Docker build jobs
#--------------------------
docker_latest:
<<: *kaniko_build-template
variables:
DMC_REPO: https://dmc-repo.web.cern.ch/dmc-repo/dmc-devel-el9.repo
DESTINATION: gitlab-registry.cern.ch/fts/fts-rest-flask:latest
needs:
- job: server_rpm
rules:
- if: $CI_COMMIT_REF_NAME == "develop"
docker_tag:
<<: *kaniko_build-template
variables:
DMC_REPO: https://dmc-repo.web.cern.ch/dmc-repo/dmc-rc-el9.repo
DESTINATION: gitlab-registry.cern.ch/fts/fts-rest-flask:${CI_COMMIT_TAG}
needs:
- job: server_rpm
rules:
- if: $CI_COMMIT_TAG != null
#--------------------------
# Testing templates
#--------------------------
.functional_tests_template: &functional_tests_definition
stage: tests
services:
- name: mysql:8.0.32
alias: mysqldb
command: ["--default-authentication-plugin=mysql_native_password"]
script:
- sleep 20 # give some time for the mysql service to start
- PY="PY${CI_JOB_NAME##*_tests}"
- VENV="VENV_${CI_JOB_NAME##*_tests}"
- source ~/.bashrc
- pyenv global ${!PY}
- python --version
- source ${!VENV}/bin/activate
- ./.gitlab-ci/setup-db.sh
- sed -i "s/DbConnectString=localhost/DbConnectString=mysqldb/" $FTS3TESTCONFIG
- coverage run --branch --source src/fts3rest/fts3rest/ --omit 'src/fts3rest/fts3rest/tests/*' -m pytest src/ -x
- coverage report
needs: []
variables:
PYTHONPATH: ./src:./src/fts3rest
FTS3TESTCONFIG: ./src/fts3rest/fts3rest/tests/fts3testconfig
.rpm_tests_template: &rpm_tests_definition
stage: tests
services:
- name: mysql:8.0.32
alias: mysqldb
command: ["--default-authentication-plugin=mysql_native_password"]
script:
- sleep 20 # give some time for the mysql service to start
- dnf install -y mariadb python3-pytest epel-release
- dnf install -y epel-rpm-macros
- curl -s https://fts-repo.web.cern.ch/fts-repo/fts3-depend.repo -o /etc/yum.repos.d/fts3-depend.repo
- PLATFORM=${CI_JOB_NAME%-*}
- dnf localinstall --nogpgcheck -y ${PLATFORM}/RPMS/*/*.rpm
- ./.gitlab-ci/setup-db.sh
- sed -i "s/DbConnectString=localhost/DbConnectString=mysqldb/" $FTS3TESTCONFIG
- pytest-3 -x $FTS3TESTPATH
#--------------------------
# Testing jobs
#--------------------------
functional_tests39:
<<: *functional_tests_definition
functional_tests310:
<<: *functional_tests_definition
functional_tests311:
<<: *functional_tests_definition
server_rpm-test:
<<: *rpm_tests_definition
image: gitlab-registry.cern.ch/linuxsupport/alma9-base
dependencies:
- server_rpm
needs:
- server_rpm
variables:
FTS3TESTCONFIG: /usr/lib/python3.9/site-packages/fts3rest/tests/fts3testconfig
FTS3TESTPATH: /usr/lib/python3.9/site-packages/fts3rest/tests/functional/
#--------------------------
# Publish templates
#--------------------------
.publish-template: &publish-template_definition
stage: publish
image: gitlab-registry.cern.ch/eos/gitlab-eos/alma9:latest
dependencies:
- client_rpm
- server_rpm
script:
- automount
- cat "$repo_passwd" | kinit "$repo_user"
- |
for package in client_rpm server_rpm ; do
packaging/fts-repo-manager.py --action add --base /eos/workspace/f/fts/repo/www/repos/ --arch-dir x86_64 --ref ${CI_COMMIT_REF_NAME} --packages ${package}/RPMS/*/*.rpm ${package}/SRPMS/*
done
tags:
- docker-privileged-xl
retry: 2
#--------------------------
# Publish jobs
#--------------------------
rpms:
<<: *publish-template_definition
rules:
- if: '$CI_PROJECT_NAMESPACE != "fts"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- if: '$CI_COMMIT_REF_NAME == "develop" || $CI_COMMIT_TAG != null'
- if: '$CI_COMMIT_REF_NAME == "FTS-1925_token_project" || $CI_COMMIT_TAG != null'
- if: '$CI_COMMIT_REF_NAME != "develop" && $CI_COMMIT_TAG == null'
when: manual
pypi-publish:
needs:
- job: client_wheel_sdist
stage: publish
image: gitlab-registry.cern.ch/linuxsupport/alma9-base
script:
- dnf install -y git python3 python3-pip
- python3 -m pip install --upgrade pip
- python3 -m pip install setuptools twine
- echo -e "[pypi]\nusername = __token__\npassword = ${PYPI_API_KEY}" > ~/.pypirc
- twine check dist/*
- twine upload dist/* --verbose
rules:
- if: '$CI_COMMIT_TAG != null'
when: manual
- when: never