1
+ # syntax = docker/dockerfile:1.3
1
2
# The build stage
2
3
# ---------------
3
4
FROM python:3.9-bullseye as build-stage
@@ -6,21 +7,16 @@ FROM python:3.9-bullseye as build-stage
6
7
7
8
WORKDIR /build-stage
8
9
9
- # Build wheels for packages that require gcc or other build dependencies and
10
- # lack wheels either for amd64 or aarch64.
11
- #
12
- # - https://pypi.org/project/pycurl/#files, no wheels available as of 7.45.1.
13
- # See https://github.com/pycurl/pycurl/issues/738.
14
- #
15
- # If you find a dependency here no longer listed in requirements.txt, remove it
16
- # from here as well. The more wheels we build here and copy and then install,
17
- # where the copy and install are separate steps, the larger the final image
18
- # becomes.
19
- #
10
+ # set env for pip cache,
11
+ # but use ARG to avoid persisting in image
12
+ ARG PIP_CACHE_DIR=/tmp/pip-cache
13
+
14
+ # Build wheels
15
+ # These are mounted into the final image for installation
20
16
COPY requirements.txt requirements.txt
21
- RUN pip install build \
22
- && pip wheel \
23
- $(cat requirements.txt | grep "pycurl==" )
17
+ RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
18
+ pip install build \
19
+ && pip wheel -r requirements.txt
24
20
25
21
26
22
# The final stage
@@ -30,6 +26,7 @@ FROM python:3.9-slim-bullseye
30
26
ARG NB_USER=jovyan
31
27
ARG NB_UID=1000
32
28
ARG HOME=/home/jovyan
29
+
33
30
ENV DEBIAN_FRONTEND=noninteractive
34
31
35
32
RUN adduser --disabled-password \
@@ -56,10 +53,16 @@ RUN apt-get update && \
56
53
tini \
57
54
&& rm -rf /var/lib/apt/lists/*
58
55
59
- COPY --from=build-stage /build-stage/*.whl /tmp/pre-built-wheels/
56
+ # set env for pip cache,
57
+ # but use ARG to avoid persisting in image
58
+ ARG PIP_CACHE_DIR=/tmp/pip-cache
59
+
60
+ # install wheels built in the build-stage
60
61
COPY requirements.txt /tmp/requirements.txt
61
- RUN pip install --no-cache-dir \
62
- /tmp/pre-built-wheels/*.whl \
62
+ RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
63
+ --mount=type=cache,from=build-stage,source=/build-stage,target=/tmp/wheels \
64
+ pip install \
65
+ --find-links /tmp/wheels/ \
63
66
-r /tmp/requirements.txt
64
67
65
68
WORKDIR /srv/jupyterhub
0 commit comments