Skip to content

Commit ebf242b

Browse files
authored
Merge pull request #2856 from minrk/smaller-simpler-layers
Mount wheels from build stage instead of copying
2 parents 52ad148 + c5adeae commit ebf242b

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252

5353
- run:
5454
command: |
55+
export DOCKER_BUILDKIT=1
5556
chartpress
5657
name: Run chartpress
5758

.github/workflows/test-chart.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ jobs:
247247
run: |
248248
pip3 install -r dev-requirements.txt
249249
chartpress
250+
env:
251+
DOCKER_BUILDKIT: "1"
250252

251253
# Generate values.schema.json from schema.yaml
252254
- name: Generate values.schema.json from schema.yaml

images/hub/Dockerfile

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax = docker/dockerfile:1.3
12
# The build stage
23
# ---------------
34
FROM python:3.9-bullseye as build-stage
@@ -6,21 +7,16 @@ FROM python:3.9-bullseye as build-stage
67

78
WORKDIR /build-stage
89

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 pip's cache directory using this environment variable, and use
11+
# ARG instead of ENV to ensure its only set when the image is built
12+
ARG PIP_CACHE_DIR=/tmp/pip-cache
13+
14+
# Build wheels
15+
# These are mounted into the final image for installation
2016
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
2420

2521

2622
# The final stage
@@ -30,6 +26,7 @@ FROM python:3.9-slim-bullseye
3026
ARG NB_USER=jovyan
3127
ARG NB_UID=1000
3228
ARG HOME=/home/jovyan
29+
3330
ENV DEBIAN_FRONTEND=noninteractive
3431

3532
RUN adduser --disabled-password \
@@ -56,10 +53,16 @@ RUN apt-get update && \
5653
tini \
5754
&& rm -rf /var/lib/apt/lists/*
5855

59-
COPY --from=build-stage /build-stage/*.whl /tmp/pre-built-wheels/
56+
# set pip's cache directory using this environment variable, and use
57+
# ARG instead of ENV to ensure its only set when the image is built
58+
ARG PIP_CACHE_DIR=/tmp/pip-cache
59+
60+
# install wheels built in the build-stage
6061
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/ \
6366
-r /tmp/requirements.txt
6467

6568
WORKDIR /srv/jupyterhub

images/singleuser-sample/Dockerfile

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax = docker/dockerfile:1.3
12
# The build stage
23
# ---------------
34
FROM python:3.9-bullseye as build-stage
@@ -6,21 +7,15 @@ FROM python:3.9-bullseye as build-stage
67

78
WORKDIR /build-stage
89

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/psutil/#files, no wheels available as of 5.9.1
13-
# for aarch64. See https://github.com/giampaolo/psutil/pull/2070.
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 pip's cache directory using this environment variable, and use
11+
# ARG instead of ENV to ensure its only set when the image is built
12+
ARG PIP_CACHE_DIR=/tmp/pip-cache
13+
14+
# These are mounted into the final image for installation
2015
COPY requirements.txt requirements.txt
21-
RUN pip install build \
22-
&& pip wheel \
23-
$(cat requirements.txt | grep "psutil==")
16+
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
17+
pip install build \
18+
&& pip wheel -r requirements.txt
2419

2520

2621
# The final stage
@@ -53,10 +48,16 @@ RUN apt-get update \
5348
git \
5449
&& rm -rf /var/lib/apt/lists/*
5550

56-
COPY --from=build-stage /build-stage/*.whl /tmp/pre-built-wheels/
51+
# set pip's cache directory using this environment variable, and use
52+
# ARG instead of ENV to ensure its only set when the image is built
53+
ARG PIP_CACHE_DIR=/tmp/pip-cache
54+
55+
# install wheels built in the build-stage
5756
COPY requirements.txt /tmp/requirements.txt
58-
RUN pip install --no-cache-dir \
59-
/tmp/pre-built-wheels/*.whl \
57+
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
58+
--mount=type=cache,from=build-stage,source=/build-stage,target=/tmp/wheels \
59+
pip install \
60+
--find-links=/tmp/wheels/ \
6061
-r /tmp/requirements.txt
6162

6263
WORKDIR ${HOME}

0 commit comments

Comments
 (0)