-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathNotebookImage.Dockerfile
70 lines (58 loc) · 3.21 KB
/
NotebookImage.Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
ARG python_version="3.11"
FROM quay.io/jupyter/minimal-notebook:python-${python_version}
ARG python_version
ARG arcgis_version="2.4.0"
ARG sampleslink="https://github.com/Esri/arcgis-python-api/releases/download/v${arcgis_version}/samples.zip"
ARG githubfolder="arcgis-python-api"
ARG env_name=arcgis
LABEL org.opencontainers.image.authors="jroebuck@esri.com"
LABEL org.opencontainers.image.description="Jupyter environment preconfigured for ArcGIS API for Python"
LABEL org.opencontainers.image.licenses=Apache
LABEL org.opencontainers.image.source=https://github.com/Esri/arcgis-python-api
USER ${NB_UID}
# Install Python API from Conda
RUN conda create -n ${env_name} -c esri -c defaults arcgis=${arcgis_version} python=${python_version} -y --quiet --override-channels \
&& conda clean --all -f -y \
&& find /opt/conda -name __pycache__ -type d -exec rm -rf {} +
# Install arcgis-mapping if arcgis_version >= 2.4.0
RUN (dpkg --compare-versions $arcgis_version ge 2.4.0 \
&& conda install -n ${env_name} -c esri -c defaults arcgis-mapping -y --quiet --override-channels \
&& conda clean --all -f -y \
&& find /opt/conda -name __pycache__ -type d -exec rm -rf {} +;) \
|| echo "[INFO] Skipped installing arcgis-mapping for version $arcgis_version (>= 2.4.0 required for arcgis-mapping)"
# Fetch and extract samples from GitHub
RUN mkdir /home/${NB_USER}/$githubfolder && \
wget -O samples.zip $sampleslink \
&& unzip -q samples.zip -d /home/${NB_USER}/$githubfolder \
&& rm samples.zip \
&& mv /home/${NB_USER}/$githubfolder/* ./ \
&& rm -rf $githubfolder/ \
apidoc/ \
work/ \
talks/ \
environment.yml\
# remove .DS_Store and __MACOSX from home directory:
&& find /home/${NB_USER} -name ".DS_Store" -delete \
&& rm -rf /home/${NB_USER}/__MACOSX \
&& fix-permissions /home/${NB_USER}
# See https://jupyter-docker-stacks.readthedocs.io/en/latest/using/recipes.html#add-a-custom-conda-environment-and-jupyter-kernel
# Create Python kernel and link it to jupyter
RUN "${CONDA_DIR}/envs/${env_name}/bin/python" -m ipykernel install --user --name="${env_name}" && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# More information here: https://github.com/jupyter/docker-stacks/pull/2047
USER root
# Set DOCKER_STACKS_JUPYTER_CMD to "notebook" for versions less than 2.4.0
RUN \
(dpkg --compare-versions $arcgis_version lt 2.4.0 \
&& echo 'DOCKER_STACKS_JUPYTER_CMD="notebook"' >> /etc/environment \
&& echo "[INFO] Set DOCKER_STACKS_JUPYTER_CMD to notebook for arcgis < 2.4.0") \
|| echo "[INFO] Using default DOCKER_STACKS_JUPYTER_CMD (lab) for arcgis >= 2.4.0"
RUN \
# This changes a startup hook, which will activate the custom environment for the process
echo conda activate "${env_name}" >> /usr/local/bin/before-notebook.d/10activate-conda-env.sh && \
# This makes the custom environment default in Jupyter Terminals for all users which might be created later
echo conda activate "${env_name}" >> /etc/skel/.bashrc && \
# This makes the custom environment default in Jupyter Terminals for already existing NB_USER
echo conda activate "${env_name}" >> "/home/${NB_USER}/.bashrc"
USER ${NB_UID}