44# This Dockerfile exists to provide a method of installing all packages from
55# `conda` using only Official and Verified Docker images.
66# The base image for training is an Official Docker Linux image, e.g., Ubuntu.
7- # The `git` and `conda` images are both from verified publishers.
8- # Also, they are used only to download files and packages.
9- # The training image does not include them and they remain in the build cache.
7+ # The `git` image is from a verified publisher and only used to download files.
8+ # The training image does not include it and it remains in the build cache.
109
1110ARG LOCK_MODE
1211ARG BASE_IMAGE
1312ARG INTERACTIVE_MODE
1413# The Bitnami Docker verified git image has `curl` installed in `/usr/bin/curl`
1514# and recent versions have both AMD64 and ARM64 architecture support.
1615ARG GIT_IMAGE=bitnami/git:latest
17- # The Miniconda3 verified image is only used
18- # if strict requirements are installed via `conda-lock` files.
19- ARG CONDA_IMAGE=continuumio/miniconda3:latest
16+
2017# #######################################################################
2118FROM ${GIT_IMAGE} AS stash
2219
@@ -36,11 +33,14 @@ RUN git clone --depth 1 ${PURE_URL} /opt/zsh/pure
3633RUN git clone --depth 1 ${ZSHA_URL} /opt/zsh/zsh-autosuggestions
3734RUN git clone --depth 1 ${ZSHS_URL} /opt/zsh/zsh-syntax-highlighting
3835
39- ARG CONDA_URL
40- RUN mkdir /tmp/conda && curl -fsSL -v -o /tmp/conda/miniconda.sh -O ${CONDA_URL}
41-
4236COPY --link ../reqs/apt-simple.requirements.txt /tmp/apt/requirements.txt
43- COPY --link ../reqs/simple-environment.yaml /tmp/req/environment.yaml
37+
38+ ARG CONDA_URL
39+ WORKDIR /tmp/conda
40+ RUN curl -fsSL -v -o /tmp/conda/miniconda.sh -O ${CONDA_URL} && \
41+ /bin/bash /tmp/conda/miniconda.sh -b -p /opt/conda && \
42+ printf "channels:\n - conda-forge\n - nodefaults\n " > /opt/conda/.condarc
43+ WORKDIR /
4444
4545# #######################################################################
4646FROM ${BASE_IMAGE} AS conda-lock-exclude
@@ -53,27 +53,41 @@ ENV PYTHONIOENCODING=UTF-8
5353ARG PYTHONDONTWRITEBYTECODE=1
5454ARG PYTHONUNBUFFERED=1
5555
56- RUN --mount=type=bind,from=stash,source=/tmp/conda,target=/tmp/conda \
57- /bin/bash /tmp/conda/miniconda.sh -b -p /opt/conda && \
58- printf "channels:\n - conda-forge\n - nodefaults\n " > /opt/conda/.condarc
56+ ARG PATH=/opt/conda/bin:$PATH
5957
6058# `CONDA_MANAGER` may be either `mamba` or `conda`.
6159ARG CONDA_MANAGER
62- ENV conda=/opt/conda/bin/${CONDA_MANAGER}
60+ ARG conda=/opt/conda/bin/${CONDA_MANAGER}
6361
64- # Use package caching to speed up installs. Borrow `curl` from the git image.
62+ # Using package caching to speed up installs.
63+ # A `CondaVerificationError` may occur if the cache is corrupted.
64+ # Use `docker builder prune` to clear out the build cache if it does.
6565ARG PIP_CACHE_DIR=/root/.cache/pip
6666ARG CONDA_PKGS_DIRS=/opt/conda/pkgs
67- RUN --mount=type=bind,from=stash,source=/tmp/req,target=/tmp/req \
68- --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
67+ COPY --link --from=stash /opt/conda /opt/conda
68+ COPY --link ../reqs/simple-environment.yaml /tmp/req/environment.yaml
69+ RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
6970 --mount=type=cache,target=${CONDA_PKGS_DIRS},sharing=locked \
7071 $conda env update --file /tmp/req/environment.yaml
7172
73+ # Cleaning must be in a separate `RUN` command to preserve the Docker cache.
74+ RUN /opt/conda/bin/conda clean -fya
75+
7276# #######################################################################
73- FROM ${CONDA_IMAGE} AS conda-lock
77+ FROM stash AS lock-stash
78+ # Extra stash for using `conda-lock` files. This stage is derived from `stash`
79+ # to reduce code repitition at the cost of unnecessary extra build cache.
80+
81+ ARG CONDA_MANAGER
82+ # Wierd paths necessary because `CONDA_PREFIX` is immutable post-installation.
83+ ARG conda=/opt/_conda/bin/${CONDA_MANAGER}
84+ RUN /bin/bash /tmp/conda/miniconda.sh -b -p /opt/_conda && \
85+ printf "channels:\n - conda-forge\n - nodefaults\n " > /opt/_conda/.condarc && \
86+ $conda install conda-lock
87+
88+ # #######################################################################
89+ FROM ${BASE_IMAGE} AS conda-lock-include
7490# Use this stage only if installing from `conda-lock`.
75- # Users must create their own `simple-conda-lock.yaml` file to use this stage.
76- COPY --link ../reqs/simple-conda-lock.yaml /tmp/conda/lock.yaml
7791
78927993ENV LANG=C.UTF-8
@@ -82,26 +96,26 @@ ENV PYTHONIOENCODING=UTF-8
8296ARG PYTHONDONTWRITEBYTECODE=1
8397ARG PYTHONUNBUFFERED=1
8498
99+ ARG PATH=/opt/_conda/bin:$PATH
100+ COPY --link --from=lock-stash /opt/_conda /opt/_conda
101+ COPY --link ../reqs/simple.conda-lock.yaml /tmp/conda/lock.yaml
102+ # Saves to `conda-linux-64.lock`, which can be installed via `conda create`
103+ RUN conda-lock render -p linux-64 /tmp/conda/lock.yaml
104+
105+ ARG CONDA_MANAGER
106+ ARG conda=/opt/_conda/bin/${CONDA_MANAGER}
85107ARG PIP_CACHE_DIR=/root/.cache/pip
86- ARG CONDA_PKGS_DIRS=/opt/conda/pkgs
87- # Set default channel to `conda-forge` for both the installing and installed
88- # `conda` envirnments to prevent any ambiguities during and after installation.
108+ ARG CONDA_PKGS_DIRS=/opt/_conda/pkgs
89109RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
90110 --mount=type=cache,target=${CONDA_PKGS_DIRS},sharing=locked \
91- printf "channels:\n - conda-forge\n - nodefaults\n " > /opt/conda/.condarc && \
92- conda create -p /opt/env --copy --file /tmp/conda/lock.yaml && \
93- printf "channels:\n - conda-forge\n - nodefaults\n " > /opt/env/.condarc
94-
95- # #######################################################################
96- FROM ${BASE_IMAGE} AS conda-lock-include
97-
98- COPY --link --from=conda-lock /opt/env /opt/conda
111+ $conda create --no-deps --no-default-packages --copy -p /opt/conda \
112+ --file conda-linux-64.lock && \
113+ printf "channels:\n - conda-forge\n - nodefaults\n " > /opt/conda/.condarc
99114
100115# #######################################################################
101116FROM conda-lock-${LOCK_MODE} AS install-conda
102117# Cleanup before copying to reduce image size.
103- RUN /opt/conda/bin/conda clean -fya && \
104- find /opt/conda -name '__pycache__' | xargs rm -rf
118+ RUN find /opt/conda -name '__pycache__' | xargs rm -rf
105119
106120# Heuristic fix to find NVRTC for CUDA 11.2+.
107121# Change this for older CUDA versions and for CUDA 12.x.
0 commit comments