|
| 1 | +# syntax = docker/dockerfile:1.3 |
1 | 2 | ARG ALPINE_VERSION=3.15.0 |
2 | | -FROM alpine:${ALPINE_VERSION} |
| 3 | +FROM alpine:${ALPINE_VERSION} AS builder |
3 | 4 |
|
4 | 5 | RUN apk add --no-cache git python3 python3-dev py-pip build-base |
5 | 6 |
|
| 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 | + |
6 | 11 | # build wheels in first image |
7 | 12 | ADD . /tmp/src |
8 | 13 | 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 \ |
10 | 16 | && cd /tmp/wheelhouse \ |
11 | 17 | && pip3 install wheel \ |
12 | | - && pip3 wheel --no-cache-dir /tmp/src \ |
| 18 | + && pip3 wheel /tmp/src \ |
13 | 19 | && ls -l /tmp/wheelhouse |
14 | 20 |
|
15 | 21 | FROM alpine:${ALPINE_VERSION} |
16 | 22 |
|
17 | 23 | # install python, git, bash, mercurial |
18 | 24 | RUN apk add --no-cache git git-lfs python3 py-pip bash docker mercurial |
19 | 25 |
|
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 |
22 | 28 |
|
23 | 29 | # 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 \ |
26 | 37 | && pip3 list |
27 | 38 |
|
28 | 39 | # add git-credential helper |
|
0 commit comments