Skip to content

Commit a53fcbe

Browse files
authored
Merge pull request #1594 from maresb/micromamba
Use micromamba to bootstrap mamba
2 parents 4b830d5 + a8579ea commit a53fcbe

File tree

3 files changed

+51
-60
lines changed

3 files changed

+51
-60
lines changed

base-notebook/Dockerfile

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ RUN apt-get update --yes && \
2626
# the ubuntu base image is rebuilt too seldom sometimes (less than once a month)
2727
apt-get upgrade --yes && \
2828
apt-get install --yes --no-install-recommends \
29+
# - bzip2 is necessary to extract the micromamba executable.
30+
bzip2 \
2931
ca-certificates \
3032
fonts-liberation \
3133
locales \
@@ -81,72 +83,60 @@ RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \
8183
fix-permissions "${CONDA_DIR}"
8284

8385
USER ${NB_UID}
84-
ARG PYTHON_VERSION=default
86+
87+
# Pin python version here, or set it to "default"
88+
ARG PYTHON_VERSION=3.9
8589

8690
# Setup work directory for backward-compatibility
8791
RUN mkdir "/home/${NB_USER}/work" && \
8892
fix-permissions "/home/${NB_USER}"
8993

90-
# Install conda as jovyan and check the sha256 sum provided on the download site
91-
WORKDIR /tmp
92-
93-
# CONDA_MIRROR is a mirror prefix to speed up downloading
94-
# For example, people from mainland China could set it as
95-
# https://mirrors.tuna.tsinghua.edu.cn/github-release/conda-forge/miniforge/LatestRelease
96-
ARG CONDA_MIRROR=https://github.com/conda-forge/miniforge/releases/latest/download
97-
98-
# ---- Miniforge installer ----
99-
# Check https://github.com/conda-forge/miniforge/releases
100-
# Package Manager and Python implementation to use (https://github.com/conda-forge/miniforge)
101-
# We're using Mambaforge installer, possible options:
102-
# - conda only: either Miniforge3 to use Python or Miniforge-pypy3 to use PyPy
103-
# - conda + mamba: either Mambaforge to use Python or Mambaforge-pypy3 to use PyPy
104-
# Installation: conda, mamba, pip
105-
RUN set -x && \
106-
# Miniforge installer
107-
miniforge_arch=$(uname -m) && \
108-
miniforge_installer="Mambaforge-Linux-${miniforge_arch}.sh" && \
109-
wget --quiet "${CONDA_MIRROR}/${miniforge_installer}" && \
110-
/bin/bash "${miniforge_installer}" -f -b -p "${CONDA_DIR}" && \
111-
rm "${miniforge_installer}" && \
112-
# Conda configuration see https://conda.io/projects/conda/en/latest/configuration.html
113-
conda config --system --set auto_update_conda false && \
114-
conda config --system --set show_channel_urls true && \
115-
if [[ "${PYTHON_VERSION}" != "default" ]]; then mamba install --quiet --yes python="${PYTHON_VERSION}"; fi && \
116-
# Pin major.minor version of python
117-
mamba list python | grep '^python ' | tr -s ' ' | cut -d ' ' -f 1,2 >> "${CONDA_DIR}/conda-meta/pinned" && \
118-
# Using conda to update all packages: https://github.com/mamba-org/mamba/issues/1092
119-
conda update --all --quiet --yes && \
120-
conda clean --all -f -y && \
121-
rm -rf "/home/${NB_USER}/.cache/yarn" && \
122-
fix-permissions "${CONDA_DIR}" && \
123-
fix-permissions "/home/${NB_USER}"
124-
125-
# Using fixed version of mamba in arm, because the latest one has problems with arm under qemu
126-
# See: https://github.com/jupyter/docker-stacks/issues/1539
127-
RUN set -x && \
128-
arch=$(uname -m) && \
129-
if [ "${arch}" == "aarch64" ]; then \
130-
mamba install --quiet --yes \
131-
'mamba<0.18' && \
132-
mamba clean --all -f -y && \
133-
fix-permissions "${CONDA_DIR}" && \
134-
fix-permissions "/home/${NB_USER}"; \
135-
fi;
136-
137-
# Install Jupyter Notebook, Lab, and Hub
94+
# Download and install Micromamba, and initialize Conda prefix.
95+
# <https://github.com/mamba-org/mamba#micromamba>
96+
# Similar projects using Micromamba:
97+
# - Micromamba-Docker: <https://github.com/mamba-org/micromamba-docker>
98+
# - repo2docker: <https://github.com/jupyterhub/repo2docker>
99+
# Install Python, Mamba, Jupyter Notebook, Lab, and Hub
138100
# Generate a notebook server config
139-
# Cleanup temporary files
101+
# Cleanup temporary files and remove Micromamba
140102
# Correct permissions
141103
# Do all this in a single RUN command to avoid duplicating all of the
142104
# files across image layers when the permissions change
143-
RUN mamba install --quiet --yes \
144-
'notebook' \
145-
'jupyterhub' \
146-
'jupyterlab' && \
105+
COPY --chown="${NB_UID}:${NB_GID}" initial-condarc "${CONDA_DIR}/.condarc"
106+
WORKDIR /tmp
107+
RUN set -x && \
108+
arch=$(uname -m) && \
109+
if [ "${arch}" = "x86_64" ]; then \
110+
# Should be simpler, see <https://github.com/mamba-org/mamba/issues/1437>
111+
arch="64"; \
112+
fi && \
113+
wget -qO /tmp/micromamba.tar.bz2 \
114+
"https://micromamba.snakepit.net/api/micromamba/linux-${arch}/latest" && \
115+
tar -xvjf /tmp/micromamba.tar.bz2 --strip-components=1 bin/micromamba && \
116+
rm /tmp/micromamba.tar.bz2 && \
117+
PYTHON_SPECIFIER="python=${PYTHON_VERSION}" && \
118+
if [[ "${PYTHON_VERSION}" == "default" ]]; then PYTHON_SPECIFIER="python"; fi && \
119+
if [ "${arch}" == "aarch64" ]; then \
120+
# Prevent libmamba from sporadically hanging on arm64 under QEMU
121+
# <https://github.com/mamba-org/mamba/issues/1611>
122+
./micromamba config set extract_threads 1; \
123+
fi && \
124+
# Install the packages
125+
./micromamba install \
126+
--root-prefix="${CONDA_DIR}" \
127+
--prefix="${CONDA_DIR}" \
128+
--yes \
129+
"${PYTHON_SPECIFIER}" \
130+
'mamba' \
131+
'notebook' \
132+
'jupyterhub' \
133+
'jupyterlab' && \
134+
rm micromamba && \
135+
# Pin major.minor version of python
136+
mamba list python | grep '^python ' | tr -s ' ' | cut -d ' ' -f 1,2 >> "${CONDA_DIR}/conda-meta/pinned" && \
137+
jupyter notebook --generate-config && \
147138
mamba clean --all -f -y && \
148139
npm cache clean --force && \
149-
jupyter notebook --generate-config && \
150140
jupyter lab clean && \
151141
rm -rf "/home/${NB_USER}/.cache/yarn" && \
152142
fix-permissions "${CONDA_DIR}" && \

base-notebook/initial-condarc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Conda configuration see https://conda.io/projects/conda/en/latest/configuration.html
2+
3+
auto_update_conda: false
4+
show_channel_urls: true
5+
channels:
6+
- conda-forge

tests/base-notebook/test_packages.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@
6868
"ca-certificates",
6969
"conda-forge::blas[build=openblas]",
7070
"hdf5",
71-
# TODO(asalikhov)
72-
# When we remove a workaround for arm regarding mamba, we can
73-
# test installation of mamba as well and remove this exception.
74-
# See: <https://github.com/jupyter/docker-stacks/issues/1539>
75-
"mamba[version='<0.18']",
7671
"openssl",
7772
"protobuf",
7873
"python",

0 commit comments

Comments
 (0)