Skip to content

Commit 67b5fff

Browse files
committed
build our own singleuser-sample image
- start from python:3.9-bullseye-slim - uses pip-compile, just like hub - consolidate pip-compile refreeze into `ci/refreeze` (simplifies workflows, reduces duplication, and allows local calls) - get tini from apt
1 parent 4faa7aa commit 67b5fff

File tree

7 files changed

+421
-64
lines changed

7 files changed

+421
-64
lines changed

.github/workflows/watch-dependencies.yaml

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# - Watch multiple images tags referenced in values.yaml to match the latest
55
# image tag.
66
#
7-
# - Watch the jupyterhub pinning in images/hub/requirements.in to match the
7+
# - Watch the jupyterhub pinning in images/*/requirements.in to match the
88
# latest jupyterhub version available on PyPI, and if doing this, also
9-
# refreeze images/hub/requirements.txt.
9+
# refreeze images/*/requirements.txt.
1010
#
1111
# About environment: watch-dependencies
1212
#
@@ -20,9 +20,7 @@ name: Watch dependencies
2020
on:
2121
push:
2222
paths:
23-
- "images/hub/Dockerfile"
24-
- "images/hub/requirements.in"
25-
- "images/hub/requirements.txt"
23+
- "images/*/requirements.in"
2624
- ".github/workflows/watch-dependencies.yaml"
2725
branches: ["main"]
2826
schedule:
@@ -167,25 +165,14 @@ jobs:
167165
- name: Update pinned version of jupyterhub
168166
if: steps.local.outputs.version != steps.latest.outputs.version
169167
run: |
170-
sed --in-place 's/jupyterhub==${{ steps.local.outputs.version }}/jupyterhub==${{ steps.latest.outputs.version }}/g' images/hub/requirements.in
171-
sed --in-place 's/jupyterhub==${{ steps.local.outputs.version }}/jupyterhub==${{ steps.latest.outputs.version }}/g' images/singleuser-sample/requirements.txt
168+
for img in hub singleuser-sample; do
169+
sed --in-place 's/jupyterhub==${{ steps.local.outputs.version }}/jupyterhub==${{ steps.latest.outputs.version }}/g' images/$img/requirements.in
170+
done
172171
sed --in-place 's/appVersion: "${{ steps.local.outputs.version }}"/appVersion: "${{ steps.latest.outputs.version }}"/g' jupyterhub/Chart.yaml
173172
174-
- name: Refreeze images/hub/requirements.txt based on images/hub/requirements.in
173+
- name: Refreeze images/*/requirements.txt based on images/*/requirements.in
175174
if: steps.local.outputs.version != steps.latest.outputs.version
176-
# IMPORTANT: This run segment is duplicated in this workflow file across
177-
# two separate jobs, any update here should be made in the
178-
# other job as well.
179-
#
180-
run: |
181-
cd images/hub
182-
docker run --rm \
183-
--env=CUSTOM_COMPILE_COMMAND='Use the "Run workflow" button at https://github.com/jupyterhub/zero-to-jupyterhub-k8s/actions/workflows/watch-dependencies.yaml' \
184-
--volume=$PWD:/io \
185-
--workdir=/io \
186-
--user=root \
187-
python:3.9-bullseye \
188-
sh -c 'pip install pip-tools==6.* && pip-compile --upgrade'
175+
run: ci/refreeze
189176

190177
- name: git diff
191178
if: steps.local.outputs.version != steps.latest.outputs.version
@@ -219,28 +206,8 @@ jobs:
219206
steps:
220207
- uses: actions/checkout@v3
221208

222-
- name: Refreeze images/hub/requirements.txt based on images/hub/requirements.in
223-
# Because `pip-compile` resolves `requirements.txt` with the current
224-
# Python for the current platform, it should be run on the same Python
225-
# version and platform as our Dockerfile.
226-
#
227-
# Note that as of 2022-05-29, `pip-compile` has issues with `pycurl`,
228-
# but we workaround them by by omitting the `-slim` part from the image
229-
# in the command below.
230-
#
231-
# IMPORTANT: This run segment is duplicated in this workflow file across
232-
# two separate jobs, any update here should be made in the
233-
# other job as well.
234-
#
235-
run: |
236-
cd images/hub
237-
docker run --rm \
238-
--env=CUSTOM_COMPILE_COMMAND='Use the "Run workflow" button at https://github.com/jupyterhub/zero-to-jupyterhub-k8s/actions/workflows/watch-dependencies.yaml' \
239-
--volume=$PWD:/io \
240-
--workdir=/io \
241-
--user=root \
242-
python:3.9-bullseye \
243-
sh -c 'pip install pip-tools==6.* && pip-compile --upgrade'
209+
- name: Refreeze images/*/requirements.txt based on images/*/requirements.in
210+
run: ci/refreeze
244211

245212
- name: git diff
246213
run: git --no-pager diff --color=always

ci/refreeze

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -xeuo pipefail
3+
IMAGES=${1:-images/hub images/singleuser-sample}
4+
5+
# Because `pip-compile` resolves `requirements.txt` with the current
6+
# Python for the current platform, it should be run on the same Python
7+
# version and platform as our Dockerfile.
8+
9+
for img in ${IMAGES}; do
10+
pushd "$img"
11+
docker run --rm \
12+
--env=CUSTOM_COMPILE_COMMAND='Use the "Run workflow" button at https://github.com/jupyterhub/zero-to-jupyterhub-k8s/actions/workflows/watch-dependencies.yaml' \
13+
--volume="$PWD:/io" \
14+
--workdir=/io \
15+
--user=root \
16+
python:3.9-bullseye \
17+
sh -c 'pip install pip-tools==6.* && pip-compile --upgrade'
18+
popd
19+
done

