Skip to content

Commit 566e800

Browse files
authored
Merge pull request #1535 from consideRatio/pr/refactor-image
2 parents 13a1b5d + 9bf1418 commit 566e800

File tree

2 files changed

+42
-48
lines changed

2 files changed

+42
-48
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ jobs:
143143
- name: Use chartpress to create the helm chart
144144
if: matrix.test == 'helm'
145145
run: |
146+
export DOCKER_BUILDKIT=1
147+
146148
# Use chartpress to create the helm chart and build its images
147149
helm dependency update ./helm-chart/binderhub
148150
(cd helm-chart && chartpress)
Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,67 @@
1-
# We use a build stage to package binderhub and pycurl into a wheel which we
2-
# then install by itself in the final image which is relatively slimmed.
3-
ARG DIST=bullseye
1+
# syntax = docker/dockerfile:1.3
42

53

64
# The build stage
75
# ---------------
8-
FROM python:3.9-$DIST as build-stage
9-
# ARG DIST is defined again to be made available in this build stage's scope.
10-
# ref: https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
11-
ARG DIST
6+
#
7+
# NOTE: If the image version is updated, also update it in ci/refreeze!
8+
#
9+
FROM python:3.9-bullseye as build-stage
10+
WORKDIR /build-stage
1211

13-
# Install node as required to package binderhub to a wheel
14-
RUN echo "deb https://deb.nodesource.com/node_16.x $DIST main" > /etc/apt/sources.list.d/nodesource.list \
12+
# install node as required to build a binderhub wheel
13+
RUN echo "deb https://deb.nodesource.com/node_16.x bullseye main" > /etc/apt/sources.list.d/nodesource.list \
1514
&& curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
1615
RUN apt-get update \
1716
&& apt-get install --yes \
1817
nodejs \
1918
&& rm -rf /var/lib/apt/lists/*
2019

21-
# Copy the whole git repository to /tmp/binderhub
22-
COPY . /tmp/binderhub
23-
WORKDIR /tmp/binderhub
24-
25-
# Build the binderhub python library into a wheel and save it to the ./dist
26-
# folder. There are no pycurl or ruamel.yaml.clib wheels so we build our own in
27-
# the build stage.
28-
RUN python -mpip install build && python -mbuild --wheel .
29-
RUN pip wheel --wheel-dir ./dist \
20+
# build wheels to be mounted through a cache in the final stage
21+
ARG PIP_CACHE_DIR=/tmp/pip-cache
22+
COPY . .
23+
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
24+
pip install build \
25+
&& pip wheel \
26+
. \
3027
pycurl \
31-
ruamel.yaml.clib
28+
-r helm-chart/images/binderhub/requirements.txt
3229

33-
# We download tini from here were we have wget available.
34-
RUN ARCH=$(uname -m); \
35-
if [ "$ARCH" = x86_64 ]; then ARCH=amd64; fi; \
36-
if [ "$ARCH" = aarch64 ]; then ARCH=arm64; fi; \
37-
wget -qO /tini "https://github.com/krallin/tini/releases/download/v0.19.0/tini-$ARCH" \
38-
&& chmod +x /tini
3930

4031
# The final stage
4132
# ---------------
42-
FROM python:3.9-slim-$DIST
43-
WORKDIR /
33+
FROM python:3.9-slim-bullseye
4434

45-
# We use tini as an entrypoint to not loose track of SIGTERM signals as sent
46-
# before SIGKILL when "docker stop" or "kubectl delete pod" is run. By doing
47-
# that the pod can terminate very quickly.
48-
COPY --from=build-stage /tini /tini
35+
ENV PYTHONUNBUFFERED=1
36+
ENV DEBIAN_FRONTEND=noninteractive
4937

50-
# The slim version doesn't include git as required by binderhub
51-
# or libcurl required by pycurl
5238
RUN apt-get update \
39+
&& apt-get upgrade --yes \
5340
&& apt-get install --yes \
5441
git \
42+
# required by binderhub
5543
libcurl4 \
44+
# required by pycurl
45+
tini \
46+
# tini is used as an entrypoint to not loose track of SIGTERM
47+
# signals as sent before SIGKILL, for example when "docker stop"
48+
# or "kubectl delete pod" is run. By doing that the pod can
49+
# terminate very quickly.
5650
&& rm -rf /var/lib/apt/lists/*
5751

58-
# Copy the built wheels from the build-stage. Also copy the image
59-
# requirements.txt built from the binderhub package requirements.txt and the
60-
# requirements.in file using pip-compile.
61-
COPY --from=build-stage /tmp/binderhub/dist/*.whl pre-built-wheels/
62-
COPY helm-chart/images/binderhub/requirements.txt .
52+
# install wheels built in the build stage
53+
ARG PIP_CACHE_DIR=/tmp/pip-cache
54+
COPY helm-chart/images/binderhub/requirements.txt /tmp/requirements.txt
55+
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
56+
--mount=type=cache,from=build-stage,source=/build-stage,target=/tmp/wheels \
57+
pip install --find-links=/tmp/wheels/ \
58+
binderhub \
59+
pycurl \
60+
-r /tmp/requirements.txt
6361

64-
# Install pre-built wheels and the generated requirements.txt for the image.
65-
# make sure that imports work,
66-
# because wheels were built in the build-stage
67-
RUN pip install --no-cache-dir \
68-
pre-built-wheels/*.whl \
69-
-r requirements.txt \
70-
&& python3 -c "import pycurl, binderhub.app"
62+
# verify success of previous step
63+
RUN python -c "import pycurl, binderhub.app"
7164

72-
ENTRYPOINT ["/tini", "--", "python3", "-m", "binderhub"]
73-
CMD ["--config", "/etc/binderhub/config/binderhub_config.py"]
74-
ENV PYTHONUNBUFFERED=1
7565
EXPOSE 8585
66+
ENTRYPOINT ["tini", "--", "python", "-m", "binderhub"]
67+
CMD ["--config", "/etc/binderhub/config/binderhub_config.py"]

0 commit comments

Comments
 (0)