Skip to content

Commit 7580a30

Browse files
authored
Merge pull request #1182 from minrk/mount-wheels
mount wheels from build stage instead of copying them
2 parents 0f52247 + ed82b83 commit 7580a30

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

Dockerfile

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1+
# syntax = docker/dockerfile:1.3
12
ARG ALPINE_VERSION=3.15.0
2-
FROM alpine:${ALPINE_VERSION}
3+
FROM alpine:${ALPINE_VERSION} AS builder
34

45
RUN apk add --no-cache git python3 python3-dev py-pip build-base
56

7+
# set pip's cache directory using this environment variable, and use
8+
# ARG instead of ENV to ensure its only set when the image is built
9+
ARG PIP_CACHE_DIR=/tmp/pip-cache
10+
611
# build wheels in first image
712
ADD . /tmp/src
813
RUN cd /tmp/src && git clean -xfd && git status
9-
RUN mkdir /tmp/wheelhouse \
14+
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
15+
mkdir /tmp/wheelhouse \
1016
&& cd /tmp/wheelhouse \
1117
&& pip3 install wheel \
12-
&& pip3 wheel --no-cache-dir /tmp/src \
18+
&& pip3 wheel /tmp/src \
1319
&& ls -l /tmp/wheelhouse
1420

1521
FROM alpine:${ALPINE_VERSION}
1622

1723
# install python, git, bash, mercurial
1824
RUN apk add --no-cache git git-lfs python3 py-pip bash docker mercurial
1925

20-
# install hg-evolve (Mercurial extensions)
21-
RUN pip3 install hg-evolve --user --no-cache-dir
26+
# repeat ARG from above
27+
ARG PIP_CACHE_DIR=/tmp/pip-cache
2228

2329
# install repo2docker
24-
COPY --from=0 /tmp/wheelhouse /tmp/wheelhouse
25-
RUN pip3 install --no-cache-dir --ignore-installed --no-deps /tmp/wheelhouse/*.whl \
30+
# and hg-evolve (Mercurial extensions)
31+
# mount /tmp/wheelhouse from build stage
32+
# avoids extra layer when using COPY --from
33+
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
34+
--mount=type=cache,from=builder,source=/tmp/wheelhouse,target=/tmp/wheelhouse \
35+
pip3 install --ignore-installed --no-deps /tmp/wheelhouse/*.whl \
36+
&& pip3 install hg-evolve \
2637
&& pip3 list
2738

2839
# add git-credential helper

0 commit comments

Comments
 (0)