repo2docker/repo2docker/buildpacks/conda/install-base-env.bash

88 wiersze
2.6 KiB
Bash
Czysty Zwykły widok Historia

2017-07-30 01:19:41 +00:00
#!/bin/bash
2021-05-03 11:48:50 +00:00
# This downloads and installs a pinned version of micromamba
# and sets up the base environment
2017-07-30 01:19:41 +00:00
set -ex
cd $(dirname $0)
2019-04-04 18:36:54 +00:00
2024-03-22 20:34:50 +00:00
export MAMBA_VERSION=1.5.7
2024-03-24 21:16:05 +00:00
export CONDA_VERSION=24.3.0
URL="https://anaconda.org/conda-forge/micromamba/${MAMBA_VERSION}/download/${CONDA_PLATFORM}/micromamba-${MAMBA_VERSION}-0.tar.bz2"
2017-07-30 01:19:41 +00:00
# make sure we don't do anything funky with user's $HOME
# since this is run as root
unset HOME
2021-04-20 07:34:08 +00:00
mkdir -p ${CONDA_DIR}
2017-07-30 01:19:41 +00:00
export MICROMAMBA_EXE="/usr/local/bin/micromamba"
time wget -qO- ${URL} | tar -xvj bin/micromamba
mv bin/micromamba "$MICROMAMBA_EXE"
chmod 0755 "$MICROMAMBA_EXE"
2021-05-03 11:48:50 +00:00
eval "$(${MICROMAMBA_EXE} shell hook -p ${CONDA_DIR} -s posix)"
2020-03-05 05:32:52 +00:00
2021-04-20 07:34:08 +00:00
micromamba activate
2021-04-20 07:34:08 +00:00
export PATH="${PWD}/bin:$PATH"
2017-07-30 01:19:41 +00:00
2021-04-20 07:34:08 +00:00
cat <<EOT >> ${CONDA_DIR}/.condarc
channels:
- conda-forge
2021-04-20 07:34:08 +00:00
- defaults
auto_update_conda: false
show_channel_urls: true
update_dependencies: false
2021-10-12 08:29:09 +00:00
# channel_priority: flexible
2021-04-20 07:34:08 +00:00
EOT
2020-12-08 10:23:21 +00:00
micromamba install conda=${CONDA_VERSION} mamba=${MAMBA_VERSION} -y
echo "installing notebook env:"
cat "${NB_ENVIRONMENT_FILE}"
2020-03-10 12:00:56 +00:00
time ${MAMBA_EXE} create -p ${NB_PYTHON_PREFIX} --file "${NB_ENVIRONMENT_FILE}"
if [[ ! -z "${NB_REQUIREMENTS_FILE:-}" ]]; then
echo "installing pip requirements"
cat "${NB_REQUIREMENTS_FILE}"
${NB_PYTHON_PREFIX}/bin/python -mpip install --no-cache --no-deps -r "${NB_REQUIREMENTS_FILE}"
fi
# 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
2018-02-01 13:28:23 +00:00
if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" ]]; then
# install kernel env and register kernelspec
echo "installing kernel env:"
cat "${KERNEL_ENVIRONMENT_FILE}"
time ${MAMBA_EXE} create -p ${KERNEL_PYTHON_PREFIX} --file "${KERNEL_ENVIRONMENT_FILE}"
if [[ ! -z "${KERNEL_REQUIREMENTS_FILE:-}" ]]; then
echo "installing pip requirements for kernel"
cat "${KERNEL_REQUIREMENTS_FILE}"
${KERNEL_PYTHON_PREFIX}/bin/python -mpip install --no-cache --no-deps -r "${KERNEL_REQUIREMENTS_FILE}"
fi
${KERNEL_PYTHON_PREFIX}/bin/ipython kernel install --prefix "${NB_PYTHON_PREFIX}"
echo '' > ${KERNEL_PYTHON_PREFIX}/conda-meta/history
${MAMBA_EXE} list -p ${KERNEL_PYTHON_PREFIX}
fi
2017-07-30 01:19:41 +00:00
# Clean things out!
time ${MAMBA_EXE} clean --all -f -y
2019-05-05 12:55:58 +00:00
2021-05-03 11:48:50 +00:00
# Remove the pip cache created as part of installing micromamba
rm -rf /root/.cache
2017-07-30 01:19:41 +00:00
chown -R $NB_USER:$NB_USER ${CONDA_DIR}
${MAMBA_EXE} list -p ${NB_PYTHON_PREFIX}
# Set NPM config
${NB_PYTHON_PREFIX}/bin/npm config --global set prefix ${NPM_DIR}