|
1 | 1 | # syntax=docker/dockerfile:1 |
2 | | -FROM redhat/ubi8:latest |
| 2 | +# Dockerfile to build environment and run ECCOv4 Python tutorials. |
| 3 | +# Adapted from pangeo/base-image. |
| 4 | +FROM ubuntu:22.04 |
3 | 5 |
|
4 | | -# clone repository and set up in container |
5 | | -RUN dnf update && dnf install git -y |
6 | | -RUN cd ~ && git clone https://github.com/ECCO-GROUP/ECCO-v4-Python-Tutorial.git |
7 | | -COPY ~/ECCO-v4-Python-Tutorial / |
| 6 | +ARG NB_USER |
| 7 | +ARG NB_UID |
8 | 8 |
|
9 | | -# expose port to be used later with Jupyterlab |
10 | | -EXPOSE 9889 |
| 9 | +# Setup environment to match variables set by repo2docker as much as possible |
| 10 | +# The name of the conda environment into which the requested packages are installed |
11 | 11 |
|
12 | | -# run jupyter set up script |
13 | | -CMD ["chmod", "755", "/ECCO-v4-Python-Tutorial/Cloud_Setup/jupyter_env_setup.sh"] |
14 | | -CMD ["/ECCO-v4-Python-Tutorial/Cloud_Setup/jupyter_env_setup.sh"] |
| 12 | +ENV CONDA_ENV=jupyter \ |
| 13 | + # Tell apt-get to not block installs by asking for interactive human input |
| 14 | + # Use /bin/bash as shell, not the default /bin/sh (arrow keys, etc don't work then) |
| 15 | + SHELL=/bin/bash \ |
| 16 | + # Setup locale to be UTF-8, avoiding gnarly hard to debug encoding errors |
| 17 | + LANG=C.UTF-8 \ |
| 18 | + LC_ALL=C.UTF-8 \ |
| 19 | + # Install conda in the same place repo2docker does |
| 20 | + CONDA_DIR=/srv/conda |
15 | 21 |
|
16 | | -## note: might have to work out how user can input Earthdata credentials when jupyter_env_setup.sh is run, and port number/password for jupyter_lab_start.sh |
17 | 22 |
|
18 | | -# run jupyter lab start script |
19 | | -CMD ["~/jupyter_lab_start.sh"] |
| 23 | +# All env vars that reference other env vars need to be in their own ENV block |
| 24 | +# Path to the python environment where the jupyter notebook packages are installed |
| 25 | +ENV NB_PYTHON_PREFIX=${CONDA_DIR}/envs/${CONDA_ENV} \ |
| 26 | + # Home directory of our non-root user |
| 27 | + HOME=/home/${NB_USER} |
| 28 | + |
| 29 | +# Add both our notebook env as well as default conda installation to $PATH |
| 30 | +# Thus, when we start a `python` process (for kernels, or notebooks, etc), |
| 31 | +# it loads the python in the notebook conda environment, as that comes |
| 32 | +# first here. |
| 33 | +ENV PATH=${NB_PYTHON_PREFIX}/bin:${CONDA_DIR}/bin:${PATH} |
| 34 | + |
| 35 | +# Ask dask to read config from ${CONDA_DIR}/etc rather than |
| 36 | +# the default of /etc, since the non-root user can write |
| 37 | +# to ${CONDA_DIR}/etc but not to /etc |
| 38 | +ENV DASK_ROOT_CONFIG=${CONDA_DIR}/etc |
| 39 | + |
| 40 | + |
| 41 | +RUN echo "Creating ${NB_USER} user..." \ |
| 42 | + # Create a group for the user to be part of, with gid same as uid |
| 43 | + && groupadd --gid ${NB_UID} ${NB_USER} \ |
| 44 | + # Create non-root user, with given gid, uid and create $HOME |
| 45 | + && useradd --create-home --gid ${NB_UID} --no-log-init --uid ${NB_UID} ${NB_USER} |
| 46 | + |
| 47 | +# Make sure that /srv is owned by non-root user, so we can install things there |
| 48 | +USER root |
| 49 | +RUN chown -R ${NB_USER}:${NB_USER} /srv |
| 50 | + |
| 51 | +# Run conda activate each time a bash shell starts, so users don't have to manually type conda activate |
| 52 | +# Note this is only read by shell, but not by the jupyter notebook - that relies |
| 53 | +# on us starting the correct `python` process, which we do by adding the notebook conda environment's |
| 54 | +# bin to PATH earlier ($NB_PYTHON_PREFIX/bin) |
| 55 | +RUN echo ". ${CONDA_DIR}/etc/profile.d/conda.sh ; conda activate ${CONDA_ENV}" > /etc/profile.d/init_conda.sh |
| 56 | + |
| 57 | +# Install basic apt packages |
| 58 | +RUN echo "Installing Apt-get packages..." \ |
| 59 | + && apt-get update --fix-missing > /dev/null \ |
| 60 | + && apt-get install -y apt-utils wget tmux zip tzdata > /dev/null \ |
| 61 | + && apt-get clean \ |
| 62 | + && rm -rf /var/lib/apt/lists/* |
| 63 | + |
| 64 | +# Add TZ configuration - https://github.com/PrefectHQ/prefect/issues/3061 |
| 65 | +ENV TZ=UTC |
| 66 | +# ======================== |
| 67 | + |
| 68 | +USER ${NB_USER} |
| 69 | +WORKDIR ${HOME} |
| 70 | + |
| 71 | +# Install latest mambaforge in ${CONDA_DIR} |
| 72 | +RUN echo "Installing Miniforge..." \ |
| 73 | + && URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(uname -m).sh" \ |
| 74 | + && wget --quiet ${URL} -O installer.sh \ |
| 75 | + && /bin/bash installer.sh -u -b -p ${CONDA_DIR} \ |
| 76 | + && rm installer.sh \ |
| 77 | + && mamba clean -afy \ |
| 78 | + # After installing the packages, we cleanup some unnecessary files |
| 79 | + # to try reduce image size - see https://jcristharif.com/conda-docker-tips.html |
| 80 | + # Although we explicitly do *not* delete .pyc files, as that seems to slow down startup |
| 81 | + # quite a bit unfortunately - see https://github.com/2i2c-org/infrastructure/issues/2047 |
| 82 | + && find ${CONDA_DIR} -follow -type f -name '*.a' -delete |
| 83 | + |
| 84 | + |
| 85 | +COPY --chown=${NB_USER}:${NB_USER} ./ECCO-v4-Python-Tutorial /home/${NB_USER}/ECCO-v4-Python-Tutorial |
| 86 | + |
| 87 | +RUN echo "Using environment.yml to create conda environment ${CONDA_ENV}" & \ |
| 88 | + mamba env create --name ${CONDA_ENV} \ |
| 89 | + -f ./ECCO-v4-Python-Tutorial/Docker/environment.yml |
| 90 | + |
| 91 | +EXPOSE 8888 |
| 92 | + |
| 93 | +# start jupyter lab inside the container |
| 94 | +ENTRYPOINT ["./ECCO-v4-Python-Tutorial/Docker/jupyter_lab_start_docker.sh"] |
0 commit comments