Skip to content

Commit a292adb

Browse files
committed
fix: clean up environment cache
1 parent 7cef99c commit a292adb

File tree

3 files changed

+221
-131
lines changed

3 files changed

+221
-131
lines changed

.circleci/config.yml

+8-20
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
- checkout
1313
- restore_cache:
1414
keys:
15-
- env-v3-{{ .Branch }}-
16-
- env-v3-master-
17-
- env-v3-
15+
- env-v5-{{ .Branch }}-
16+
- env-v5-master-
17+
- env-v5-
1818
- run:
1919
name: Setup git-annex
2020
command: |
@@ -29,17 +29,14 @@ jobs:
2929
- run:
3030
name: Setup DataLad
3131
command: |
32-
export PY3=$(pyenv versions | grep '3\.' |
33-
sed -e 's/.* 3\./3./' -e 's/ .*//')
34-
pyenv local $PY3
35-
python -m pip install --no-cache-dir -U pip "setuptools >= 45.0" "setuptools_scm[toml] >= 3.4"
36-
python -m pip install --no-cache-dir -U datalad datalad-osf
32+
python3 -m pip install --no-cache-dir -U pip "setuptools >= 45.0" "setuptools_scm[toml] >= 3.4"
33+
python3 -m pip install --no-cache-dir -U datalad datalad-osf
3734
3835
- save_cache:
39-
key: env-v3-{{ .Branch }}-{{ .BuildNum }}
36+
key: env-v5-{{ .Branch }}-{{ .BuildNum }}
4037
paths:
4138
- /opt/circleci/git-annex.linux
42-
- /opt/circleci/.pyenv/versions/3.9.4
39+
- /opt/circleci/.pyenv/versions/3.12.2
4340

