Debian Codegraph @

Dockerfile

raw
1 # An incomplete base Docker image for running JupyterHub
2 #
3 # Add your configuration to create a complete derivative Docker image.
4 #
5 # Include your configuration settings by starting with one of two options:
6 #
7 # Option 1:
8 #
9 # FROM quay.io/jupyterhub/jupyterhub:latest
10 #
11 # And put your configuration file jupyterhub_config.py in /srv/jupyterhub/jupyterhub_config.py.
12 #
13 # Option 2:
14 #
15 # Or you can create your jupyterhub config and database on the host machine, and mount it with:
16 #
17 # docker run -v $PWD:/srv/jupyterhub -t quay.io/jupyterhub/jupyterhub
18 #
19 # NOTE
20 # If you base on quay.io/jupyterhub/jupyterhub-onbuild
21 # your jupyterhub_config.py will be added automatically
22 # from your docker directory.
23
24 ######################################################################
25 # This Dockerfile uses multi-stage builds with optimisations to build
26 # the JupyterHub wheel on the native architecture only
27 # https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
28
29 ARG BASE_IMAGE=ubuntu:22.04
30
31
32 ######################################################################
33 # The JupyterHub wheel is pure Python so can be built for any platform
34 # on the native architecture (avoiding QEMU emulation)
35 FROM --platform=${BUILDPLATFORM:-linux/amd64} $BASE_IMAGE AS jupyterhub-builder
36
37 ENV DEBIAN_FRONTEND=noninteractive
38
39 # Don't clear apt cache, and don't combine RUN commands, so that cached layers can
40 # be reused in other stages
41
42 RUN apt-get update -qq \
43 && apt-get install -yqq --no-install-recommends \
44 build-essential \
45 ca-certificates \
46 curl \
47 git \
48 gnupg \
49 locales \
50 python3-dev \
51 python3-pip \
52 python3-pycurl \
53 python3-venv \
54 && python3 -m pip install --no-cache-dir --upgrade setuptools pip build wheel
55 # Ubuntu 22.04 comes with Nodejs 12 which is too old for building JupyterHub JS
56 # It's fine at runtime though (used only by configurable-http-proxy)
57 ARG NODE_MAJOR=20
58 RUN mkdir -p /etc/apt/keyrings \
59 && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
60 && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
61 && apt-get update \
62 && apt-get install -yqq --no-install-recommends \
63 nodejs
64
65 WORKDIR /src/jupyterhub
66 # copy everything except whats in .dockerignore, its a
67 # compromise between needing to rebuild and maintaining
68 # what needs to be part of the build
69 COPY . .
70
71 ARG PIP_CACHE_DIR=/tmp/pip-cache
72 RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
73 python3 -m build --wheel
74
75 # verify installed files
76 RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
77 python3 -m pip install ./dist/*.whl \
78 && cd ci \
79 && python3 check_installed_data.py
80
81 ######################################################################
82 # All other wheels required by JupyterHub, some are platform specific
83 FROM $BASE_IMAGE AS wheel-builder
84
85 ENV DEBIAN_FRONTEND=noninteractive
86
87 RUN apt-get update -qq \
88 && apt-get install -yqq --no-install-recommends \
89 build-essential \
90 ca-certificates \
91 curl \
92 locales \
93 python3-dev \
94 python3-pip \
95 python3-pycurl \
96 python3-venv \
97 && python3 -m pip install --no-cache-dir --upgrade setuptools pip build wheel
98
99 WORKDIR /src/jupyterhub
100
101 COPY --from=jupyterhub-builder /src/jupyterhub/dist/*.whl /src/jupyterhub/dist/
102 ARG PIP_CACHE_DIR=/tmp/pip-cache
103 RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
104 python3 -m pip wheel --wheel-dir wheelhouse dist/*.whl
105
106
107 ######################################################################
108 # The final JupyterHub image, platform specific
109 FROM $BASE_IMAGE AS jupyterhub
110
111 ENV DEBIAN_FRONTEND=noninteractive \
112 SHELL=/bin/bash \
113 LC_ALL=en_US.UTF-8 \
114 LANG=en_US.UTF-8 \
115 LANGUAGE=en_US.UTF-8 \
116 PYTHONDONTWRITEBYTECODE=1
117
118 EXPOSE 8000
119
120 LABEL maintainer="Jupyter Project <[email protected]>"
121 LABEL org.jupyter.service="jupyterhub"
122
123 WORKDIR /srv/jupyterhub
124
125 RUN apt-get update -qq \
126 && apt-get install -yqq --no-install-recommends \
127 ca-certificates \
128 curl \
129 gnupg \
130 locales \
131 python-is-python3 \
132 python3-pip \
133 python3-pycurl \
134 nodejs \
135 npm \
136 && locale-gen $LC_ALL \
137 && npm install -g configurable-http-proxy@^4.2.0 \
138 # clean cache and logs
139 && rm -rf /var/lib/apt/lists/* /var/log/* /var/tmp/* ~/.npm
140 # install the wheels we built in the previous stage
141 RUN --mount=type=cache,from=wheel-builder,source=/src/jupyterhub/wheelhouse,target=/tmp/wheelhouse \
142 # always make sure pip is up to date!
143 python3 -m pip install --no-compile --no-cache-dir --upgrade setuptools pip \
144 && python3 -m pip install --no-compile --no-cache-dir /tmp/wheelhouse/*
145
146 CMD ["jupyterhub"]