Skip to content

Commit 22cec4b

Browse files
authored
Implement installation from conda-lock.yaml files. (#107)
* Add `conda-lock` file for the `simple` service. * Reformat lockfile according to prettier rules. * Rename lockfile to match standard. * Add `conda-lock.yaml` file to the .dockerignore to allow installation. * Implement a working installation from `conda-lock`. * Rename directory containing Dockerfiles from `misc` to `dockerfiles`.
1 parent c918561 commit 22cec4b

File tree

6 files changed

+1927
-36
lines changed

6 files changed

+1927
-36
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
!**/*requirements*.txt
88
!*environment*.yaml
99
!**/*environment*.yaml
10+
!*conda-lock.yaml
11+
!**/*conda-lock.yaml

docker-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ services:
164164
- "${HOSTNAME:-ngc}:127.0.0.1"
165165
build:
166166
target: ${TARGET_STAGE:-train}
167-
dockerfile: misc/ngc.Dockerfile
167+
dockerfile: dockerfiles/ngc.Dockerfile
168168
args:
169169
NGC_YEAR: ${NGC_YEAR:-23}
170170
NGC_MONTH: ${NGC_MONTH:-03}
@@ -185,7 +185,7 @@ services:
185185
- "${HOSTNAME:-hub}:127.0.0.1"
186186
build:
187187
target: ${TARGET_STAGE:-train}
188-
dockerfile: misc/hub.Dockerfile
188+
dockerfile: dockerfiles/hub.Dockerfile
189189
args:
190190
PYTORCH_VERSION: ${PYTORCH_VERSION:-2.0.0}
191191
# Note that `CUDA_SHORT_VERSION` excludes the patch version numbers.
@@ -205,7 +205,7 @@ services:
205205
- .:${PROJECT_ROOT:-/opt/project}
206206
build:
207207
target: ${TARGET_STAGE:-train}
208-
dockerfile: misc/simple.Dockerfile
208+
dockerfile: dockerfiles/simple.Dockerfile
209209
args:
210210
BASE_IMAGE: ${LINUX_DISTRO:-ubuntu}:${DISTRO_VERSION:-22.04}
211211
INTERACTIVE_MODE: ${INTERACTIVE_MODE:-include}
Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
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

1110
ARG LOCK_MODE
1211
ARG BASE_IMAGE
1312
ARG 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.
1615
ARG 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
########################################################################
2118
FROM ${GIT_IMAGE} AS stash
2219

@@ -36,11 +33,14 @@ RUN git clone --depth 1 ${PURE_URL} /opt/zsh/pure
3633
RUN git clone --depth 1 ${ZSHA_URL} /opt/zsh/zsh-autosuggestions
3734
RUN 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-
4236
COPY --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
########################################################################
4646
FROM ${BASE_IMAGE} AS conda-lock-exclude
@@ -53,27 +53,41 @@ ENV PYTHONIOENCODING=UTF-8
5353
ARG PYTHONDONTWRITEBYTECODE=1
5454
ARG 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`.
6159
ARG 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.
6565
ARG PIP_CACHE_DIR=/root/.cache/pip
6666
ARG 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

7892
7993
ENV LANG=C.UTF-8
@@ -82,26 +96,26 @@ ENV PYTHONIOENCODING=UTF-8
8296
ARG PYTHONDONTWRITEBYTECODE=1
8397
ARG 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}
85107
ARG 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
89109
RUN --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
########################################################################
101116
FROM 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

Comments
 (0)