|
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 |
4 | 2 |
|
5 | 3 |
|
6 | 4 | # The build stage |
7 | 5 | # --------------- |
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 |
12 | 11 |
|
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 \ |
15 | 14 | && curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - |
16 | 15 | RUN apt-get update \ |
17 | 16 | && apt-get install --yes \ |
18 | 17 | nodejs \ |
19 | 18 | && rm -rf /var/lib/apt/lists/* |
20 | 19 |
|
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 | + . \ |
30 | 27 | pycurl \ |
31 | | - ruamel.yaml.clib |
| 28 | + -r helm-chart/images/binderhub/requirements.txt |
32 | 29 |
|
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 |
39 | 30 |
|
40 | 31 | # The final stage |
41 | 32 | # --------------- |
42 | | -FROM python:3.9-slim-$DIST |
43 | | -WORKDIR / |
| 33 | +FROM python:3.9-slim-bullseye |
44 | 34 |
|
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 |
49 | 37 |
|
50 | | -# The slim version doesn't include git as required by binderhub |
51 | | -# or libcurl required by pycurl |
52 | 38 | RUN apt-get update \ |
| 39 | + && apt-get upgrade --yes \ |
53 | 40 | && apt-get install --yes \ |
54 | 41 | git \ |
| 42 | + # required by binderhub |
55 | 43 | 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. |
56 | 50 | && rm -rf /var/lib/apt/lists/* |
57 | 51 |
|
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 |
63 | 61 |
|
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" |
71 | 64 |
|
72 | | -ENTRYPOINT ["/tini", "--", "python3", "-m", "binderhub"] |
73 | | -CMD ["--config", "/etc/binderhub/config/binderhub_config.py"] |
74 | | -ENV PYTHONUNBUFFERED=1 |
75 | 65 | EXPOSE 8585 |
| 66 | +ENTRYPOINT ["tini", "--", "python", "-m", "binderhub"] |
| 67 | +CMD ["--config", "/etc/binderhub/config/binderhub_config.py"] |
0 commit comments