summaryrefslogtreecommitdiffstats
path: root/.gitlab/ci/docker/debian10/Dockerfile
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2023-02-06 23:54:07 (GMT)
committerBrad King <brad.king@kitware.com>2023-02-07 16:58:21 (GMT)
commitfc8335a17f14c2b8615b94303b732ae9b10d7a04 (patch)
tree8c8a9b99457733a33cf25485c6eb0f301ee86c1b /.gitlab/ci/docker/debian10/Dockerfile
parent26f962f8b1009587d101b8ede57e42e31c522b01 (diff)
downloadCMake-fc8335a17f14c2b8615b94303b732ae9b10d7a04.zip
CMake-fc8335a17f14c2b8615b94303b732ae9b10d7a04.tar.gz
CMake-fc8335a17f14c2b8615b94303b732ae9b10d7a04.tar.bz2
ci: Reduce Fedora and Debian image sizes even more
Apply the approach from commit 354fdf2116 (ci: Reduce intermediate docker layers and final image size, 2023-02-01) to more stages. Also: * Use cache (prefetch metadata and packages) to reduce network I/O and speedup image build. * Use `tmpfs` to drop logs produced by the package manager.
Diffstat (limited to '.gitlab/ci/docker/debian10/Dockerfile')
-rw-r--r--.gitlab/ci/docker/debian10/Dockerfile62
1 files changed, 50 insertions, 12 deletions
diff --git a/.gitlab/ci/docker/debian10/Dockerfile b/.gitlab/ci/docker/debian10/Dockerfile
index 2d3ae3a..d866428 100644
--- a/.gitlab/ci/docker/debian10/Dockerfile
+++ b/.gitlab/ci/docker/debian10/Dockerfile
@@ -1,20 +1,58 @@
-FROM debian:10 AS iwyu-build
-MAINTAINER Ben Boeckel <ben.boeckel@kitware.com>
+# syntax=docker/dockerfile:1
-COPY install_iwyu.sh /root/install_iwyu.sh
-RUN sh /root/install_iwyu.sh
+ARG BASE_IMAGE=debian:10
-FROM debian:10 AS rvm-build
-MAINTAINER Ben Boeckel <ben.boeckel@kitware.com>
+FROM ${BASE_IMAGE} AS apt-cache
+# Populate APT cache w/ the fresh metadata and prefetch packages.
+# Use an empty `docker-clean` file to "hide" the image-provided
+# file to disallow removing packages after `apt-get` operations.
+RUN --mount=type=tmpfs,target=/var/log \
+ --mount=type=bind,source=docker-clean,target=/etc/apt/apt.conf.d/docker-clean \
+ --mount=type=bind,source=deps_packages.lst,target=/root/deps_packages.lst \
+ --mount=type=bind,source=iwyu_packages.lst,target=/root/iwyu_packages.lst \
+ --mount=type=bind,source=rvm_packages.lst,target=/root/rvm_packages.lst \
+ apt-get update \
+ && apt-get --download-only -y install $(grep -h '^[^#]\+$' /root/*.lst)
-COPY install_rvm.sh /root/install_rvm.sh
-RUN sh /root/install_rvm.sh
-FROM debian:10
-MAINTAINER Ben Boeckel <ben.boeckel@kitware.com>
+FROM ${BASE_IMAGE} AS iwyu-build
+LABEL maintainer="Ben Boeckel <ben.boeckel@kitware.com>"
-COPY install_deps.sh /root/install_deps.sh
-RUN sh /root/install_deps.sh
+RUN --mount=type=bind,source=install_iwyu.sh,target=/root/install_iwyu.sh \
+ --mount=type=bind,source=iwyu_packages.lst,target=/root/iwyu_packages.lst \
+ --mount=type=bind,source=docker-clean,target=/etc/apt/apt.conf.d/docker-clean \
+ --mount=type=cache,from=apt-cache,source=/var/lib/apt/lists,target=/var/lib/apt/lists \
+ --mount=type=cache,from=apt-cache,source=/var/cache/apt,target=/var/cache/apt,sharing=private \
+ --mount=type=tmpfs,target=/var/log \
+ --mount=type=tmpfs,target=/tmp \
+ sh /root/install_iwyu.sh
+
+
+FROM ${BASE_IMAGE} AS rvm-build
+LABEL maintainer="Ben Boeckel <ben.boeckel@kitware.com>"
+
+RUN --mount=type=bind,source=install_rvm.sh,target=/root/install_rvm.sh \
+ --mount=type=bind,source=rvm_packages.lst,target=/root/rvm_packages.lst \
+ --mount=type=bind,source=docker-clean,target=/etc/apt/apt.conf.d/docker-clean \
+ --mount=type=cache,from=apt-cache,source=/var/lib/apt/lists,target=/var/lib/apt/lists \
+ --mount=type=cache,from=apt-cache,source=/var/cache/apt,target=/var/cache/apt,sharing=private \
+ --mount=type=tmpfs,target=/var/log \
+ --mount=type=tmpfs,target=/tmp \
+ sh /root/install_rvm.sh
+
+
+FROM ${BASE_IMAGE}
+LABEL maintainer="Ben Boeckel <ben.boeckel@kitware.com>"
+
+RUN --mount=type=bind,source=install_deps.sh,target=/root/install_deps.sh \
+ --mount=type=bind,source=deps_packages.lst,target=/root/deps_packages.lst \
+ --mount=type=bind,source=dpkg-exclude,target=/etc/dpkg/dpkg.cfg.d/exclude \
+ --mount=type=bind,source=docker-clean,target=/etc/apt/apt.conf.d/docker-clean \
+ --mount=type=cache,from=apt-cache,source=/var/lib/apt/lists,target=/var/lib/apt/lists \
+ --mount=type=cache,from=apt-cache,source=/var/cache/apt,target=/var/cache/apt,sharing=private \
+ --mount=type=tmpfs,target=/var/log \
+ --mount=type=tmpfs,target=/tmp \
+ sh /root/install_deps.sh
RUN --mount=type=bind,from=iwyu-build,source=/root,target=/root \
tar -C / -xf /root/iwyu.tar \