Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@


def setup(app):
app.add_stylesheet("custom.css") # may also be a URL
app.add_css_file("custom.css") # may also be a URL
app.add_config_value(
"recommonmark_config", {"auto_toc_tree_section": "Contents"}, True
)
Expand Down
22 changes: 12 additions & 10 deletions repo2docker/buildpacks/conda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def get_build_env(self):
env = super().get_build_env() + [
("CONDA_DIR", "${APP_BASE}/conda"),
("NB_PYTHON_PREFIX", "${CONDA_DIR}/envs/notebook"),
("MAMBA_ROOT_PREFIX", "${CONDA_DIR}"),
("MAMBA_EXE", "/tmp/bin/micromamba"),
]
if self.py2:
env.append(("KERNEL_PYTHON_PREFIX", "${CONDA_DIR}/envs/kernel"))
Expand Down Expand Up @@ -63,7 +65,7 @@ def get_build_scripts(self):

All scripts here should be independent of contents of the repository.

This sets up through `install-miniforge.bash` (found in this directory):
This sets up through `install-base-env.bash` (found in this directory):

- a directory for the conda environment and its ownership by the
notebook user
Expand All @@ -80,8 +82,8 @@ def get_build_scripts(self):
"root",
r"""
TIMEFORMAT='time: %3R' \
bash -c 'time /tmp/install-miniforge.bash' && \
rm /tmp/install-miniforge.bash /tmp/environment.yml
bash -c 'time /tmp/install-base-env.bash' && \
rm /tmp/install-base-env.bash /tmp/environment.yml
""",
)
]
Expand All @@ -104,7 +106,7 @@ def get_build_script_files(self):

