1
0
Fork 0

container: Optimize layer cache usage

With the addition of ancillary scripts like `entrypoint.sh`, the `COPY .`
instruction in the build stage results in a full rebuild of the final
image for every change.  To avoid this, we now only copy the files that
are actually required to build the wheel.  The other scripts are copied
later, using an intermediate layer.  This avoids needing a `COPY`
instruction, and therefore a new layer in the final image, for each
script.  Hypothetically, we could use `RUN --mount=bind` and copy the
files with the `install` command, but bind-mounting the build context
doesn't actually work; SELinux prevents the container builder from
accessing the source directory directly.
master
Dustin 2024-07-11 20:19:44 -05:00
parent 76cb7c7958
commit e4742f1c6e
1 changed files with 12 additions and 3 deletions

View File

@ -18,10 +18,19 @@ RUN --mount=type=cache,target=/var/cache \
python3-wheel \ python3-wheel \
&& : && :
COPY . /src COPY .git /src/.git
COPY xactfetch.py pyproject.toml /src
RUN python3 -m pip wheel -w /wheels /src RUN python3 -m pip wheel -w /wheels /src
FROM scratch AS mixin
COPY pinentry-stub.sh /usr/local/bin/pinentry-stub
COPY entrypoint.sh /entrypoint.sh
FROM git.pyrocufflink.net/containerimages/dch-base FROM git.pyrocufflink.net/containerimages/dch-base
RUN --mount=type=cache,target=/var/cache \ RUN --mount=type=cache,target=/var/cache \
@ -66,11 +75,11 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/usr/local/playwright/browsers
RUN --mount=type=bind,from=build,source=/,target=/build \ RUN --mount=type=bind,from=build,source=/,target=/build \
python3 -m pip install --no-index -f /build/wheels xactfetch \ python3 -m pip install --no-index -f /build/wheels xactfetch \
&& cp /build/root/.cargo/bin/rbw* /usr/local/bin/ \ && cp /build/root/.cargo/bin/rbw* /usr/local/bin/ \
&& install /build/src/pinentry-stub.sh /usr/local/bin/pinentry-stub \
&& install /build/src/entrypoint.sh /entrypoint.sh \
&& playwright install chromium \ && playwright install chromium \
&& : && :
COPY --from=mixin / /
VOLUME /var/lib/xactfetch VOLUME /var/lib/xactfetch
WORKDIR /var/lib/xactfetch WORKDIR /var/lib/xactfetch