1
+ # reusable anchors
2
+ _machine_defaults : &machine_defaults
3
+ environment :
4
+ TZ : " /usr/share/zoneinfo/America/Los_Angeles"
5
+ SCRATCH : " /scratch"
6
+ machine :
7
+ image : ubuntu-2204:current
8
+ docker_layer_caching : true
9
+ working_directory : /tmp/src/sdcflows
10
+ resource_class : large
11
+
12
+ _python_defaults : &python_defaults
13
+ docker :
14
+ - image : cimg/python:3.10.9
15
+ working_directory : /tmp/src/sdcflows
16
+
17
+ _docker_auth : &docker_auth
18
+ name : Docker authentication
19
+ command : |
20
+ if [[ -n $DOCKER_PAT ]]; then
21
+ echo "$DOCKER_PAT" | docker login -u $DOCKER_USER --password-stdin
22
+ fi
23
+
24
+ _setup_docker_registry : &setup_docker_registry
25
+ name : Set up Docker registry
26
+ command : |
27
+ if [[ -f /tmp/images/registry.tar.gz ]]; then
28
+ echo "Loading saved registry image"
29
+ docker load < /tmp/images/registry.tar.gz
30
+ else
31
+ echo "Pulling registry image from DockerHub"
32
+ docker pull registry:2
33
+ fi
34
+ docker run -d -p 5000:5000 --restart=always --name=registry \
35
+ -v /tmp/docker:/var/lib/registry registry:2
36
+
37
+ _pull_from_registry : &pull_from_registry
38
+ name : Pull and tag image from local registry
39
+ command : |
40
+ docker pull localhost:5000/sdcflows
41
+ docker tag localhost:5000/sdcflows nipreps/sdcflows:latest
42
+
1
43
version : 2.1
2
44
orbs :
3
- docker : circleci/docker@1.6.0
45
+ docker : circleci/docker@2.1.4
4
46
5
47
jobs :
6
48
cache_test_data :
@@ -126,11 +168,8 @@ jobs:
126
168
- /tmp/freesurfer
127
169
128
170
build_n_pytest :
129
- machine :
130
- image : ubuntu-2004:202107-02
171
+ << : *machine_defaults
131
172
working_directory : /tmp/tests
132
- environment :
133
- TZ : " /usr/share/zoneinfo/America/Los_Angeles"
134
173
steps :
135
174
- restore_cache :
136
175
keys :
@@ -140,45 +179,53 @@ jobs:
140
179
- build-v2-
141
180
paths :
142
181
- /tmp/docker
182
+ - docker/install-docker-credential-helper
183
+ - run : *docker_auth
184
+ - run : *setup_docker_registry
143
185
- run :
144
- name : Set-up a Docker registry
186
+ name : Pull Ubuntu/jammy image
145
187
command : |
146
- docker run -d -p 5000:5000 --restart=always --name=registry \
147
- -v /tmp/docker:/var/lib/registry registry:2
188
+ set +e
189
+ docker pull localhost:5000/ubuntu
190
+ success=$?
191
+ set -e
192
+ if [[ "$success" = "0" ]]; then
193
+ echo "Pulling from local registry"
194
+ docker tag localhost:5000/ubuntu ubuntu:jammy
195
+ else
196
+ echo "Pulling from Docker Hub"
197
+ docker pull ubuntu:jammy
198
+ docker tag ubuntu:jammy localhost:5000/ubuntu
199
+ docker push localhost:5000/ubuntu
200
+ fi
148
201
- run :
149
- name : Pull images
202
+ name : Pull SDCFlows Docker image
150
203
command : |
151
204
set +e
152
- docker pull localhost:5000/ubuntu
205
+ docker pull localhost:5000/sdcflows
153
206
success=$?
154
207
set -e
155
208
if [[ "$success" = "0" ]]; then
156
209
echo "Pulling from local registry"
157
- docker tag localhost:5000/ubuntu ubuntu:xenial-20201030
158
- docker pull localhost:5000/sdcflows
159
210
docker tag localhost:5000/sdcflows nipreps/sdcflows:latest
160
211
docker tag localhost:5000/sdcflows nipreps/sdcflows
161
212
else
162
213
echo "Pulling from Docker Hub"
163
- docker pull ubuntu:xenial-20201030
164
- docker tag ubuntu:xenial-20201030 localhost:5000/ubuntu
165
- docker push localhost:5000/ubuntu
166
214
docker pull nipreps/sdcflows:latest
167
215
fi
168
216
- checkout :
169
217
path : /tmp/src/sdcflows
170
218
- run :
171
219
name : Build Docker image
220
+ working_directory : /tmp/src/sdcflows
172
221
no_output_timeout : 60m
173
222
command : |
174
- cd /tmp/src/sdcflows
175
- export PY3=$(pyenv versions | grep '3\.' |
176
- sed -e 's/.* 3\./3./' -e 's/ .*//')
223
+ export PY3=$( pyenv versions | awk '/^\* 3/ { print $2 }' )
177
224
pyenv local $PY3
178
- python3 -m pip install " setuptools ~= 45.0" " setuptools_scm >= 6.2" " pip>=10.0.1"
225
+ python3 -m pip install --upgrade setuptools setuptools_scm pip
179
226
180
227
# Get version, update files.
181
- THISVERSION=$( python3 setup.py --version )
228
+ THISVERSION=$( python3 -m setuptools_scm )
182
229
if [[ ${THISVERSION:0:1} == "0" ]] ; then
183
230
echo "WARNING: latest git tag could not be found"
184
231
echo "Please, make sure you fetch all tags from upstream with"
@@ -194,6 +241,20 @@ jobs:
194
241
--build-arg VERSION="${CIRCLE_TAG:-$THISVERSION}" . \
195
242
| tee build-output.log
196
243
echo "${CIRCLE_TAG:-$THISVERSION}" >> /tmp/.local-version.txt
244
+ - run :
245
+ name : Check Docker image
246
+ working_directory : /tmp/src/sdcflows
247
+ command : |
248
+ export PY3=$( pyenv versions | awk '/^\* 3/ { print $2 }' )
249
+ pyenv local $PY3
250
+ # Get version, update files.
251
+ THISVERSION=$( python3 -m setuptools_scm )
252
+ BUILT_VERSION=$( docker run --rm --entrypoint=python nipreps/sdcflows:latest -c "import sdcflows; print(sdcflows.__version__)" )
253
+ BUILT_VERSION=${BUILT_VERSION%$'\r'}
254
+ echo "VERSION: \"$THISVERSION\""
255
+ echo "BUILT: \"$BUILT_VERSION\""
256
+ set -e
257
+ test "$BUILT_VERSION" = "$THISVERSION"
197
258
- run :
198
259
name : Docker push to local registry
199
260
no_output_timeout : 40m
@@ -209,16 +270,6 @@ jobs:
209
270
key : build-v2-{{ .Branch }}-{{ epoch }}
210
271
paths :
211
272
- /tmp/docker
212
- - run :
213
- name : Check version packaged in Docker image
214
- command : |
215
- docker run --rm -v /tmp:/tmp -v /tmp/src/sdcflows/.circleci/version.py:/usr/share/version.py \
216
- --entrypoint=python nipreps/sdcflows /usr/share/version.py
217
- THISVERSION=$( head -n1 /tmp/.local-version.txt )
218
- INSTALLED_VERSION=$( head -n1 /tmp/.docker-version.txt )
219
- echo "VERSION: \"${THISVERSION}\""
220
- echo "INSTALLED: \"${INSTALLED_VERSION}\""
221
- test "${INSTALLED_VERSION}" = "${THISVERSION}"
222
273
223
274
- restore_cache :
224
275
keys :
@@ -239,8 +290,8 @@ jobs:
239
290
- workdir-v2-
240
291
- run :
241
292
name : Refreshing cached intermediate results
293
+ working_directory : /tmp/src/sdcflows
242
294
command : |
243
- cd /tmp/src/sdcflows
244
295
COMMIT_MSG=$( git log --format=oneline -n 1 $CIRCLE_SHA1 )
245
296
set +e
246
297
do_refresh="$( echo "${COMMIT_MSG}" | grep -i -E '\[refresh[ _]?cache\]' )"
@@ -295,12 +346,11 @@ jobs:
295
346
296
347
- run :
297
348
name : Submit unit test coverage
349
+ working_directory : /tmp/src/sdcflows
298
350
command : |
299
- export PY3=$(pyenv versions | grep '3\.' |
300
- sed -e 's/.* 3\./3./' -e 's/ .*//')
351
+ export PY3=$( pyenv versions | awk '/^\* 3/ { print $2 }' )
301
352
pyenv local $PY3
302
353
python3 -m pip install codecov
303
- cd /tmp/src/sdcflows
304
354
python3 -m codecov --file /tmp/tests/unittests.xml \
305
355
--flags unittests -e CIRCLE_JOB
306
356
@@ -326,8 +376,7 @@ jobs:
326
376
command : |
327
377
python -m venv /tmp/venv
328
378
source /tmp/venv/bin/activate
329
- python -m pip install -U build "setuptools >= 45" wheel "setuptools_scm >= 6.2" \
330
- setuptools_scm_git_archive pip twine docutils
379
+ python -m pip install -U pip setuptools_scm
331
380
pip install --no-cache-dir -r docs/requirements.txt
332
381
- run :
333
382
name : Build only this commit
@@ -340,9 +389,7 @@ jobs:
340
389
path : ~/docs/
341
390
342
391
deploy_docker :
343
- machine :
344
- image : ubuntu-2004:202107-02
345
- working_directory : /tmp/src/
392
+ << : *machine_defaults
346
393
steps :
347
394
- restore_cache :
348
395
keys :
@@ -352,40 +399,30 @@ jobs:
352
399
- build-v2-
353
400
paths :
354
401
- /tmp/docker
355
- - run :
356
- name : Set-up a Docker registry
357
- command : |
358
- docker run -d -p 5000:5000 --restart=always --name=registry \
359
- -v /tmp/docker:/var/lib/registry registry:2
360
- - run :
361
- name : Pull images from local registry
362
- command : |
363
- docker pull localhost:5000/sdcflows
364
- docker tag localhost:5000/sdcflows nipreps/sdcflows:latest
402
+ - docker/install-docker-credential-helper
403
+ - run : *docker_auth
404
+ - run : *setup_docker_registry
405
+ - run : *pull_from_registry
365
406
- run :
366
407
name : Deploy to Docker Hub
367
408
no_output_timeout : 40m
368
409
command : |
369
410
if [[ -n "$DOCKER_PAT" ]]; then
370
- docker login -u $DOCKER_USER -p $DOCKER_PAT
371
411
docker push nipreps/sdcflows:latest
372
412
docker tag nipreps/sdcflows nipreps/sdcflows:$CIRCLE_TAG
373
413
docker push nipreps/sdcflows:$CIRCLE_TAG
374
414
fi
375
415
376
416
test_package :
377
- docker :
378
- - image : cimg/python:3.8.5
379
- working_directory : /tmp/src/sdcflows
417
+ << : *python_defaults
380
418
steps :
381
419
- checkout
382
420
- run :
383
421
name : Prepare environment & build
384
422
command : |
385
423
python -m venv /tmp/buildenv
386
424
source /tmp/buildenv/bin/activate
387
- python -m pip install -U build "setuptools >= 45" wheel "setuptools_scm >= 6.2" \
388
- setuptools_scm_git_archive pip twine docutils
425
+ python -m pip install -U build twine setuptools_scm
389
426
python -m build -s -w
390
427
python -m twine check dist/*
391
428
- store_artifacts :
@@ -399,24 +436,20 @@ jobs:
399
436
command : |
400
437
source /tmp/buildenv/bin/activate
401
438
THISVERSION=$( python -m setuptools_scm )
402
- python -m pip install dist/*.tar.gz
439
+ python -m pip install dist/*.whl
403
440
mkdir empty
404
441
cd empty
405
442
INSTALLED=$( python -c 'import sdcflows; print(sdcflows.__version__)' )
406
443
test "${CIRCLE_TAG:-$THISVERSION}" == "$INSTALLED"
407
444
408
445
deploy_pypi :
409
- docker :
410
- - image : cimg/python:3.8.5
411
- working_directory : /tmp/src/sdcflows
446
+ << : *python_defaults
412
447
steps :
413
448
- attach_workspace :
414
449
at : /tmp/src/sdcflows
415
450
- run :
416
451
name : Upload to Pypi
417
452
command : |
418
- python -m venv /tmp/upload
419
- source /tmp/upload/bin/activate
420
453
python -m pip install twine
421
454
python -m twine check dist/*
422
455
python -m twine upload dist/* --non-interactive
0 commit comments