From 65d724c991fd593bd14aecdaf3b3710d3e4a2ea6 Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Wed, 3 May 2023 08:48:49 -0400 Subject: [PATCH 1/5] Update Dockerfile uses Dockerfile created by @kaitj for diffparc-surf (minus the installation of diffparc-surf, and adding the CreateJacobianDeterminantImage ants binary. --- Dockerfile | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 57d077d..66d7946 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,164 @@ -FROM mrtrix3/mrtrix3:3.0.3 +# Stage: python +FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04 as python +ENV DEBIAN_FRONTEND="noninteractive" \ + PYENV_VER="v2.3.17" \ + PYTHON_VER="3.8.12" \ + PYENV_ROOT="/opt/.pyenv" \ + PATH="/opt/.pyenv/shims:/opt/.pyenv/bin:/usr/local/cuda/bin:${PATH}" \ + LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH} +RUN apt-get update -qq \ + && apt-get install -y -q --no-install-recommends \ + build-essential \ + curl \ + git \ + libbz2-dev \ + libffi-dev \ + liblzma-dev \ + libncurses5-dev \ + libncursesw5-dev \ + libreadline-dev \ + libsqlite3-dev \ + libssl-dev \ + llvm \ + python-openssl \ + tk-dev \ + wget \ + xz-utils \ + zlib1g-dev \ + software-properties-common \ + && git clone -b ${PYENV_VER} --depth=1 https://github.com/pyenv/pyenv.git /opt/.pyenv \ + && pyenv install -v ${PYTHON_VER} \ + && pyenv global ${PYTHON_VER} \ + && python -m pip install --upgrade pip -RUN apt-get -qq update \ - && apt-get install -yq --no-install-recommends \ - parallel \ - && rm -rf /var/lib/apt/lists/* +# Stage: builder +# Notes: g++ (snakebids), tcsh (freesurfer), libtiff5 (mrtrix3) +FROM python as builder +RUN mkdir -p /opt \ + && apt-get update -qq \ + && apt-get install -y -q --no-install-recommends \ + libeigen3-dev \ + zlib1g-dev \ + libqt5opengl5-dev \ + libqt5svg5-dev \ + libgl1-mesa-dev \ + libncurses5 \ + libxt6 \ + libtiff5 \ + parallel \ + rsync \ + tcsh \ + g++ \ + unzip \ + bc \ + # FSL dependencies + libexpat1-dev \ + liblapack-dev \ + libopenblas-dev \ + libx11-dev \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# Stage: ants +FROM builder as ants +ARG ANTS_VER=2.4.3 +RUN wget https://github.com/ANTsX/ANTs/releases/download/v${ANTS_VER}/ants-${ANTS_VER}-centos7-X64-gcc.zip -O ants.zip \ + && unzip -qq ants.zip -d /opt \ + && mv /opt/ants-${ANTS_VER} /opt/ants \ + && rm ants.zip +# Stage: fsl +FROM fnndsc/fsl:6.0.5.1-cuda9.1 as fsl +RUN mv /usr/local/fsl/bin /usr/local/fsl/bin-all \ + && mkdir -p /usr/local/fsl/bin \ + && cd /usr/local/fsl/bin-all \ + && cp -R bet* bedpost* topup applytopup eddy* fslorient probtrack* fslmerge remove_ext avscale /usr/local/fsl/bin \ + && cd /usr/local/fsl/bin \ + && rm -r eddy_cuda8.0 eddy_cuda10.2 /usr/local/fsl/bin-all + +# Stage: itksnap (built with Ubuntu16.04 - glibc 2.23) +FROM khanlab/itksnap:main as itksnap +RUN cp -R /opt/itksnap/ /opt/itksnap-mini/ \ + && cd /opt/itksnap-mini/bin \ + && rm c2d itksnap* + +# Stage: mrtrix (nogui) +FROM builder as mrtrix +ARG MRTRIX_VER=3.0.4 +ARG MRTRIX_CONFIG_FLAGS="-nogui" +ARG MRTRIX_BUILD_FLAGS="" +RUN git clone --depth 1 https://github.com/MRtrix3/mrtrix3.git /opt/mrtrix3 \ + && cd /opt/mrtrix3 \ + && git fetch --tags \ + && git checkout ${MRTRIX_VER} \ + && ./configure ${MRTRIX_CONFIG_FLAGS} \ + && ./build ${MRTRIX_BUILD_FLAGS} \ + && mkdir -p mrtrix3_runtime \ + && cp -R bin core lib src mrtrix3_runtime \ + && rm -r tmp + +# Stage: niftyreg +FROM builder as niftyreg +ARG NIFTYREG_VER=1.3.9 +RUN wget https://sourceforge.net/projects/niftyreg/files/nifty_reg-${NIFTYREG_VER}/NiftyReg-${NIFTYREG_VER}-Linux-x86_64-Release.tar.gz/download -O /opt/niftyreg.tar.gz \ + && tar -xf /opt/niftyreg.tar.gz -C /opt \ + && mv /opt/NiftyReg-${NIFTYREG_VER}-Linux-x86_64-Release /opt/niftyreg \ + && cd /opt/niftyreg/bin \ + && ls . | grep -xv "reg_aladin" | xargs rm \ + && rm /opt/niftyreg.tar.gz + +# Stage: synthstrip +FROM freesurfer/synthstrip:1.3 as synthstrip + +# Stage: synthseg +FROM builder as synthseg +RUN git clone https://github.com/BBillot/Synthseg.git /opt/SynthSeg \ + && curl https://www.dropbox.com/s/i62tzl821mqi3vd/synths_models_freesurfer_7.3.2.zip -Lo synthseg_models_freesurfer_7.3.2.zip \ + && unzip -qqo synthseg_models_freesurfer_7.3.2.zip -d /opt/SynthSeg/models \ + && rm synthseg_models_freesurfer_7.3.2.zip + +# Stage: workbench +FROM builder as workbench +ARG WB_VER=1.5.0 +RUN wget https://humanconnectome.org/storage/app/media/workbench/workbench-linux64-v${WB_VER}.zip -O workbench.zip \ + && unzip -qq workbench.zip -d /opt \ + && rm -r /opt/workbench/plugins_linux64 \ + && rm workbench.zip + +# Stage: runtime +FROM builder as runtime +WORKDIR / +COPY --from=diffparc /opt/diffparc-surf/dist/*.whl /opt/diffparc-surf/ +COPY --from=ants \ + # Commands to copy + /opt/ants/bin/antsApplyTransforms \ + /opt/ants/bin/antsRegistration \ + /opt/ants/bin/Atropos \ + /opt/ants/bin/N4BiasFieldCorrection \ + /opt/ants/bin/CreateJacobianDeterminantImage \ + # Target destination + /opt/ants/bin/ +COPY --from=itksnap /opt/itksnap-mini /opt/itksnap/ +COPY --from=mrtrix /opt/mrtrix3/mrtrix3_runtime /opt/mrtrix3/ +COPY --from=niftyreg /opt/niftyreg /opt/niftyreg/ +COPY --from=synthseg /opt/SynthSeg /opt/SynthSeg/ +COPY --from=synthstrip /freesurfer /opt/freesurfer/ +COPY --from=workbench /opt/workbench /opt/workbench/ +# FSL + cuda9.1 +COPY --from=fsl /usr/local/cuda /usr/local/cuda/ +COPY --from=fsl /usr/local/cuda-9.1 /usr/local/cuda-9.1/ +COPY --from=fsl /usr/local/fsl /usr/local/fsl/ +# Setup environments +ENV OS=Linux \ + ANTSPATH=/opt/ants/bin \ + FREESURFER_HOME=/opt/freesurfer \ + LD_LIBRARY_PATH=/opt/itksnap/lib:/opt/niftyreg/lib:/opt/workbench/libs_linux64:/opt/workbench/libs_linux64_software_opengl:${LD_LIBRARY_PATH}:/usr/local/cuda9.1/lib64:/usr/local/fsl/lib \ + PATH=/opt/ants:/opt/ants/bin:/opt/freesurfer:/opt/itksnap/bin:/opt/mrtrix3/bin:/opt/niftyreg/bin/:/opt/workbench/bin_linux64:${PATH}:/usr/local/cuda9.1/bin:/usr/local/fsl/bin \ + # FSL Options + FSLDIR=/usr/local/fsl \ + FSLOUTPUTTYPE=NIFTI_GZ \ + FSLMULTIFILEQUIT=TRUE \ + FSLTCLSH=$FSLDIR/bin/fsltclsh \ + FSLWISH=$FSLDIR/bin/fslwish +RUN apt-get purge -y -q curl g++ unzip wget \ + && apt-get --purge -y -qq autoremove +ENTRYPOINT ["/bin/bash"] From 4dcb4ce0bcab6d1c60c8cc504536b6cbb6e68e92 Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Wed, 3 May 2023 08:51:04 -0400 Subject: [PATCH 2/5] Update push_container.yml changes by @kaitj from diffparc-surf container deployment to maximize disk space in action --- .github/workflows/push_container.yml | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push_container.yml b/.github/workflows/push_container.yml index e6eb4bf..56f54a8 100644 --- a/.github/workflows/push_container.yml +++ b/.github/workflows/push_container.yml @@ -5,7 +5,7 @@ name: Publish Docker image -on: +on: workflow_dispatch: release: types: [published] @@ -18,22 +18,40 @@ jobs: packages: write contents: read steps: + - name: Maximize build space + uses: easimon/maximize-build-space@master + with: + remove-android: "true" # android-sdk + remove-codeql: "true" # code scanning + remove-dotnet: "true" # .net sdk + remove-haskell: "true" # haskell + remove-docker-images: "true" # rm existing cached images + overprovision-lvm: "true" + - name: Check out the repo uses: actions/checkout@v2 - + - name: Log in to Docker Hub uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: | ${{ github.repository }} - + ghcr.io/${{ github.repository }} + - name: Build and push Docker images uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: From ffb474ac0226151b7dfab9d2ffeab5656e9960cd Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Wed, 3 May 2023 09:05:16 -0400 Subject: [PATCH 3/5] Update Dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 66d7946..3922714 100644 --- a/Dockerfile +++ b/Dockerfile @@ -127,7 +127,6 @@ RUN wget https://humanconnectome.org/storage/app/media/workbench/workbench-linux # Stage: runtime FROM builder as runtime WORKDIR / -COPY --from=diffparc /opt/diffparc-surf/dist/*.whl /opt/diffparc-surf/ COPY --from=ants \ # Commands to copy /opt/ants/bin/antsApplyTransforms \ From 9b4b779e397024dfd2f1a2f017047d9b1fafa4e2 Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Wed, 3 May 2023 15:06:12 -0400 Subject: [PATCH 4/5] add python dependencies from pythondeps-diffparc-app --- Dockerfile | 3 ++- pyproject.toml | 28 ++++++++++++++++++++++++++++ pythondeps/__init__.py | 0 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml create mode 100644 pythondeps/__init__.py diff --git a/Dockerfile b/Dockerfile index 3922714..c93c747 100644 --- a/Dockerfile +++ b/Dockerfile @@ -158,6 +158,7 @@ ENV OS=Linux \ FSLMULTIFILEQUIT=TRUE \ FSLTCLSH=$FSLDIR/bin/fsltclsh \ FSLWISH=$FSLDIR/bin/fslwish -RUN apt-get purge -y -q curl g++ unzip wget \ +COPY . /opt/pythondeps +RUN pip install --prefer-binary --no-cache-dir /opts/pythondeps && apt-get purge -y -q curl g++ unzip wget \ && apt-get --purge -y -qq autoremove ENTRYPOINT ["/bin/bash"] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e2e5eb6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,28 @@ +[tool.poetry] +name = "pythondeps" +version = "0.1.0" +description = "Containerized python environment" +authors = ["Ali Khan "] + +[tool.poetry.dependencies] +python = ">=3.8,<3.12" +matplotlib = "^3.5.2" +nibabel = "^3.2.2" +numpy = "^1.22.3" +templateflow = "^0.8.1" +PyPDF2 = "^1.27.12" +nilearn = "^0.9.1" +pandas = "^1.4.2" +networkx = "^2.7.1" +pillow = "9.0.1" +pyvista = "^0.36.1" +Pygments = "^2.11.2" +snakebids = "^0.8.0" +pybids = "0.15.6" + + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/pythondeps/__init__.py b/pythondeps/__init__.py new file mode 100644 index 0000000..e69de29 From 0ff19d52d5c8f32120d9a21fda166bc28be4357a Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Wed, 3 May 2023 21:21:14 -0400 Subject: [PATCH 5/5] Update Dockerfile fix typo --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c93c747..3441a41 100644 --- a/Dockerfile +++ b/Dockerfile @@ -159,6 +159,6 @@ ENV OS=Linux \ FSLTCLSH=$FSLDIR/bin/fsltclsh \ FSLWISH=$FSLDIR/bin/fslwish COPY . /opt/pythondeps -RUN pip install --prefer-binary --no-cache-dir /opts/pythondeps && apt-get purge -y -q curl g++ unzip wget \ +RUN pip install --prefer-binary --no-cache-dir /opt/pythondeps && apt-get purge -y -q curl g++ unzip wget \ && apt-get --purge -y -qq autoremove ENTRYPOINT ["/bin/bash"]