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
|
2020-06-26 13:03:26 +00:00
|
|
|
# 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
|
2022-01-21 09:57:11 +00:00
|
|
|
|
2023-01-01 15:52:19 +00:00
|
|
|
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
|
|
|
|
2019-03-04 15:01:24 +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
|
|
|
|
2022-01-28 14:58:13 +00:00
|
|
|
export MICROMAMBA_EXE="/usr/local/bin/micromamba"
|
2022-01-27 08:55:11 +00:00
|
|
|
|
|
|
|
time wget -qO- ${URL} | tar -xvj bin/micromamba
|
2022-01-28 14:58:13 +00:00
|
|
|
mv bin/micromamba "$MICROMAMBA_EXE"
|
|
|
|
chmod 0755 "$MICROMAMBA_EXE"
|
2021-05-03 11:48:50 +00:00
|
|
|
|
2022-01-28 14:58:13 +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
|
2018-02-01 16:38:09 +00:00
|
|
|
|
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:
|
2021-05-17 08:24:00 +00:00
|
|
|
- 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
|
|
|
|
2022-01-21 09:57:11 +00:00
|
|
|
micromamba install conda=${CONDA_VERSION} mamba=${MAMBA_VERSION} -y
|
2021-11-18 09:59:10 +00:00
|
|
|
|
2019-04-25 13:44:51 +00:00
|
|
|
echo "installing notebook env:"
|
2021-03-03 14:35:29 +00:00
|
|
|
cat "${NB_ENVIRONMENT_FILE}"
|
2019-04-25 13:44:51 +00:00
|
|
|
|
2020-03-10 12:00:56 +00:00
|
|
|
|
2022-01-28 14:58:13 +00:00
|
|
|
time ${MAMBA_EXE} create -p ${NB_PYTHON_PREFIX} --file "${NB_ENVIRONMENT_FILE}"
|
2019-04-25 13:44:51 +00:00
|
|
|
|
2021-03-08 11:58:07 +00:00
|
|
|
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
|
2019-04-25 13:44:51 +00:00
|
|
|
# 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
|
|
|
|
2021-03-08 11:58:07 +00:00
|
|
|
if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" ]]; then
|
2018-01-03 17:17:33 +00:00
|
|
|
# install kernel env and register kernelspec
|
2018-02-01 16:38:09 +00:00
|
|
|
echo "installing kernel env:"
|
2021-03-03 14:35:29 +00:00
|
|
|
cat "${KERNEL_ENVIRONMENT_FILE}"
|
2022-01-28 14:58:13 +00:00
|
|
|
time ${MAMBA_EXE} create -p ${KERNEL_PYTHON_PREFIX} --file "${KERNEL_ENVIRONMENT_FILE}"
|
2021-03-08 11:58:07 +00:00
|
|
|
|
|
|
|
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}"
|
2021-03-03 14:35:29 +00:00
|
|
|
fi
|
2018-02-01 16:38:09 +00:00
|
|
|
|
2019-04-25 14:53:50 +00:00
|
|
|
${KERNEL_PYTHON_PREFIX}/bin/ipython kernel install --prefix "${NB_PYTHON_PREFIX}"
|
|
|
|
echo '' > ${KERNEL_PYTHON_PREFIX}/conda-meta/history
|
2022-01-28 14:58:13 +00:00
|
|
|
${MAMBA_EXE} list -p ${KERNEL_PYTHON_PREFIX}
|
2018-01-03 17:17:33 +00:00
|
|
|
fi
|
2019-02-08 11:07:31 +00:00
|
|
|
|
2017-07-30 01:19:41 +00:00
|
|
|
# Clean things out!
|
2022-01-28 14:58:13 +00:00
|
|
|
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
|
2019-05-04 11:03:50 +00:00
|
|
|
rm -rf /root/.cache
|
2017-07-30 01:19:41 +00:00
|
|
|
|
|
|
|
chown -R $NB_USER:$NB_USER ${CONDA_DIR}
|
2019-02-08 10:24:35 +00:00
|
|
|
|
2022-01-28 14:58:13 +00:00
|
|
|
${MAMBA_EXE} list -p ${NB_PYTHON_PREFIX}
|
2021-11-19 16:30:10 +00:00
|
|
|
|
|
|
|
# Set NPM config
|
|
|
|
${NB_PYTHON_PREFIX}/bin/npm config --global set prefix ${NPM_DIR}
|