Skip to content

Commit

Permalink
Reduce the number of layers by one by combining RUN lines
Browse files Browse the repository at this point in the history
Uses the new HEREDOC syntax supported by the more recent dockerfile
version.
  • Loading branch information
bloodearnest committed Oct 22, 2024
1 parent e957cb3 commit 588beb1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ LABEL org.opencontainers.image.authors="[email protected]" \
org.opencontainers.image.vendor="OpenSAFELY" \
org.opencontainers.image.source="https://github.com/opensafely-core/base-docker"

# Disable automatic cache cleaning, and make `apt install` preserve caches.
# This implies we should always use RUN --mount=cache on apt installs
# Taken from docs: https://docs.docker.com/reference/dockerfile/#example-cache-apt-packages
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache

# useful utility for installing apt packages in the most space efficient way
# possible. It's worth it because this is the base image, and so any bloat
# here affects all our images. Plus, it's then available for downstream images
# to use.
COPY docker-apt-install.sh /root/docker-apt-install.sh

# install some base tools we want in all images
# caching from docs: https://docs.docker.com/reference/dockerfile/#example-cache-apt-packages
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
UPGRADE=yes /root/docker-apt-install.sh ca-certificates sysstat lsof net-tools tcpdump vim strace file
# Ccaching from docs: https://docs.docker.com/reference/dockerfile/#example-cache-apt-packages
# Enable full caching of apt packages and metadata, undoing the debian defaults.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF
rm -f /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
UPGRADE=yes /root/docker-apt-install.sh ca-certificates sysstat lsof net-tools tcpdump vim strace file
EOF


# record build info so downstream images know about the base image they were
# built from
Expand Down

0 comments on commit 588beb1

Please sign in to comment.