-
Notifications
You must be signed in to change notification settings - Fork 51
/
config.yml
469 lines (443 loc) · 15.2 KB
/
config.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
version: 2.1
orbs:
docker: circleci/docker@1.6.0
jobs:
build:
machine:
# https://discuss.circleci.com/t/linux-machine-executor-images-2021-april-q2-update/39928
# upgrade Docker version
image: ubuntu-2004:202104-01
working_directory: /tmp/src/niworkflows
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
SCRATCH: "/scratch"
steps:
- restore_cache:
keys:
- build-v1-{{ .Branch }}-{{ .Revision }}
- build-v1--{{ .Revision }}
- build-v1-{{ .Branch }}-
- build-v1-master-
- build-v1-
paths:
- /tmp/docker
- /tmp/images
- run:
name: Docker authentication
command: |
if [[ -n $DOCKER_PAT ]]; then
echo "$DOCKER_PAT" | docker login -u $DOCKER_USER --password-stdin
fi
- run:
name: Set up Docker registry
command: |
if [[ -f /tmp/images/registry.tar.gz ]]; then
echo "Loading saved registry image"
docker load < /tmp/images/registry.tar.gz
else
echo "Pulling registry image from DockerHub"
docker pull registry:2
mkdir -p /tmp/images
docker save registry:2 | gzip > /tmp/images/registry.tar.gz
fi
docker run -d -p 5000:5000 --restart=always --name=registry \
-v /tmp/docker:/var/lib/registry registry:2
- run:
name: Pull existing images
command: |
set +e
docker pull localhost:5000/ubuntu
success=$?
set -e
if [[ "$success" = "0" ]]; then
echo "Pulling from local registry"
docker tag localhost:5000/ubuntu ubuntu:focal-20210416
docker pull localhost:5000/niworkflows
docker tag localhost:5000/niworkflows niworkflows:latest
else
echo "Pulling from Docker Hub"
docker pull ubuntu:focal-20210416
docker tag ubuntu:focal-20210416 localhost:5000/ubuntu
docker push localhost:5000/ubuntu
fi
- checkout
- run:
name: Build Docker image & push to registry
no_output_timeout: 60m
command: |
e=1 && for i in {1..5}; do
docker build --rm --cache-from=niworkflows:latest \
-t niworkflows:latest \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg VERSION=`python3 get_version.py` . \
&& e=0 && break || sleep 15
done && [ "$e" -eq "0" ]
docker tag niworkflows:latest localhost:5000/niworkflows
docker push localhost:5000/niworkflows
- run:
name: Docker registry garbage collection
command: |
docker exec -it registry /bin/registry garbage-collect --delete-untagged \
/etc/docker/registry/config.yml
- save_cache:
key: build-v1-{{ .Branch }}-{{ .Revision }}
paths:
- /tmp/docker
- /tmp/images
get_data:
docker:
- image: continuumio/miniconda3:4.9.2-alpine
working_directory: /tmp/data
environment:
- TEMPLATEFLOW_HOME: /tmp/templateflow
steps:
- restore_cache:
keys:
- env-v2-{{ .Branch }}-
- env-v2-master-
- env-v2-
- run:
name: Setup git-annex, DataLad & TemplateFlow
command: |
apk update && apk add --no-cache coreutils
conda install -y -c conda-forge datalad git wget
python -m pip install --no-cache-dir -U datalad-osf templateflow
git config --global user.name 'NiPreps Bot'
git config --global user.email 'nipreps@gmail.com'
- save_cache:
key: env-v2-{{ .Branch }}-{{ .BuildNum }}
paths:
- /opt/conda
- restore_cache:
keys:
- data-v3-{{ .Branch }}-{{ epoch }}
- data-v3-{{ .Branch }}-
- data-v3-master-
- data-v3-
- run:
name: Get test data from ds000003
command: |
if [[ ! -d ds000003 ]]; then
datalad install -r https://github.com/nipreps-data/ds000003.git
fi
datalad update -r --merge -d ds000003/
datalad get -J 2 -r -d ds000003/ ds000003/*
- run:
name: Get test data from ds000030
command: |
if [[ ! -d ds000030 ]]; then
datalad install -r https://github.com/nipreps-data/ds000030.git
fi
datalad update -r --merge -d ds000030/
datalad get -J 2 -r -d ds000030/ ds000030/sub-10228/func/*
- run:
name: Get BIDS test data stub
command: |
mkdir -p /tmp/data
if [[ ! -d /tmp/data/BIDS-examples-1-enh-ds054 ]]; then
wget --retry-connrefused --waitretry=5 --read-timeout=20 --timeout=15 -t 0 -q \
-O BIDS-examples-1-enh-ds054.zip "http://github.com/chrisfilo/BIDS-examples-1/archive/enh/ds054.zip"
unzip BIDS-examples-1-enh-ds054.zip -d /tmp/data/
else
echo "BIDS stub was cached"
fi
- save_cache:
key: data-v3-{{ .Branch }}-{{ epoch }}
paths:
- /tmp/data/ds000003
- /tmp/data/ds000030
- /tmp/data/BIDS-examples-1-enh-ds054
- run:
name: Store FreeSurfer license file
command: |
mkdir -p /tmp/fslicense
cd /tmp/fslicense
echo "cHJpbnRmICJrcnp5c3p0b2YuZ29yZ29sZXdza2lAZ21haWwuY29tXG41MTcyXG4gKkN2dW12RVYzelRmZ1xuRlM1Si8yYzFhZ2c0RVxuIiA+IGxpY2Vuc2UudHh0Cg==" | base64 -d | sh
- checkout:
path: /tmp/src/niworkflows
- persist_to_workspace:
root: /tmp
paths:
- fslicense
- src/
test_pytest:
machine:
image: ubuntu-2004:202104-01
working_directory: /tmp/tests
steps:
- attach_workspace:
at: /tmp
- run:
name: Get codecov
command: python -m pip install codecov
- restore_cache:
keys:
- build-v1-{{ .Branch }}-{{ .Revision }}
- build-v1--{{ .Revision }}
- build-v1-{{ .Branch }}-
- build-v1-master-
- build-v1-
- run:
name: Docker authentication
command: |
if [[ -n $DOCKER_PAT ]]; then
echo "$DOCKER_PAT" | docker login -u $DOCKER_USER --password-stdin
fi
- run:
name: Set up Docker registry
command: |
if [[ -f /tmp/images/registry.tar.gz ]]; then
echo "Loading saved registry image"
docker load < /tmp/images/registry.tar.gz
else
echo "Pulling registry image from DockerHub"
docker pull registry:2
fi
docker run -d -p 5000:5000 --restart=always --name=registry \
-v /tmp/docker:/var/lib/registry registry:2
- run:
name: Pull images from registry
command: |
docker pull localhost:5000/niworkflows
docker tag localhost:5000/niworkflows niworkflows:latest
- restore_cache:
keys:
- data-v3-{{ .Branch }}-{{ epoch }}
- data-v3-{{ .Branch }}-
- data-v3-master-
- data-v3-
- run:
name: Run unit tests
no_output_timeout: 2h
command: |
mkdir -p $PWD/artifacts $PWD/summaries
docker run -u $( id -u ):$( id -g ) -it --rm -w /src/niworkflows \
-e COVERAGE_FILE=/tmp/summaries/.pytest.coverage \
-e SAVE_CIRCLE_ARTIFACTS="/tmp/artifacts/" \
-e TEST_DATA_HOME=/data -v /tmp/data:/data \
-e FS_LICENSE=/etc/fslicense.txt \
-v /tmp/fslicense/license.txt:/etc/fslicense.txt:ro \
-v ${PWD}:/tmp niworkflows:latest \
pytest --junit-xml=/tmp/summaries/pytest.xml \
--cov niworkflows --cov-report xml:/tmp/summaries/unittests.xml \
--ignore=niworkflows/tests/ \
--ignore=niworkflows/func/tests/ \
niworkflows/
- run:
name: Submit unit test coverage
command: |
cd /tmp/src/niworkflows
python -m codecov --file /tmp/tests/summaries/unittests.xml \
--flags unittests -e CIRCLE_JOB
- run:
name: Run reportlet tests
no_output_timeout: 2h
command: |
docker run -u $( id -u ):$( id -g ) -it --rm -w /src/niworkflows \
-e COVERAGE_FILE=/tmp/summaries/.reportlets.coverage \
-e SAVE_CIRCLE_ARTIFACTS="/tmp/artifacts/" \
-e TEST_DATA_HOME=/data -v /tmp/data:/data \
-v /tmp/fslicense/license.txt:/opt/freesurfer/license.txt:ro \
-v ${PWD}:/tmp niworkflows:latest \
pytest -n auto --junit-xml=/tmp/summaries/reportlets.xml \
--cov niworkflows --cov-report xml:/tmp/summaries/reportlets.xml \
niworkflows/tests/
- run:
name: Submit reportlet test coverage
command: |
cd /tmp/src/niworkflows
python -m codecov --file /tmp/tests/summaries/reportlets.xml \
--flags reportlettests -e CIRCLE_JOB
- run:
name: Clean up tests directory
command: |
rm -rf /tmp/tests/pytest-of-root
- store_artifacts:
path: /tmp/tests/artifacts
- store_test_results:
path: /tmp/tests/summaries/
test_package:
docker:
- image: cimg/python:3.9
working_directory: /tmp/src/niworkflows
steps:
- checkout
- run:
name: Install build depends
command: python -m pip install "setuptools>=40.8.0" "pip>=19" "twine<2.0" docutils
- run:
name: Build and check
command: |
python setup.py sdist
python -m twine check dist/*
- run:
name: Validate version
command: |
THISVERSION=$( python get_version.py )
python -m pip install dist/*.tar.gz
mkdir empty
cd empty
INSTALLED=$( python -c 'import niworkflows; print(niworkflows.__version__)' )
test "${CIRCLE_TAG:-$THISVERSION}" == "$INSTALLED"
deploy_pypi:
docker:
- image: cimg/python:3.9
working_directory: /tmp/src/niworkflows
steps:
- checkout
- run:
name: Install build depends
command: python -m pip install "setuptools>=40.8.0" "pip>=19" "twine<2.0" docutils
- run:
name: Build and check
command: |
python setup.py check -r -s
python setup.py sdist
python -m twine check dist/*
- run:
name: Validate version
command: |
THISVERSION=$( python3 get_version.py )
python -m pip install dist/*.tar.gz
mkdir empty
cd empty
INSTALLED=$( python -c 'import niworkflows; print(niworkflows.__version__)' )
test "${CIRCLE_TAG:-$THISVERSION}" == "$INSTALLED"
- run:
name: Upload to PyPi
command: |
python -m twine upload dist/*
deploy_docker:
machine:
image: ubuntu-2004:202104-01
working_directory: /tmp/src/
steps:
- restore_cache:
keys:
- build-v1-{{ .Branch }}-{{ .Revision }}
- build-v1--{{ .Revision }}
- build-v1-{{ .Branch }}-
- build-v1-master-
- build-v1-
paths:
- /tmp/docker
- /tmp/images
- run:
name: Docker authentication
command: |
if [[ -n $DOCKER_PAT ]]; then
echo "$DOCKER_PAT" | docker login -u $DOCKER_USER --password-stdin
fi
- run:
name: Set up Docker registry
command: |
if [[ -f /tmp/images/registry.tar.gz ]]; then
echo "Loading saved registry image"
docker load < /tmp/images/registry.tar.gz
else
echo "Pulling registry image from DockerHub"
docker pull registry:2
fi
docker run -d -p 5000:5000 --restart=always --name=registry \
-v /tmp/docker:/var/lib/registry registry:2
- run:
name: Pull images from local registry
command: |
docker pull localhost:5000/niworkflows
docker tag localhost:5000/niworkflows nipreps/niworkflows:latest
- run:
name: Deploy to Docker Hub
no_output_timeout: 40m
command: |
docker push nipreps/niworkflows:latest
docker tag nipreps/niworkflows nipreps/niworkflows:$CIRCLE_TAG
docker push nipreps/niworkflows:$CIRCLE_TAG
build_docs:
docker:
- image: cimg/python:3.9
environment:
- FSLOUTPUTTYPE: NIFTI
- SUBJECTS_DIR: /tmp/subjects
steps:
- checkout
- run:
name: Create subjects folder
command: mkdir -p $SUBJECTS_DIR
- run:
name: Install Graphviz
command: sudo apt update && sudo apt -y install graphviz
- run:
name: Install deps
command: |
python -m pip install --no-cache-dir -U "pip>=20.3"
python -m pip install --no-cache-dir -r docs/requirements.txt
eval "$(pyenv init -)"
- run:
name: Install Niworkflows
command: |
python -m pip install .
- run:
name: Build only this commit
command: |
BRANCH=$( echo $CIRCLE_BRANCH | sed 's+/+_+g' )
make -C docs SPHINXOPTS="-W" BUILDDIR="$HOME/docs" OUTDIR=${CIRCLE_TAG:-$BRANCH} html
- store_artifacts:
path: ~/docs
workflows:
version: 2
build_test_deploy:
jobs:
- build:
filters:
tags:
only: /.*/
- get_data:
filters:
tags:
only: /.*/
- test_package:
filters:
branches:
ignore:
- /masks?\/.*/
tags:
only: /.*/
- test_pytest:
requires:
- build
- get_data
filters:
branches:
ignore:
- /docs?\/.*/
- /masks?\/.*/
tags:
only: /.*/
- deploy_pypi:
requires:
- test_pytest
- test_package
- build_docs
filters:
branches:
ignore: /.*/
tags:
only: /.*/
- deploy_docker:
requires:
- deploy_pypi
filters:
branches:
ignore: /.*/
tags:
only: /.*/
- build_docs:
filters:
branches:
ignore:
- /tests?\/.*/
- /ds005\/.*/
- /ds054\/.*/
tags:
only: /.*/