-
Notifications
You must be signed in to change notification settings - Fork 92
/
Dockerfile
147 lines (129 loc) · 5.56 KB
/
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
FROM ubuntu:20.04
# Master build file for pangeo images
# Run this section as root
# try to keep conda version in sync with repo2docker
# ========================
ENV CONDA_VERSION=4.9.2-5 \
CONDA_ENV=notebook \
NB_USER=jovyan \
NB_UID=1000 \
SHELL=/bin/bash \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
CONDA_DIR=/srv/conda
ENV NB_PYTHON_PREFIX=${CONDA_DIR}/envs/${CONDA_ENV} \
DASK_ROOT_CONFIG=${CONDA_DIR}/etc \
HOME=/home/${NB_USER} \
PATH=${CONDA_DIR}/bin:${PATH}
# required for prefect agent: https://github.com/PrefectHQ/prefect/issues/3061
ENV DEBIAN_FRONTEND=noninteractive
# Create jovyan user, permissions, add conda init to startup script
RUN echo "Creating ${NB_USER} user..." \
&& groupadd --gid ${NB_UID} ${NB_USER} \
&& useradd --create-home --gid ${NB_UID} --no-log-init --uid ${NB_UID} ${NB_USER} \
&& echo ". ${CONDA_DIR}/etc/profile.d/conda.sh ; conda activate ${CONDA_ENV}" > /etc/profile.d/init_conda.sh \
&& chown -R ${NB_USER}:${NB_USER} /srv
# SEE: https://github.com/phusion/baseimage-docker/issues/58
ARG DEBIAN_FRONTEND=noninteractive
RUN echo "Installing Apt-get packages..." \
&& apt-get update --fix-missing \
&& apt-get install -y apt-utils 2> /dev/null \
&& apt-get install -y wget zip tzdata \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# ========================
USER ${NB_USER}
WORKDIR ${HOME}
RUN echo "Installing Miniforge..." \
&& URL="https://github.com/conda-forge/miniforge/releases/download/${CONDA_VERSION}/Miniforge3-${CONDA_VERSION}-Linux-x86_64.sh" \
&& wget --quiet ${URL} -O miniconda.sh \
&& /bin/bash miniconda.sh -u -b -p ${CONDA_DIR} \
&& rm miniconda.sh \
&& conda install -y -c conda-forge mamba \
&& mamba clean -afy \
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.pyc' -delete
EXPOSE 8888
ENTRYPOINT ["/srv/start"]
#CMD ["jupyter", "notebook", "--ip", "0.0.0.0"]
# Only run these if used as a base image
# ----------------------
ONBUILD USER root
# FIXME (?): user and home folder is hardcoded for now
# FIXME (?): this line breaks the cache of all steps below
ONBUILD COPY --chown=jovyan:jovyan . /home/jovyan
ONBUILD RUN echo "Checking for 'binder' or '.binder' subfolder" \
; if [ -d binder ] ; then \
echo "Using 'binder/' build context" \
; elif [ -d .binder ] ; then \
echo "Using '.binder/' build context" \
; else \
echo "Using './' build context" \
; fi
ONBUILD ARG DEBIAN_FRONTEND=noninteractive
ONBUILD RUN echo "Checking for 'apt.txt'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "apt.txt" ; then \
apt-get update --fix-missing \
&& xargs -a apt.txt apt-get install -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
; fi
# Copy jupyter_notebook_config.py to /etc/jupyter
ONBUILD RUN echo "Checking for 'jupyter_notebook_config.py'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "jupyter_notebook_config.py" ; then \
mkdir -p /etc/jupyter \
&& cp jupyter_notebook_config.py /etc/jupyter \
; fi
ONBUILD USER ${NB_USER}
# Create "notebook" conda environment and dask labextensions
ONBUILD RUN echo "Checking for 'conda-linux-64.lock' or 'environment.yml'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "conda-linux-64.lock" ; then \
mamba create --name ${CONDA_ENV} --file conda-linux-64.lock \
; elif test -f "environment.yml" ; then \
mamba env create --name ${CONDA_ENV} -f environment.yml \
; else echo "No conda-linux-64.lock or environment.yml! *creating default env*" ; \
mamba create --name ${CONDA_ENV} pangeo-notebook \
; fi \
&& mamba clean -yaf \
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.pyc' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete \
&& find ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static -follow -type f -name '*.js' ! -name '*.min.js' -delete
# Install pip packages
# remove cache https://github.com/pypa/pip/pull/6391 ?
ONBUILD RUN echo "Checking for pip 'requirements.txt'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "requirements.txt" ; then \
${NB_PYTHON_PREFIX}/bin/pip install --no-cache-dir -r requirements.txt \
; fi
# Run postBuild script within "pangeo" environment
ONBUILD RUN echo "Checking for 'postBuild'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "postBuild" ; then \
export PATH=${NB_PYTHON_PREFIX}/bin:${PATH} \
&& chmod +x postBuild \
&& ./postBuild \
&& rm -rf /tmp/* \
&& rm -rf ${HOME}/.cache ${HOME}/.npm ${HOME}/.yarn \
&& rm -rf ${NB_PYTHON_PREFIX}/share/jupyter/lab/staging \
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.pyc' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete \
; fi
# Overwrite start entrypoint script if present
ONBUILD RUN echo "Checking for 'start'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "start" ; then \
chmod +x start \
&& cp start /srv/start \
; fi
# ----------------------