|
| 1 | +#!/bin/bash |
| 2 | +# This downloads and installs a pinned version of micromamba |
| 3 | +# and sets up the base environment |
| 4 | +set -ex |
| 5 | + |
| 6 | +cd $(dirname $0) |
| 7 | + |
| 8 | +export MAMBA_VERSION=0.19.1 |
| 9 | +export CONDA_VERSION=4.11.0 |
| 10 | + |
| 11 | +URL="https://anaconda.org/conda-forge/micromamba/${MAMBA_VERSION}/download/linux-64/micromamba-${MAMBA_VERSION}-0.tar.bz2" |
| 12 | + |
| 13 | +# make sure we don't do anything funky with user's $HOME |
| 14 | +# since this is run as root |
| 15 | +unset HOME |
| 16 | +mkdir -p ${CONDA_DIR} |
| 17 | + |
| 18 | +time wget -qO- ${URL} | tar -xvj bin/micromamba |
| 19 | +chmod 0755 /tmp/bin/micromamba |
| 20 | + |
| 21 | +export MAMBA_ROOT_PREFIX=${CONDA_DIR} |
| 22 | +export MAMBA_EXE="/tmp/bin/micromamba" |
| 23 | + |
| 24 | +eval "$(/tmp/bin/micromamba shell hook -p ${CONDA_DIR} -s posix)" |
| 25 | + |
| 26 | +micromamba activate |
| 27 | + |
| 28 | +export PATH="${PWD}/bin:$PATH" |
| 29 | + |
| 30 | +cat <<EOT >> ${CONDA_DIR}/.condarc |
| 31 | +channels: |
| 32 | + - conda-forge |
| 33 | + - defaults |
| 34 | +auto_update_conda: false |
| 35 | +show_channel_urls: true |
| 36 | +update_dependencies: false |
| 37 | +# channel_priority: flexible |
| 38 | +EOT |
| 39 | + |
| 40 | +micromamba install conda=${CONDA_VERSION} mamba=${MAMBA_VERSION} -y |
| 41 | + |
| 42 | +echo "installing notebook env:" |
| 43 | +cat "${NB_ENVIRONMENT_FILE}" |
| 44 | + |
| 45 | + |
| 46 | +time micromamba create -p ${NB_PYTHON_PREFIX} -f "${NB_ENVIRONMENT_FILE}" |
| 47 | + |
| 48 | +if [[ ! -z "${NB_REQUIREMENTS_FILE:-}" ]]; then |
| 49 | + echo "installing pip requirements" |
| 50 | + cat "${NB_REQUIREMENTS_FILE}" |
| 51 | + ${NB_PYTHON_PREFIX}/bin/python -mpip install --no-cache --no-deps -r "${NB_REQUIREMENTS_FILE}" |
| 52 | +fi |
| 53 | +# empty conda history file, |
| 54 | +# which seems to result in some effective pinning of packages in the initial env, |
| 55 | +# which we don't intend. |
| 56 | +# this file must not be *removed*, however |
| 57 | +echo '' > ${NB_PYTHON_PREFIX}/conda-meta/history |
| 58 | + |
| 59 | +if [[ ! -z "${KERNEL_ENVIRONMENT_FILE:-}" ]]; then |
| 60 | + # install kernel env and register kernelspec |
| 61 | + echo "installing kernel env:" |
| 62 | + cat "${KERNEL_ENVIRONMENT_FILE}" |
| 63 | + time micromamba create -p ${KERNEL_PYTHON_PREFIX} -f "${KERNEL_ENVIRONMENT_FILE}" |
| 64 | + |
| 65 | + if [[ ! -z "${KERNEL_REQUIREMENTS_FILE:-}" ]]; then |
| 66 | + echo "installing pip requirements for kernel" |
| 67 | + cat "${KERNEL_REQUIREMENTS_FILE}" |
| 68 | + ${KERNEL_PYTHON_PREFIX}/bin/python -mpip install --no-cache --no-deps -r "${KERNEL_REQUIREMENTS_FILE}" |
| 69 | + fi |
| 70 | + |
| 71 | + ${KERNEL_PYTHON_PREFIX}/bin/ipython kernel install --prefix "${NB_PYTHON_PREFIX}" |
| 72 | + echo '' > ${KERNEL_PYTHON_PREFIX}/conda-meta/history |
| 73 | + micromamba list -p ${KERNEL_PYTHON_PREFIX} |
| 74 | +fi |
| 75 | + |
| 76 | +# Clean things out! |
| 77 | +time micromamba clean --all -y |
| 78 | + |
| 79 | +# Remove the pip cache created as part of installing micromamba |
| 80 | +rm -rf /root/.cache |
| 81 | + |
| 82 | +chown -R $NB_USER:$NB_USER ${CONDA_DIR} |
| 83 | + |
| 84 | +micromamba list -p ${NB_PYTHON_PREFIX} |
| 85 | + |
| 86 | +# Set NPM config |
| 87 | +${NB_PYTHON_PREFIX}/bin/npm config --global set prefix ${NPM_DIR} |
0 commit comments