-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
354 lines (323 loc) · 8.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
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
284
285
286
287
288
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
include:
- project: computing/gitlab-ci-templates
file: debian.yml
- project: computing/gitlab-ci-templates
file: python.yml
- project: computing/gitlab-ci-templates
file: workflow/sccb.yml
- template: Security/Dependency-Scanning.gitlab-ci.yml
variables:
# Allow Celery to run as root, because everything runs as root under Docker.
C_FORCE_ROOT: 'true'
stages:
- build
- test
- deploy
# Build source distribution
build:
stage: build
extends: .python:build
# Install redis
.install-redis: &install-redis
apt-get install -y -qq redis-server
.test-common:
stage: test
extends:
- .debian:base
- .python:pytest
variables:
PYTEST_OPTIONS: "--cov-report=html"
artifacts:
paths:
- htmlcov/
# Run test suite using poetry environment and locked dependencies
.test-poetry:
extends: .test-common
before_script:
- !reference [".debian:base", before_script]
- !reference [".python:pytest", before_script]
- *install-redis
- curl -sSL https://install.python-poetry.org | python3 -
- export PATH="/root/.local/bin:$PATH"
- poetry config virtualenvs.create false
- poetry install -E test
needs: []
test/poetry/python3.8:
extends: .test-poetry
image: python:3.8
test/poetry/python3.9:
extends: .test-poetry
image: python:3.9
test/poetry/python3.10:
extends: .test-poetry
image: python:3.10
# Run test suite using wheel and bleeding-edge dependencies
.test-wheel:
extends: .test-common
variables:
PYTEST_OPTIONS: "--pyargs $CI_PROJECT_NAME"
before_script:
- INSTALL_TARGET=$(echo *.whl)[test]
- !reference [".debian:base", before_script]
- !reference [".python:pytest", before_script]
- *install-redis
needs:
- build
test/wheel/python3.8:
extends: .test-wheel
image: python:3.8
test/wheel/python3.9:
extends: .test-wheel
image: python:3.9
test/wheel/python3.10:
extends: .test-wheel
image: python:3.10
lint:
stage: test
extends: .python:flake8
needs: []
associate commits in Sentry:
stage: test
needs:
- build
only:
- main@emfollow/gwcelery
- tags@emfollow/gwcelery
image:
name: getsentry/sentry-cli
entrypoint: [""]
script:
- SENTRY_VERSION=$(echo *.tar.* | sed 's/\.tar\..*//')
- sentry-cli releases new ${SENTRY_VERSION}
- sentry-cli releases set-commits --auto ${SENTRY_VERSION}
# Generate documentation
doc:
stage: test
extends:
- .debian:base
- .python:sphinx
# FIXME: temporarily set image to Python 3.9 because default `python` image
# is now Python 3.10 which lacks wheels for many packages right now.
image: python:3.9
variables:
SOURCEDIR: doc
REQUIREMENTS: .[doc]
before_script:
- !reference [".debian:base", before_script]
- !reference [".python:sphinx", before_script]
- apt-get install -y -qq graphviz
needs: []
# SCCB request
sccb:
stage: deploy
before_script:
# poetry-dynamic-versioning needs to be installed to properly
# update the version information in pyproject.toml
- >
python -m pip install --upgrade pip;
curl -sSL https://install.python-poetry.org | python3 -;
python -m pip install --upgrade poetry-dynamic-versioning
needs: []
# Publish coverage
pages:
stage: deploy
script:
- mv htmlcov public/
artifacts:
paths:
- public
expire_in: 30 days
only:
- main
needs:
- test/poetry/python3.8
# Upload package to PyPI.
# Place your PyPI API token in the repository's GitLab CI secrets.
pypi:
stage: deploy
image: python:slim
script:
- pip install twine
- twine upload --username __token__ --password $PYPI_API_TOKEN *.tar.* *.whl
needs:
- build
only:
- tags@emfollow/gwcelery
# Create a release in GitLab
release:
stage: deploy
image: python
variables:
GIT_STRATEGY: fetch
script:
- python -m pip install --upgrade pip poetry poetry-dynamic-versioning
- PACKAGE_NAME="$(basename $PWD)"
- PACKAGE_VERSION="$(poetry version --short)"
- CHANGES_FILENAME="$(echo CHANGES.*)"
- |
tee json <<EOF
{
"name": "${PACKAGE_VERSION}",
"tag_name": "${CI_COMMIT_TAG}",
"description": "Version ${PACKAGE_VERSION}",
"assets": {
"links": [
{
"name": "PyPI",
"url": "https://pypi.org/project/${PACKAGE_NAME}/${PACKAGE_VERSION}/"
},
{
"name": "Change log",
"url": "${CI_PROJECT_URL}/blob/v${VERSION}/${CHANGES_FILENAME}"
},
{
"name": "Documentation",
"url": "https://${PACKAGE_NAME}.readthedocs.io/en/v${PACKAGE_VERSION}/"
}
]
}
}
EOF
- |
if [ -n "$CI_COMMIT_TAG" ]
then
curl --silent --show-error --fail \
--request POST --header "Private-Token: $GITLAB_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data "@json" \
"$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases"
fi
.deploy-common: &deploy-common
image: containers.ligo.org/emfollow/ssh-kerberos
stage: deploy
only:
- branches@emfollow/gwcelery
- tags@emfollow/gwcelery
needs: []
# Continuous deployment.
# Note that all deployments except playground/CIT are manual.
.deploy-start: &deploy-start
<<: *deploy-common
script:
# Update the repository.
- |
ssh -T $REMOTE_HOST bash <<EOF
set -e
if [ ! -d .git ]; then git init; fi
git fetch --tags ${CI_REPOSITORY_URL} $CI_COMMIT_SHA
git checkout -f $CI_COMMIT_SHA
EOF
# Reinstall and start (new session to reload bashrc).
- |
ssh -T $REMOTE_HOST bash <<EOF
. .bashrc
set -e
python -m pip install --upgrade pip
curl -sSL https://install.python-poetry.org | python3 -
# FIXME: It would be simpler to use `poetry install`, but it tries to
# uninstall system site-packages even if they are not writable.
pip install --no-deps -r <(poetry export --with dev)
pip install --no-deps .
# FIXME: remove pip uninstall temporary directories left behind due to
# bug with pip on NFS. See https://github.com/pypa/pip/issues/6327
chmod -R ug+rwx .local/lib/python*/site-packages/~* || true
rm -rf .local/lib/python*/site-packages/~* || true
gwcelery condor resubmit
EOF
.deploy-stop: &deploy-stop
<<: *deploy-common
script: |
ssh -T $REMOTE_HOST bash <<EOF
. .bashrc
set -e
gwcelery condor rm
EOF
deploy to production at CIT:
<<: *deploy-start
when: manual
environment:
name: production/CIT
on_stop: stop deployment on production at CIT
url: https://emfollow.ligo.caltech.edu/flower
variables:
REMOTE_HOST: [email protected]
deploy to production at LHO:
<<: *deploy-start
when: manual
environment:
name: production/LHO
on_stop: stop deployment on production at LHO
url: https://emfollow.ligo-wa.caltech.edu/flower
variables:
REMOTE_HOST: [email protected]
deploy to playground at CIT:
<<: *deploy-start
environment:
name: playground/CIT
on_stop: stop deployment on playground at CIT
url: https://emfollow-playground.ligo.caltech.edu/flower
variables:
REMOTE_HOST: [email protected]
deploy to playground at LHO:
<<: *deploy-start
when: manual
environment:
name: playground/LHO
on_stop: stop deployment on playground at LHO
url: https://emfollow-playground.ligo-wa.caltech.edu/flower
variables:
REMOTE_HOST: [email protected]
deploy to test at CIT:
<<: *deploy-start
when: manual
environment:
name: test/CIT
on_stop: stop deployment on test at CIT
url: https://emfollow-test.ligo.caltech.edu/flower
variables:
REMOTE_HOST: [email protected]
deploy to test at LHO:
<<: *deploy-start
when: manual
environment:
name: test/LHO
on_stop: stop deployment on test at LHO
url: https://emfollow-test.ligo-wa.caltech.edu/flower
variables:
REMOTE_HOST: [email protected]
stop deployment on production at CIT:
<<: *deploy-stop
when: manual
environment:
name: production/CIT
action: stop
stop deployment on production at LHO:
<<: *deploy-stop
when: manual
environment:
name: production/LHO
action: stop
stop deployment on playground at CIT:
<<: *deploy-stop
when: manual
environment:
name: playground/CIT
action: stop
stop deployment on playground at LHO:
<<: *deploy-stop
when: manual
environment:
name: playground/LHO
action: stop
stop deployment on test at CIT:
<<: *deploy-stop
when: manual
environment:
name: test/CIT
action: stop
stop deployment on test at LHO:
<<: *deploy-stop
when: manual
environment:
name: test/LHO
action: stop