images/hub/Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ RUN apt-get update && \
5454
libcurl4 \
5555
# requirement for using a local sqlite database
5656
sqlite3 \
57+
tini \
5758
&& rm -rf /var/lib/apt/lists/*
5859

59-
RUN if [ "$(uname -m)" = x86_64 ]; then ARCH=amd64; fi; \
60-
if [ "$(uname -m)" = aarch64 ]; then ARCH=arm64; fi; \
61-
curl -sSLo /tini "https://github.com/krallin/tini/releases/download/v0.19.0/tini-$ARCH" \
62-
&& chmod +x /tini
63-
6460
COPY --from=build-stage /build-stage/*.whl /tmp/pre-built-wheels/
6561
COPY requirements.txt /tmp/requirements.txt
6662
RUN pip install --no-cache-dir \
@@ -72,5 +68,5 @@ RUN chown ${NB_USER}:${NB_USER} /srv/jupyterhub
7268
USER ${NB_USER}
7369

7470
EXPOSE 8081
75-
ENTRYPOINT ["/tini", "--"]
71+
ENTRYPOINT ["tini", "--"]
7672
CMD ["jupyterhub", "--config", "/usr/local/etc/jupyterhub/jupyterhub_config.py"]

images/hub/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jinja2==3.1.2
5858
# via
5959
# jupyterhub
6060
# jupyterhub-kubespawner
61-
jsonschema==4.9.1
61+
jsonschema==4.11.0
6262
# via
6363
# jupyter-telemetry
6464
# oauthenticator
@@ -90,7 +90,7 @@ jupyterhub-nativeauthenticator==1.0.5
9090
# via -r requirements.in
9191
jupyterhub-tmpauthenticator==0.6
9292
# via -r requirements.in
93-
kubernetes-asyncio==24.2.0
93+
kubernetes-asyncio==24.2.1
9494
# via jupyterhub-kubespawner
9595
ldap3==2.9.1
9696
# via jupyterhub-ldapauthenticator

images/singleuser-sample/Dockerfile

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,61 @@
1-
FROM jupyter/base-notebook:latest
2-
# Built from... https://hub.docker.com/r/jupyter/base-notebook/
3-
# https://github.com/jupyter/docker-stacks/blob/HEAD/base-notebook/Dockerfile
4-
# Built from... Ubuntu 20.04
1+
# The build stage
2+
# ---------------
3+
FROM python:3.9-bullseye as build-stage
54

6-
# VULN_SCAN_TIME=2022-08-08_07:54:05
5+
# VULN_SCAN_TIME=
6+
7+
WORKDIR /build-stage
8+
9+
# Build wheels for packages that require gcc or other build dependencies and
10+
# lack wheels either for amd64 or aarch64.
11+
COPY requirements.txt requirements.txt
12+
RUN pip wheel -r requirements.txt
13+
14+
# The final stage
15+
# ---------------
16+
FROM python:3.9-slim-bullseye
17+
18+
# VULN_SCAN_TIME=
19+
20+
ENV DEBIAN_FRONTEND=noninteractive \
21+
LANG=en_US.UTF-8 \
22+
LC_ALL=en_US.UTF-8 \
23+
LANGUAGE=en_US.UTF-8 \
24+
NB_USER=jovyan \
25+
NB_UID=1000 \
26+
HOME=/home/jovyan
727

828
USER root
929
RUN apt-get update \
1030
&& apt-get upgrade -y \
1131
&& apt-get install -y --no-install-recommends \
32+
ca-certificates \
1233
dnsutils \
1334
git \
35+
locales \
1436
iputils-ping \
15-
&& rm -rf /var/lib/apt/lists/*
16-
USER $NB_USER
37+
tini \
38+
&& apt-get clean \
39+
&& rm -rf /var/lib/apt/lists/* \
40+
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
41+
&& locale-gen
1742

18-
COPY requirements.txt /tmp/requirements.txt
19-
RUN pip install --no-cache-dir \
20-
-r /tmp/requirements.txt
43+
COPY --from=build-stage /build-stage/*.whl /tmp/pre-built-wheels/
44+
RUN pip install --no-cache-dir /tmp/pre-built-wheels/*.whl
2145

2246
# nbgitpuller is installed in requirements.txt for demo purposes, and this
2347
# enables it to function.
2448
RUN jupyter serverextension enable --py nbgitpuller --sys-prefix
2549

2650
# conda/pip/apt install additional packages here, if desired.
51+
52+
RUN adduser --disabled-password \
53+
--gecos "Default user" \
54+
--uid ${NB_UID} \
55+
--home ${HOME} \
56+
--force-badname \
57+
${NB_USER}
58+
59+
USER $NB_USER
60+
61+
ENTRYPOINT ["tini", "--"]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is the input to requirements.txt,
2+
# which is a frozen version of this. To update
3+
# requirements.txt, use the "Run workflow" button at
4+
# https://github.com/jupyterhub/zero-to-jupyterhub-k8s/actions/workflows/watch-dependencies.yaml
5+
# that will also update the jupyterhub version if needed.
6+
# README.md file.
7+
8+
# JupyterHub itself, update this version pinning by running the workflow
9+
# mentioned above.
10+
jupyterhub==3.0.0b1
11+
12+
# UI
13+
jupyterlab
14+
nbclassic
15+
retrolab
16+
17+
# plugins
18+
nbgitpuller

0 commit comments

Comments
 (0)