"""
files = {
"conda/install-miniforge.bash": "/tmp/install-miniforge.bash",
"conda/install-base-env.bash": "/tmp/install-base-env.bash",
"conda/activate-conda.sh": "/etc/profile.d/activate-conda.sh",
}
py_version = self.python_version
Expand Down Expand Up @@ -277,9 +279,9 @@ def get_env_scripts(self):
"${NB_USER}",
r"""
TIMEFORMAT='time: %3R' \
bash -c 'time mamba env update -p {0} -f "{1}" && \
time mamba clean --all -f -y && \
mamba list -p {0} \
bash -c 'time /tmp/bin/micromamba install -p {0} -f "{1}" && \
# time /tmp/bin/micromamba clean --all -y && \
/tmp/bin/micromamba list -p {0} \
'
""".format(
env_prefix, environment_yml
Expand All @@ -296,9 +298,9 @@ def get_env_scripts(self):
(
"${NB_USER}",
r"""
mamba install -p {0} r-base{1} r-irkernel={2} r-devtools -y && \
mamba clean --all -f -y && \
mamba list -p {0}
/tmp/bin/micromamba install -p {0} r-base{1} r-irkernel={2} r-devtools -y && \
# /tmp/bin/micromamba clean --all -f -y && \
/tmp/bin/micromamba list -p {0}
""".format(
env_prefix, r_pin, IRKERNEL_VERSION
),
Expand Down
10 changes: 6 additions & 4 deletions repo2docker/buildpacks/conda/activate-conda.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# enable conda and activate the notebook environment
CONDA_PROFILE="${CONDA_DIR}/etc/profile.d/conda.sh"
export MAMBA_EXE="/tmp/bin/micromamba"
export MAMBA_ROOT_PREFIX="/srv/conda"
CONDA_PROFILE="${CONDA_DIR}/etc/profile.d/mamba.sh"
test -f $CONDA_PROFILE && . $CONDA_PROFILE
if [[ "${KERNEL_PYTHON_PREFIX}" != "${NB_PYTHON_PREFIX}" ]]; then
# if the kernel is a separate env, stack them
# so both are on PATH, notebook first
conda activate ${KERNEL_PYTHON_PREFIX}
conda activate --stack ${NB_PYTHON_PREFIX}
micromamba activate ${KERNEL_PYTHON_PREFIX}
micromamba activate --stack ${NB_PYTHON_PREFIX}

# even though it's second on $PATH
# make sure CONDA_DEFAULT_ENV is the *kernel* env
Expand All @@ -14,5 +16,5 @@ if [[ "${KERNEL_PYTHON_PREFIX}" != "${NB_PYTHON_PREFIX}" ]]; then
# which only contains UI when the two are different
export CONDA_DEFAULT_ENV="${KERNEL_PYTHON_PREFIX}"
else
conda activate ${NB_PYTHON_PREFIX}
micromamba activate ${NB_PYTHON_PREFIX}
fi
68 changes: 68 additions & 0 deletions repo2docker/buildpacks/conda/install-base-env.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
# This downloads and installs a pinned version of micromamba
# and sets up the base environment
set -ex


cd $(dirname $0)

URL="https://github.com/mamba-org/boa-forge/releases/download/micromamba-nightly-21.5.31.1722/micromamba-nightly-linux-64"

# make sure we don't do anything funky with user's $HOME
# since this is run as root
unset HOME
mkdir -p ${CONDA_DIR}

time wget ${URL} && mkdir bin && mv micromamba-nightly-linux-64 bin/micromamba
chmod +x bin/micromamba

export MAMBA_ROOT_PREFIX=${CONDA_DIR}
export MAMBA_EXE="/tmp/bin/micromamba"

eval "$(./bin/micromamba shell hook -p ${CONDA_DIR} -s posix)"
./bin/micromamba shell init -s bash -p ${CONDA_DIR}

micromamba activate

export PATH="${PWD}/bin:$PATH"

cat <<EOT >> ${CONDA_DIR}/.condarc
channels:
- conda-forge
- defaults
auto_update_conda: false
show_channel_urls: true
update_dependencies: false
channel_priority: strict
EOT

echo "installing notebook env:"
cat /tmp/environment.yml
time micromamba create -p ${NB_PYTHON_PREFIX} -f /tmp/environment.yml

# empty conda history file,
# which seems to result in some effective pinning of packages in the initial env,
# which we don't intend.
# this file must not be *removed*, however
echo '' > ${NB_PYTHON_PREFIX}/conda-meta/history

if [[ -f /tmp/kernel-environment.yml ]]; then
# install kernel env and register kernelspec
echo "installing kernel env:"
cat /tmp/kernel-environment.yml

time micromamba create -p ${KERNEL_PYTHON_PREFIX} -f /tmp/kernel-environment.yml
${KERNEL_PYTHON_PREFIX}/bin/ipython kernel install --prefix "${NB_PYTHON_PREFIX}"
echo '' > ${KERNEL_PYTHON_PREFIX}/conda-meta/history
micromamba list -p ${KERNEL_PYTHON_PREFIX}
fi

# Clean things out!
time micromamba clean --all -y

# Remove the pip cache created as part of installing micromamba
rm -rf /root/.cache

chown -R $NB_USER:$NB_USER ${CONDA_DIR}

micromamba list -p ${NB_PYTHON_PREFIX}
80 changes: 0 additions & 80 deletions repo2docker/buildpacks/conda/install-miniforge.bash

This file was deleted.

4 changes: 2 additions & 2 deletions tests/conda/binder-dir/verify
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from subprocess import check_output

assert sys.version_info[:2] == (3, 5), sys.version

out = check_output(["conda", "--version"]).decode("utf8").strip()
assert out == "conda 4.9.2", out
out = check_output(["/tmp/bin/micromamba", "--version"]).decode("utf8").strip()
assert out == "21.5.31.1722", out

import numpy
2 changes: 1 addition & 1 deletion tests/conda/default-env/postBuild
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# install pytest with conda in the default env (should be $KERNEL_PYTHON_PREFIX)
conda install -yq pytest
/tmp/bin/micromamba install -yq pytest -p $KERNEL_PYTHON_PREFIX
# install there with pip (should be the same)
pip install there
8 changes: 6 additions & 2 deletions tests/conda/simple-py2/verify
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ assert sorted(specs) == ["python2", "python3"], specs.keys()
import json
from subprocess import check_output

envs = json.loads(check_output(["conda", "env", "list", "--json"]).decode("utf8"))
envs = json.loads(
check_output(["/tmp/bin/micromamba", "env", "list", "--json"]).decode("utf8")
)
assert envs == {
"envs": ["/srv/conda", "/srv/conda/envs/kernel", "/srv/conda/envs/notebook"]
}, envs

pkgs = json.loads(
check_output(["conda", "list", "-n", "kernel", "--json"]).decode("utf8")
check_output(["/tmp/bin/micromamba", "list", "-n", "kernel", "--json"]).decode(
"utf8"
)
)
pkg_names = [pkg["name"] for pkg in pkgs]
assert "ipykernel" in pkg_names, pkg_names
Expand Down
1 change: 1 addition & 0 deletions tests/pipfile/environment-yml/environment.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependencies:
- pip
- pip:
- pypi-pkg-test