Skip to content

Commit 80482da

Browse files
authored
Merge pull request #471 from nipreps/ci/docker-registry-caching
MAINT: Use docker-registry for caching on CircleCI
2 parents d6f6d39 + 2640482 commit 80482da

File tree

2 files changed

+68
-72
lines changed

2 files changed

+68
-72
lines changed

.circleci/config.yml

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -31,66 +31,69 @@ docs_deploy: &docs
3131
version: 2
3232
jobs:
3333
build:
34+
machine:
35+
image: circleci/classic:201711-01
36+
working_directory: /tmp/src/niworkflows
3437
environment:
3538
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
3639
SCRATCH: "/scratch"
37-
docker:
38-
- image: docker:18.01.0-ce-git
39-
working_directory: /tmp/src/niworkflows
4040
steps:
41-
- run:
42-
name: Install parallel gzip and python3
43-
command: |
44-
apk add --no-cache pigz python3
4541
- restore_cache:
4642
keys:
47-
- docker-v1-{{ .Branch }}-{{ epoch }}
48-
- docker-v1-{{ .Branch }}-
49-
- docker-v1-master-
50-
- docker-v1-
43+
- build-v1-{{ .Branch }}-{{ epoch }}
44+
- build-v1-{{ .Branch }}-
45+
- build-v1-master-
46+
- build-v1-
5147
paths:
52-
- /tmp/cache/docker.tar.gz
53-
- checkout
54-
- setup_remote_docker
48+
- /tmp/docker
49+
50+
- run:
51+
name: Set-up a Docker registry
52+
command: |
53+
docker run -d -p 5000:5000 --restart=always --name=registry \
54+
-v /tmp/docker:/var/lib/registry registry:2
5555
- run:
56-
name: Load Docker image layer cache
57-
no_output_timeout: 30m
56+
name: Pull existing images
5857
command: |
59-
docker info
60-
set +o pipefail
61-
if [ -f /tmp/cache/docker.tar.gz ]; then
62-
pigz -d --stdout /tmp/cache/docker.tar.gz | docker load
63-
docker images
58+
set +e
59+
docker pull localhost:5000/ubuntu
60+
success=$?
61+
set -e
62+
if [[ "$success" = "0" ]]; then
63+
echo "Pulling from local registry"
64+
docker tag localhost:5000/ubuntu ubuntu:xenial-20191010
65+
docker pull localhost:5000/niworkflows
66+
docker tag localhost:5000/niworkflows niworkflows:latest
67+
else
68+
echo "Pulling from Docker Hub"
69+
docker pull ubuntu:xenial-20191010
70+
docker tag ubuntu:xenial-20191010 localhost:5000/ubuntu
71+
docker push localhost:5000/ubuntu
6472
fi
73+
74+
- checkout
6575
- run:
66-
name: Build Docker image
76+
name: Build Docker image & push to registry
6777
no_output_timeout: 60m
6878
command: |
6979
e=1 && for i in {1..5}; do
70-
docker build \
71-
--cache-from=niworkflows:py3 \
72-
--rm=false \
73-
-t niworkflows:py3 \
80+
docker build --rm \
81+
-t niworkflows:latest \
7482
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
7583
--build-arg VCS_REF=`git rev-parse --short HEAD` . \
7684
&& e=0 && break || sleep 15
7785
done && [ "$e" -eq "0" ]
86+
docker tag niworkflows:latest localhost:5000/niworkflows
87+
docker push localhost:5000/niworkflows
7888
- run:
79-
name: Docker save
80-
no_output_timeout: 40m
89+
name: Docker registry garbage collection
8190
command: |
82-
mkdir -p /tmp/cache
83-
docker save ubuntu:xenial-20161213 niworkflows:py3 \
84-
| pigz -8 -p 3 > /tmp/cache/docker.tar.gz
91+
docker exec -it registry /bin/registry garbage-collect --delete-untagged \
92+
/etc/docker/registry/config.yml
8593
- save_cache:
86-
key: docker-v1-{{ .Branch }}-{{ epoch }}
94+
key: build-v1-{{ .Branch }}-{{ epoch }}
8795
paths:
88-
- /tmp/cache/docker.tar.gz
89-
90-
# - persist_to_workspace:
91-
# root: /tmp
92-
# paths:
93-
# - cache/docker.tar.gz
96+
- /tmp/docker
9497

