Skip to content

Commit 7bc9a2f

Browse files
author
jakubk
committed
enh: migrate to circleci 2.0 + check base dockerfile against cache
The specification for CircleCI 2.0 is stored in `.circleci/config.yml` instead of in `circle.yml`. Todo: - Run tests. For now, images are built and pushed, but no tests are run. - Minimize containers with neurodocker reprozip. This functionality will be updated soon. See discussion in VIDA-NYU/reprozip#274.
1 parent 7b3c404 commit 7bc9a2f

File tree

3 files changed

+149
-86
lines changed

3 files changed

+149
-86
lines changed

.circleci/config.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Examples:
2+
# https://github.com/circleci/frontend/blob/master/.circleci/config.yml
3+
#
4+
# Questions
5+
# ---------
6+
# 1. Regarding the cache: what if the base Dockerfile is reverted to a previous
7+
# version? The cache for that Dockerfile will exist, so it will pull the
8+
# image, which is incorrect. Include a note in generate_dockerfiles.sh to
9+
# increase the version of the cache.
10+
11+
version: 2
12+
jobs:
13+
14+
compare_base_dockerfiles:
15+
docker:
16+
- image: docker:17.06.2-ce-git # shell is /bin/ash (bash not available)
17+
steps:
18+
- checkout:
19+
path: /home/circleci/nipype
20+
- run:
21+
name: Prune base Dockerfile in preparation for cache check
22+
command: |
23+
mkdir -p /tmp/docker
24+
25+
# Remove empty lines, comments, and the timestamp from the base
26+
# Dockerfile. Use the sha256 sum of this pruned Dockerfile as the
27+
# cache key.
28+
sed -e '/\s*#.*$/d' \
29+
-e '/^\s*$/d' \
30+
-e '/generation_timestamp/d' \
31+
/home/circleci/nipype/docker/Dockerfile.base \
32+
> /tmp/docker/Dockerfile.base-pruned
33+
- restore_cache:
34+
key: dftest-v4-master-{{ checksum "/tmp/docker/Dockerfile.base-pruned" }}
35+
- run:
36+
name: Determine how to get base image
37+
command: |
38+
GET_BASE="/tmp/docker/get_base_image.sh"
39+
40+
# This directory comes from the cache.
41+
if [ -d /cache/base-dockerfile ]; then
42+
echo 'echo Pulling base image ...' > "$GET_BASE"
43+
echo 'docker pull kaczmarj/nipype:base' >> "$GET_BASE"
44+
else
45+
echo 'echo Building base image ...' > "$GET_BASE"
46+
echo 'docker build -t kaczmarj/nipype:base - < /home/circleci/nipype/docker/Dockerfile.base' >> "$GET_BASE"
47+
fi
48+
- persist_to_workspace:
49+
root: /tmp
50+
paths:
51+
- docker/*
52+
53+
54+
build_and_test:
55+
parallelism: 1
56+
# Ideally, we could test inside the main docker image.
57+
machine:
58+
# Ubuntu 14.04 with Docker 17.03.0-ce
59+
image: circleci/classic:201703-01
60+
steps:
61+
- checkout:
62+
path: /home/circleci/nipype
63+
- attach_workspace:
64+
at: /tmp
65+
- run:
66+
name: Get base image (pull or build)
67+
no_output_timeout: 60m
68+
command: |
69+
bash /tmp/docker/get_base_image.sh
70+
- run:
71+
name: Build main image (latest & py36)
72+
no_output_timeout: 60m
73+
command: |
74+
cd /home/circleci/nipype
75+
76+
docker build --rm=false \
77+
--tag kaczmarj/nipype:latest \
78+
--tag kaczmarj/nipype:py36 \
79+
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
80+
--build-arg VCS_REF=`git rev-parse --short HEAD` \
81+
--build-arg VERSION=$CIRCLE_TAG .
82+
- run:
83+
name: Build main image (py27)
84+
no_output_timeout: 60m
85+
command: |
86+
cd /home/circleci/nipype
87+
88+
docker build --rm=false \
89+
--tag kaczmarj/nipype:py27 \
90+
--build-arg PYTHON_VERSION_MAJOR=2 \
91+
--build-arg PYTHON_VERSION_MINOR=7 \
92+
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
93+
--build-arg VCS_REF=`git rev-parse --short HEAD` \
94+
--build-arg VERSION=$CIRCLE_TAG-py27 /home/circleci/nipype
95+
- run:
96+
name: Run tests
97+
command: |
98+
echo "This is node $CIRCLE_NODE_INDEX"
99+
echo "No tests to run yet."
100+
- run:
101+
name: Save Docker images to workspace
102+
no_output_timeout: 60m
103+
command: |
104+
if [ "$CIRCLE_NODE_INDEX" -eq "0" ]; then
105+
echo "Saving Docker images to tar.gz files ..."
106+
docker save kaczmarj/nipype:latest kaczmarj/nipype:py36 | gzip > /tmp/docker/nipype-latest-py36.tar.gz
107+
fi
108+
- persist_to_workspace:
109+
root: /tmp
110+
paths:
111+
- docker/*
112+
113+
114+
deploy:
115+
docker:
116+
- image: docker:17.06.2-ce-git
117+
steps:
118+
- checkout
119+
- setup_remote_docker
120+
- attach_workspace:
121+
at: /tmp
122+
- run:
123+
name: Load saved Docker images.
124+
no_output_timeout: 60m
125+
command: |
126+
docker load < /tmp/docker/nipype-latest-py36.tar.gz
127+
- run:
128+
name: Push to DockerHub
129+
no_output_timeout: 60m
130+
command: |
131+
if [ "${CIRCLE_BRANCH}" == "enh/circleci-neurodocker" ]; then
132+
docker login -u $DOCKER_USER -p $DOCKER_PASS
133+
docker push kaczmarj/nipype:latest
134+
docker push kaczmarj/nipype:py36
135+
fi
136+
# TODO: write pruned Dockerfile to cache here. Make a shell script that will
137+
# prune Dockerfiles
138+
139+
workflows:
140+
version: 2
141+
build_test_deply:
142+
jobs:
143+
- compare_base_dockerfiles
144+
- build_and_test:
145+
requires:
146+
- compare_base_dockerfiles
147+
- deploy:
148+
requires:
149+
- build_and_test
File renamed without changes.

circle.yml

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)