4441
- restore_cache:
4542
keys:
@@ -49,10 +46,7 @@ jobs:
4946
- run:
5047
name: Install test data from GIN
5148
command: |
52-
export PY3=$(pyenv versions | grep '3\.' |
53-
sed -e 's/.* 3\./3./' -e 's/ .*//')
54-
pyenv local $PY3
55-
export PATH=/opt/circleci/git-annex.linux:$PATH
49+
export PATH=/opt/circleci/.pyenv/versions/3.12.2/bin/:/opt/circleci/git-annex.linux:$PATH
5650
mkdir -p /tmp/data
5751
cd /tmp/data
5852
datalad install -r https://gin.g-node.org/oesteban/nitransforms-tests
@@ -98,9 +92,6 @@ jobs:
9892
name: Build Docker image & push to registry
9993
no_output_timeout: 60m
10094
command: |
101-
export PY3=$(pyenv versions | grep '3\.' |
102-
sed -e 's/.* 3\./3./' -e 's/ .*//')
103-
pyenv local $PY3
10495
e=1 && for i in {1..5}; do
10596
docker build --rm --cache-from=nitransforms:latest \
10697
-t nitransforms:latest \
@@ -123,9 +114,6 @@ jobs:
123114
- run:
124115
name: Check version packaged in Docker image
125116
command: |
126-
export PY3=$(pyenv versions | grep '3\.' |
127-
sed -e 's/.* 3\./3./' -e 's/ .*//')
128-
pyenv local $PY3
129117
THISVERSION=${CIRCLE_TAG:-$(python3 setup.py --version)}
130118
INSTALLED_VERSION=$(\
131119
docker run -it --rm --entrypoint=python nitransforms \

Dockerfile

+171-111
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,144 @@
1-
FROM ubuntu:xenial-20200114
2-
3-
# Pre-cache neurodebian key
4-
COPY docker/files/neurodebian.gpg /usr/local/etc/neurodebian.gpg
5-
6-
# Prepare environment
1+
# Ubuntu 22.04 LTS - Jammy
2+
ARG BASE_IMAGE=ubuntu:jammy-20240125
3+
4+
#
5+
# Build wheel
6+
#
7+
FROM python:slim AS src
8+
RUN pip install build
9+
RUN apt-get update && \
10+
apt-get install -y --no-install-recommends git
11+
COPY . /src
12+
RUN python -m build /src
13+
14+
#
15+
# Download stages
16+
#
17+
18+
# Utilities for downloading packages
19+
FROM ${BASE_IMAGE} as downloader
20+
# Bump the date to current to refresh curl/certificates/etc
21+
RUN echo "2023.07.20"
722
RUN apt-get update && \
823
apt-get install -y --no-install-recommends \
9-
curl \
24+
binutils \
1025
bzip2 \
1126
ca-certificates \
12-
xvfb \
13-
build-essential \
14-
autoconf \
15-
libtool \
16-
pkg-config \
17-
git && \
18-
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
27+
curl \
28+
unzip && \
29+
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
30+
31+
# FreeSurfer 7.3.2
32+
FROM downloader as freesurfer
33+
COPY docker/files/freesurfer7.3.2-exclude.txt /usr/local/etc/freesurfer7.3.2-exclude.txt
34+
RUN curl -sSL https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/7.3.2/freesurfer-linux-ubuntu22_amd64-7.3.2.tar.gz \
35+
| tar zxv --no-same-owner -C /opt --exclude-from=/usr/local/etc/freesurfer7.3.2-exclude.txt
36+
37+
# AFNI
38+
FROM downloader as afni
39+
# Bump the date to current to update AFNI
40+
RUN echo "2023.07.20"
41+
RUN mkdir -p /opt/afni-latest \
42+
&& curl -fsSL --retry 5 https://afni.nimh.nih.gov/pub/dist/tgz/linux_openmp_64.tgz \
43+
| tar -xz -C /opt/afni-latest --strip-components 1 \
44+
--exclude "linux_openmp_64/*.gz" \
45+
--exclude "linux_openmp_64/funstuff" \
46+
--exclude "linux_openmp_64/shiny" \
47+
--exclude "linux_openmp_64/afnipy" \
48+
--exclude "linux_openmp_64/lib/RetroTS" \
49+
--exclude "linux_openmp_64/lib_RetroTS" \
50+
--exclude "linux_openmp_64/meica.libs" \
51+
# Keep only what we use
52+
&& find /opt/afni-latest -type f -not \( \
53+
-name "3dTshift" -or \
54+
-name "3dUnifize" -or \
55+
-name "3dAutomask" -or \
56+
-name "3dvolreg" \) -delete
57+
58+
# Micromamba
59+
FROM downloader as micromamba
60+
61+
# Install a C compiler to build extensions when needed.
62+
# traits<6.4 wheels are not available for Python 3.11+, but build easily.
63+
RUN apt-get update && \
64+
apt-get install -y --no-install-recommends build-essential && \
65+
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
66+
67+
WORKDIR /
68+
# Bump the date to current to force update micromamba
69+
RUN echo "2024.02.06"
70+
RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
71+
72+
ENV MAMBA_ROOT_PREFIX="/opt/conda"
73+
COPY env.yml /tmp/env.yml
74+
# COPY requirements.txt /tmp/requirements.txt
75+
WORKDIR /tmp
76+
RUN micromamba create -y -f /tmp/env.yml && \
77+
micromamba clean -y -a
78+
79+
#
80+
# Main stage
81+
#
82+
FROM ${BASE_IMAGE} as fmriprep
83+
84+
# Configure apt
85+
ENV DEBIAN_FRONTEND="noninteractive" \
86+
LANG="en_US.UTF-8" \
87+
LC_ALL="en_US.UTF-8"
88+
89+
# Some baseline tools; bc is needed for FreeSurfer, so don't drop it
90+
RUN apt-get update && \
1991
apt-get install -y --no-install-recommends \
20-
nodejs && \
92+
bc \
93+
ca-certificates \
94+
curl \
95+
git \
96+
gnupg \
97+
lsb-release \
98+
netbase \
99+
xvfb && \
21100
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
22101

23-
# Installing freesurfer
24-
RUN curl -sSL https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/6.0.1/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.1.tar.gz | tar zxv --no-same-owner -C /opt \
25-
--exclude='freesurfer/diffusion' \
26-
--exclude='freesurfer/docs' \
27-
--exclude='freesurfer/fsfast' \
28-
--exclude='freesurfer/lib/cuda' \
29-
--exclude='freesurfer/lib/qt' \
30-
--exclude='freesurfer/matlab' \
31-
--exclude='freesurfer/mni/share/man' \
32-
--exclude='freesurfer/subjects/fsaverage_sym' \
33-
--exclude='freesurfer/subjects/fsaverage3' \
34-
--exclude='freesurfer/subjects/fsaverage4' \
35-
--exclude='freesurfer/subjects/cvs_avg35' \
36-
--exclude='freesurfer/subjects/cvs_avg35_inMNI152' \
37-
--exclude='freesurfer/subjects/bert' \
38-
--exclude='freesurfer/subjects/lh.EC_average' \
39-
--exclude='freesurfer/subjects/rh.EC_average' \
40-
--exclude='freesurfer/subjects/sample-*.mgz' \
41-
--exclude='freesurfer/subjects/V1_average' \
42-
--exclude='freesurfer/trctrain'
43-
44-
ENV FSL_DIR="/usr/share/fsl/5.0" \
45-
OS="Linux" \
102+
# Configure PPAs for libpng12 and libxp6
103+
RUN GNUPGHOME=/tmp gpg --keyserver hkps://keyserver.ubuntu.com --no-default-keyring --keyring /usr/share/keyrings/linuxuprising.gpg --recv 0xEA8CACC073C3DB2A \
104+
&& GNUPGHOME=/tmp gpg --keyserver hkps://keyserver.ubuntu.com --no-default-keyring --keyring /usr/share/keyrings/zeehio.gpg --recv 0xA1301338A3A48C4A \
105+
&& echo "deb [signed-by=/usr/share/keyrings/linuxuprising.gpg] https://ppa.launchpadcontent.net/linuxuprising/libpng12/ubuntu jammy main" > /etc/apt/sources.list.d/linuxuprising.list \
106+
&& echo "deb [signed-by=/usr/share/keyrings/zeehio.gpg] https://ppa.launchpadcontent.net/zeehio/libxp/ubuntu jammy main" > /etc/apt/sources.list.d/zeehio.list
107+
108+
# Dependencies for AFNI; requires a discontinued multiarch-support package from bionic (18.04)
109+
RUN apt-get update -qq \
110+
&& apt-get install -y -q --no-install-recommends \
111+
ed \
112+
gsl-bin \
113+
libglib2.0-0 \
114+
libglu1-mesa-dev \
115+
libglw1-mesa \
116+
libgomp1 \
117+
libjpeg62 \
118+
libpng12-0 \
119+
libxm4 \
120+
libxp6 \
121+
netpbm \
122+
tcsh \
123+
xfonts-base \
124+
xvfb \
125+
&& curl -sSL --retry 5 -o /tmp/multiarch.deb http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/multiarch-support_2.27-3ubuntu1.5_amd64.deb \
126+
&& dpkg -i /tmp/multiarch.deb \
127+
&& rm /tmp/multiarch.deb \
128+
&& apt-get install -f \
129+
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
130+
&& gsl2_path="$(find / -name 'libgsl.so.19' || printf '')" \
131+
&& if [ -n "$gsl2_path" ]; then \
132+
ln -sfv "$gsl2_path" "$(dirname $gsl2_path)/libgsl.so.0"; \
133+
fi \
134+
&& ldconfig
135+
136+
# Install files from stages
137+
COPY --from=freesurfer /opt/freesurfer /opt/freesurfer
138+
COPY --from=afni /opt/afni-latest /opt/afni-latest
139+
140+
# Simulate SetUpFreeSurfer.sh
141+
ENV OS="Linux" \
46142
FS_OVERRIDE=0 \
47143
FIX_VERTEX_AREA="" \
48144
FSF_OUTPUT_FORMAT="nii.gz" \
@@ -56,95 +152,59 @@ ENV SUBJECTS_DIR="$FREESURFER_HOME/subjects" \
56152
MNI_DATAPATH="$FREESURFER_HOME/mni/data"
57153
ENV PERL5LIB="$MINC_LIB_DIR/perl5/5.8.5" \
58154
MNI_PERL5LIB="$MINC_LIB_DIR/perl5/5.8.5" \
59-
PATH="$FREESURFER_HOME/bin:$FSFAST_HOME/bin:$FREESURFER_HOME/tktools:$MINC_BIN_DIR:$PATH"
155+
PATH="$FREESURFER_HOME/bin:$FREESURFER_HOME/tktools:$MINC_BIN_DIR:$PATH"
60156

61-
# Installing Neurodebian packages (FSL, AFNI, git)
62-
RUN curl -sSL "http://neuro.debian.net/lists/$( lsb_release -c | cut -f2 ).us-ca.full" >> /etc/apt/sources.list.d/neurodebian.sources.list && \
63-
apt-key add /usr/local/etc/neurodebian.gpg && \
64-
(apt-key adv --refresh-keys --keyserver hkp://ha.pool.sks-keyservers.net 0xA5D32F012649A5A9 || true)
157+
# AFNI config
158+
ENV PATH="/opt/afni-latest:$PATH" \
159+
AFNI_IMSAVE_WARNINGS="NO" \
160+
AFNI_PLUGINPATH="/opt/afni-latest"
65161

66-
RUN apt-get update && \
67-
apt-get install -y --no-install-recommends \
68-
fsl-core=5.0.9-5~nd16.04+1 \
69-
fsl-mni152-templates=5.0.7-2 \
70-
afni=16.2.07~dfsg.1-5~nd16.04+1 \
71-
convert3d \
72-
connectome-workbench=1.3.2-2~nd16.04+1 \
73-
git-annex-standalone && \
74-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
162+
# Workbench config
163+
ENV PATH="/opt/workbench/bin_linux64:$PATH"
164+
165+
# Create a shared $HOME directory
166+
RUN useradd -m -s /bin/bash -G users neuro
167+
WORKDIR /home/neuro
168+
ENV HOME="/home/neuro" \
169+
LD_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
170+
171+
COPY --from=micromamba /bin/micromamba /bin/micromamba
172+
COPY --from=micromamba /opt/conda/envs/fmriprep /opt/conda/envs/fmriprep
75173

76-
ENV FSLDIR="/usr/share/fsl/5.0" \
174+
ENV MAMBA_ROOT_PREFIX="/opt/conda"
175+
RUN micromamba shell init -s bash && \
176+
echo "micromamba activate fmriprep" >> $HOME/.bashrc
177+
ENV PATH="/opt/conda/envs/fmriprep/bin:$PATH" \
178+
CPATH="/opt/conda/envs/fmriprep/include:$CPATH" \
179+
LD_LIBRARY_PATH="/opt/conda/envs/fmriprep/lib:$LD_LIBRARY_PATH"
180+
181+
# FSL environment
182+
ENV LANG="C.UTF-8" \
183+
LC_ALL="C.UTF-8" \
184+
PYTHONNOUSERSITE=1 \
185+
FSLDIR="/opt/conda/envs/fmriprep" \
77186
FSLOUTPUTTYPE="NIFTI_GZ" \
78187
FSLMULTIFILEQUIT="TRUE" \
79-
POSSUMDIR="/usr/share/fsl/5.0" \
80-
LD_LIBRARY_PATH="/usr/lib/fsl/5.0:$LD_LIBRARY_PATH" \
81-
FSLTCLSH="/usr/bin/tclsh" \
82-
FSLWISH="/usr/bin/wish" \
83-
AFNI_MODELPATH="/usr/lib/afni/models" \
84-
AFNI_IMSAVE_WARNINGS="NO" \
85-
AFNI_TTATLAS_DATASET="/usr/share/afni/atlases" \
86-
AFNI_PLUGINPATH="/usr/lib/afni/plugins"
87-
ENV PATH="/usr/lib/fsl/5.0:/usr/lib/afni/bin:$PATH"
88-
89-
# Installing ANTs 2.3.3 (NeuroDocker build)
90-
# Note: the URL says 2.3.4 but it is actually 2.3.3
91-
ENV ANTSPATH=/usr/lib/ants
92-
RUN mkdir -p $ANTSPATH && \
93-
curl -sSL "https://dl.dropbox.com/s/gwf51ykkk5bifyj/ants-Linux-centos6_x86_64-v2.3.4.tar.gz" \
94-
| tar -xzC $ANTSPATH --strip-components 1
95-
ENV PATH=$ANTSPATH:$PATH
96-
97-
# Installing and setting up miniconda
98-
RUN curl -sSLO https://repo.continuum.io/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh && \
99-
bash Miniconda3-4.5.11-Linux-x86_64.sh -b -p /usr/local/miniconda && \
100-
rm Miniconda3-4.5.11-Linux-x86_64.sh
101-
102-
# Set CPATH for packages relying on compiled libs (e.g. indexed_gzip)
103-
ENV PATH="/usr/local/miniconda/bin:$PATH" \
104-
CPATH="/usr/local/miniconda/include/:$CPATH" \
105-
LANG="C.UTF-8" \
106-
LC_ALL="C.UTF-8" \
107-
PYTHONNOUSERSITE=1
108-
109-
# Installing precomputed python packages
110-
RUN conda install -y -c anaconda -c conda-forge \
111-
python=3.8 \
112-
libxml2=2.9 \
113-
libxslt=1.1 \
114-
lxml \
115-
mkl \
116-
mkl-service \
117-
numpy=1.20 \
118-
pip=21 \
119-
scipy=1.6 \
120-
setuptools \
121-
setuptools_scm \
122-
toml \
123-
zlib; sync && \
124-
chmod -R a+rX /usr/local/miniconda; sync && \
125-
chmod +x /usr/local/miniconda/bin/*; sync && \
126-
conda build purge-all; sync && \
127-
conda clean -tipsy && sync
188+
FSLLOCKDIR="" \
189+
FSLMACHINELIST="" \
190+
FSLREMOTECALL="" \
191+
FSLGECUDAQ="cuda.q"
128192

129193
# Unless otherwise specified each process should only use one thread - nipype
130194
# will handle parallelization
131195
ENV MKL_NUM_THREADS=1 \
132196
OMP_NUM_THREADS=1
133197

134-
# Create a shared $HOME directory
135-
RUN useradd -m -s /bin/bash -G users neuro
136-
WORKDIR /home/neuro
137-
ENV HOME="/home/neuro"
138-
139198
# Install package
140199
# CRITICAL: Make sure python setup.py --version has been run at least once
141200
# outside the container, with access to the git history.
142-
COPY . /src/nitransforms
143-
RUN pip install --no-cache-dir "/src/nitransforms[all]"
201+
COPY --from=src /src/dist/*.whl .
202+
RUN python -m pip install --no-cache-dir $( ls /src/dist/*.whl )[all]
144203

145-
RUN find $HOME -type d -exec chmod go=u {} + && \
146-
find $HOME -type f -exec chmod go=u {} +
147204

205+
RUN find $HOME -type d -exec chmod go=u {} + && \
206+
find $HOME -type f -exec chmod go=u {} + && \
207+
rm -rf $HOME/.npm $HOME/.conda $HOME/.empty
148208

149209
RUN ldconfig
150210
WORKDIR /tmp/

0 commit comments

Comments
 (0)