9598
get_data:
9699
machine:
@@ -185,24 +188,20 @@ jobs:
185188
at: /tmp
186189
- restore_cache:
187190
keys:
188-
- docker-v1-{{ .Branch }}-{{ epoch }}
189-
- docker-v1-{{ .Branch }}-
190-
- docker-v1-master-
191-
- docker-v1-
191+
- build-v1-{{ .Branch }}-{{ epoch }}
192+
- build-v1-{{ .Branch }}-
193+
- build-v1-master-
194+
- build-v1-
195+
- run:
196+
name: Set-up a Docker registry & pull
197+
command: |
198+
docker run -d -p 5000:5000 --restart=always --name=registry \
199+
-v /tmp/docker:/var/lib/registry registry:2
200+
docker pull localhost:5000/niworkflows
201+
docker tag localhost:5000/niworkflows niworkflows:latest
192202
193203
- checkout:
194204
path: /tmp/src/niworkflows
195-
- run:
196-
name: Load Docker image layer cache
197-
no_output_timeout: 30m
198-
command: |
199-
docker info
200-
set +o pipefail
201-
if [ -f /tmp/cache/docker.tar.gz ]; then
202-
sudo apt update && sudo apt -y install pigz
203-
pigz -d --stdout /tmp/cache/docker.tar.gz | docker load
204-
docker images
205-
fi
206205
- run:
207206
name: Set PR number
208207
command: |
@@ -222,7 +221,7 @@ jobs:
222221
docker run -u $( id -u ) -it --rm=false -w /src/niworkflows \
223222
-e COVERAGE_FILE=/tmp/summaries/.pytest.coverage \
224223
-e TEST_DATA_HOME=/data -v /tmp/data:/data \
225-
-v ${PWD}:/tmp niworkflows:py3 \
224+
-v ${PWD}:/tmp niworkflows:latest \
226225
pytest --junit-xml=/tmp/summaries/pytest.xml \
227226
--cov niworkflows --cov-report xml:/tmp/summaries/unittests.xml \
228227
--ignore=niworkflows/tests/ \
@@ -245,7 +244,7 @@ jobs:
245244
-e SAVE_CIRCLE_ARTIFACTS="/tmp/artifacts/" \
246245
-e TEST_DATA_HOME=/data -v /tmp/data:/data \
247246
-v /tmp/fslicense/license.txt:/opt/freesurfer/license.txt:ro \
248-
-v ${PWD}:/tmp niworkflows:py3 \
247+
-v ${PWD}:/tmp niworkflows:latest \
249248
pytest -n auto --junit-xml=/tmp/summaries/reportlets.xml \
250249
--cov niworkflows --cov-report xml:/tmp/summaries/reportlets.xml \
251250
niworkflows/tests/
@@ -275,27 +274,24 @@ jobs:
275274
at: /tmp
276275
- restore_cache:
277276
keys:
278-
- docker-v1-{{ .Branch }}-{{ epoch }}
279-
- docker-v1-{{ .Branch }}-
280-
- docker-v1-master-
281-
- docker-v1-
277+
- build-v1-{{ .Branch }}-{{ epoch }}
278+
- build-v1-{{ .Branch }}-
279+
- build-v1-master-
280+
- build-v1-
281+
- run:
282+
name: Set-up a Docker registry & pull
283+
command: |
284+
docker run -d -p 5000:5000 --restart=always --name=registry \
285+
-v /tmp/docker:/var/lib/registry registry:2
286+
docker pull localhost:5000/niworkflows
287+
docker tag localhost:5000/niworkflows niworkflows:latest
288+
282289
- restore_cache:
283290
keys:
284291
- regression-v2-{{ .Revision }}
285292

286293
- checkout:
287294
path: /tmp/src/niworkflows
288-
- run:
289-
name: Load Docker image layer cache
290-
no_output_timeout: 30m
291-
command: |
292-
docker info
293-
set +o pipefail
294-
if [ -f /tmp/cache/docker.tar.gz ]; then
295-
sudo apt update && sudo apt -y install pigz
296-
pigz -d --stdout /tmp/cache/docker.tar.gz | docker load
297-
docker images
298-
fi
299295
- run:
300296
name: Set PR number
301297
command: |
@@ -317,7 +313,7 @@ jobs:
317313
-e FMRIPREP_REGRESSION_SOURCE=/tmp/data/fmriprep_bold_truncated \
318314
-e FMRIPREP_REGRESSION_TARGETS=/tmp/data/fmriprep_bold_mask \
319315
-e FMRIPREP_REGRESSION_REPORTS=/tmp/masks/reports \
320-
niworkflows:py3 \
316+
niworkflows:latest \
321317
pytest --junit-xml=/tmp/masks/regression.xml \
322318
--cov niworkflows --cov-report xml:/tmp/masks/coverage.xml \
323319
niworkflows/func/tests/

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use Ubuntu 16.04 LTS
2-
FROM ubuntu:xenial-20161213
2+
FROM ubuntu:xenial-20191010
33

44
# Pre-cache neurodebian key
55
COPY docker/files/neurodebian.gpg /usr/local/etc/.neurodebian.gpg

0 commit comments

Comments
 (0)