Skip to content

Commit

Permalink
Merge pull request #457 from jrussell9000/dev
Browse files Browse the repository at this point in the history
Swapping out use of conda in building the dockerfile for the much faster mamba
  • Loading branch information
dkuegler authored Feb 19, 2024
2 parents 7209593 + 445a7d4 commit cc7eedc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
32 changes: 17 additions & 15 deletions Docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
# Image to use to install freesurfer binaries from, the freesurfer binaries
# should be located in /opt/freesurfer in the image.
# - default: build_freesurfer
# - CONDA_BUILD_IAMGE:
# - CONDA_BUILD_IMAGE:
# Image to use to install the python environment from, the python environment
# should be in /venv/ in the image.
# - default: build_cuda
# - CONDA_FILE:
# Which conda minifile to download to install conda
# from https://repo.continuum.io/miniconda/${CONDA_FILE}
# - default: Miniconda3-py38_4.11.0-Linux-x86_64.sh
# - MAMBA_VERSION:
# Which miniforge file to download to install mamba
# from https://github.com/conda-forge/miniforge/releases/download/
# ${FORGE_VERSION}/Miniforge3-${FORGE_VERSION}-Linux-x86_64.sh
# - default: Miniforge3-23.11.0-0-Linux-x86_64.sh

# DOCUMENTATION FOR TARGETS (use '--target <VALUE>'):
# To select which imaged will be tagged with '-t'
Expand Down Expand Up @@ -65,15 +66,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ARG PYTHON_VERSION=3.10
ARG CONDA_FILE=Miniconda3-py310_23.9.0-0-Linux-x86_64.sh
ARG FORGE_VERSION=23.11.0-0

# Install conda
RUN wget --no-check-certificate -qO ~/miniconda.sh https://repo.continuum.io/miniconda/${CONDA_FILE} && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p /opt/conda && \
rm ~/miniconda.sh
RUN wget --no-check-certificate -qO ~/miniforge.sh \
https://github.com/conda-forge/miniforge/releases/download/${FORGE_VERSION}/Miniforge3-${FORGE_VERSION}-Linux-x86_64.sh && \
chmod +x ~/miniforge.sh && \
~/miniforge.sh -b -p /opt/miniforge && \
rm ~/miniforge.sh

ENV PATH /opt/conda/bin:$PATH
ENV PATH /opt/miniforge/bin:$PATH

# create a stage for the common components used across different DEVICE settings
FROM build_base AS build_common
Expand All @@ -86,7 +88,7 @@ COPY ./env/fastsurfer.yml ./Docker/conda_pack.sh ./Docker/install_env.py /instal

ARG DEBUG=false
RUN python /install/install_env.py -m base -i /install/fastsurfer.yml -o /install/base-env.yml && \
conda env create -f "/install/base-env.yml" | tee /install/env-create.log ; \
mamba env create -f "/install/base-env.yml" | tee /install/env-create.log ; \
if [ "${DEBUG}" != "true" ]; then \
rm /install/base-env.yml ; \
fi
Expand All @@ -97,11 +99,11 @@ ARG DEBUG=false
ARG DEVICE=cu118
# install additional packages for cuda/rocm/cpu
RUN python /install/install_env.py -m ${DEVICE} -i /install/fastsurfer.yml -o /install/${DEVICE}-env.yml && \
conda env update -n "fastsurfer" -f "/install/${DEVICE}-env.yml" | tee /install/env-update.log && \
mamba env update -n "fastsurfer" -f "/install/${DEVICE}-env.yml" | tee /install/env-update.log && \
/install/conda_pack.sh "fastsurfer" && \
echo "DEBUG=$DEBUG\nDEVICE=$DEVICE\n" > /install/build_conda.args ; \
if [ "${DEBUG}" != "true" ]; then \
conda env remove -n "fastsurfer" && \
mamba env remove -n "fastsurfer" && \
rm -R /install ; \
fi

Expand Down Expand Up @@ -197,4 +199,4 @@ FROM runtime as runtime_cuda

ENV NVIDIA_VISIBLE_DEVICES=all \
NVIDIA_DRIVER_CAPABILITIES=compute,utility \
NVIDIA_REQUIRE_CUDA="cuda>=8.0"
NVIDIA_REQUIRE_CUDA="cuda>=8.0"
4 changes: 2 additions & 2 deletions Docker/conda_pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
set -e

# Install conda-pack
conda install -c conda-forge conda-pack
mamba install -c conda-forge conda-pack
# Use conda-pack to create a standalone environment in /venv
conda-pack -n "$1" -o /tmp/env.tar
mkdir /venv
cd /venv
tar xf /tmp/env.tar
rm /tmp/env.tar
# Finally, when venv in a new location, fix up paths
/venv/bin/conda-unpack
/venv/bin/conda-unpack

0 comments on commit cc7eedc

Please sign in to comment.