[igt-dev] [PATCH] .gitlab-ci: Reduce Docker images size

Ramotowski, Maciej maciej.ramotowski at intel.com
Wed Mar 18 06:29:03 UTC 2020


Make Dockerfile's more universal.

Reduce size of Ubuntu based images by removing package lists.

Add support for building with build cache and without --squash flag:

 - Using apt-get update alone in a RUN statement causes caching issues
   and subsequent apt-get install instructions fail.

 - When you run an image and generate a container, you add a new
   writable layer (the “container layer”) on top of the underlying
   layers. All changes made to the running container, such as writing
   new files, modifying existing files, and deleting files, are written
   to this thin  writable container layer.

Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
Cc: Petri Latvala <petri.latvala at intel.com>
Signed-off-by: Maciej Ramotowski <maciej.ramotowski at intel.com>
---
 Dockerfile.build-debian         | 39 +++++++---------
 Dockerfile.build-debian-arm64   | 68 ++++++++++++---------------
 Dockerfile.build-debian-armhf   | 67 ++++++++++++--------------
 Dockerfile.build-debian-minimal | 44 +++++++++--------
 Dockerfile.build-debian-mips    | 70 +++++++++++++--------------
 Dockerfile.build-fedora         | 83 ++++++++++++++++-----------------
 6 files changed, 172 insertions(+), 199 deletions(-)

diff --git a/Dockerfile.build-debian b/Dockerfile.build-debian
index b143a532..6cf7a1f0 100644
--- a/Dockerfile.build-debian
+++ b/Dockerfile.build-debian
@@ -7,25 +7,20 @@ FROM $CI_REGISTRY_IMAGE/build-debian-minimal:commit-$CI_COMMIT_SHA
 # just few extra dependencies for building IGT with all the optional components
 # enabled
 
-RUN apt-get update
-RUN apt-get install -y \
-			libunwind-dev \
-			libgsl-dev \
-			libasound2-dev \
-			libxmlrpc-core-c3-dev \
-			libjson-c-dev \
-			libcurl4-openssl-dev \
-			python-docutils \
-			valgrind \
-			peg \
-			libdrm-intel1
-
-# autotools build deps
-RUN apt-get install -y \
-			autoconf \
-			automake \
-			xutils-dev \
-			libtool \
-			make
-
-RUN apt-get clean
+RUN apt-get update && apt-get install -y \
+    autoconf \
+    automake \
+    libasound2-dev \
+    libcurl4-openssl-dev \
+    libdrm-intel1 \
+    libgsl-dev \
+    libjson-c-dev \
+    libtool \
+    libunwind-dev \
+    libxmlrpc-core-c3-dev \
+    make \
+    peg \
+    python-docutils \
+    valgrind \
+    xutils-dev \
+ && rm -rf /var/lib/apt/lists/*
diff --git a/Dockerfile.build-debian-arm64 b/Dockerfile.build-debian-arm64
index 573c7096..924432bd 100644
--- a/Dockerfile.build-debian-arm64
+++ b/Dockerfile.build-debian-arm64
@@ -1,40 +1,34 @@
 FROM debian:buster
 
-RUN apt-get update
-RUN apt-get install -y \
-			flex \
-			bison \
-			pkg-config \
-			x11proto-dri2-dev \
-			python-docutils \
-			valgrind \
-			peg
-
 RUN dpkg --add-architecture arm64
-RUN apt-get update
-RUN apt-get install -y \
-			gcc-aarch64-linux-gnu \
-			libatomic1:arm64 \
-			libpciaccess-dev:arm64 \
-			libkmod-dev:arm64 \
-			libprocps-dev:arm64 \
-			libunwind-dev:arm64 \
-			libdw-dev:arm64 \
-			zlib1g-dev:arm64 \
-			liblzma-dev:arm64 \
-			libcairo-dev:arm64 \
-			libpixman-1-dev:arm64 \
-			libudev-dev:arm64 \
-			libgsl-dev:arm64 \
-			libasound2-dev:arm64 \
-			libjson-c-dev:arm64 \
-			libcurl4-openssl-dev:arm64 \
-			libxrandr-dev:arm64 \
-			libxv-dev:arm64 \
-			meson \
-			libdrm-dev:arm64 \
-			qemu-user \
-			qemu-user-static
-
-
-RUN apt-get clean
+RUN apt-get update && apt-get install -y \
+    bison \
+    flex \
+    gcc-aarch64-linux-gnu \
+    libasound2-dev:arm64 \
+    libatomic1:arm64 \
+    libcairo-dev:arm64 \
+    libcurl4-openssl-dev:arm64 \
+    libdrm-dev:arm64 \
+    libdw-dev:arm64 \
+    libgsl-dev:arm64 \
+    libjson-c-dev:arm64 \
+    libkmod-dev:arm64 \
+    liblzma-dev:arm64 \
+    libpciaccess-dev:arm64 \
+    libpixman-1-dev:arm64 \
+    libprocps-dev:arm64 \
+    libudev-dev:arm64 \
+    libunwind-dev:arm64 \
+    libxrandr-dev:arm64 \
+    libxv-dev:arm64 \
+    meson \
+    peg \
+    pkg-config \
+    python-docutils \
+    qemu-user \
+    qemu-user-static \
+    valgrind \
+    x11proto-dri2-dev \
+    zlib1g-dev:arm64 \
+ && rm -rf /var/lib/apt/lists/*
diff --git a/Dockerfile.build-debian-armhf b/Dockerfile.build-debian-armhf
index 737ca364..3752dc91 100644
--- a/Dockerfile.build-debian-armhf
+++ b/Dockerfile.build-debian-armhf
@@ -1,39 +1,34 @@
 FROM debian:buster
 
-RUN apt-get update
-RUN apt-get install -y \
-			flex \
-			bison \
-			pkg-config \
-			x11proto-dri2-dev \
-			python-docutils \
-			valgrind \
-			peg
-
 RUN dpkg --add-architecture armhf
-RUN apt-get update
-RUN apt-get install -y \
-			gcc-arm-linux-gnueabihf \
-			libatomic1:armhf \
-			libpciaccess-dev:armhf \
-			libkmod-dev:armhf \
-			libprocps-dev:armhf \
-			libunwind-dev:armhf \
-			libdw-dev:armhf \
-			zlib1g-dev:armhf \
-			liblzma-dev:armhf \
-			libcairo-dev:armhf \
-			libpixman-1-dev:armhf \
-			libudev-dev:armhf \
-			libgsl-dev:armhf \
-			libasound2-dev:armhf \
-			libjson-c-dev:armhf \
-			libcurl4-openssl-dev:armhf \
-			libxrandr-dev:armhf \
-			libxv-dev:armhf \
-			meson \
-			libdrm-dev:armhf \
-			qemu-user \
-			qemu-user-static
-
-RUN apt-get clean
+RUN apt-get update && apt-get install -y \
+    bison \
+    flex \
+    gcc-arm-linux-gnueabihf \
+    libasound2-dev:armhf \
+    libatomic1:armhf \
+    libcairo-dev:armhf \
+    libcurl4-openssl-dev:armhf \
+    libdrm-dev:armhf \
+    libdw-dev:armhf \
+    libgsl-dev:armhf \
+    libjson-c-dev:armhf \
+    libkmod-dev:armhf \
+    liblzma-dev:armhf \
+    libpciaccess-dev:armhf \
+    libpixman-1-dev:armhf \
+    libprocps-dev:armhf \
+    libudev-dev:armhf \
+    libunwind-dev:armhf \
+    libxrandr-dev:armhf \
+    libxv-dev:armhf \
+    meson \
+    peg \
+    pkg-config \
+    python-docutils \
+    qemu-user \
+    qemu-user-static \
+    valgrind \
+    x11proto-dri2-dev \
+    zlib1g-dev:armhf \
+ && rm -rf /var/lib/apt/lists/*
diff --git a/Dockerfile.build-debian-minimal b/Dockerfile.build-debian-minimal
index 64edf4b4..d0756be5 100644
--- a/Dockerfile.build-debian-minimal
+++ b/Dockerfile.build-debian-minimal
@@ -1,25 +1,23 @@
 FROM debian:buster
 
-RUN apt-get update
-RUN apt-get install -y \
-			gcc \
-			flex \
-			bison \
-			pkg-config \
-			libatomic1 \
-			libpciaccess-dev \
-			libkmod-dev \
-			libprocps-dev \
-			libdw-dev \
-			zlib1g-dev \
-			liblzma-dev \
-			libcairo-dev \
-			libpixman-1-dev \
-			libudev-dev \
-			libxrandr-dev \
-			libxv-dev \
-			x11proto-dri2-dev \
-			meson \
-			libdrm-dev
-
-RUN apt-get clean
+RUN apt-get update && apt-get install -y \
+    bison \
+    flex \
+    gcc \
+    libatomic1 \
+    libcairo-dev \
+    libdrm-dev \
+    libdw-dev \
+    libkmod-dev \
+    liblzma-dev \
+    libpciaccess-dev \
+    libpixman-1-dev \
+    libprocps-dev \
+    libudev-dev \
+    libxrandr-dev \
+    libxv-dev \
+    meson \
+    pkg-config \
+    x11proto-dri2-dev \
+    zlib1g-dev \
+ && rm -rf /var/lib/apt/lists/*
diff --git a/Dockerfile.build-debian-mips b/Dockerfile.build-debian-mips
index 7e4bacdf..e52d403b 100644
--- a/Dockerfile.build-debian-mips
+++ b/Dockerfile.build-debian-mips
@@ -2,42 +2,36 @@
 # https://bugs.debian.org/932725
 FROM debian:stretch-backports
 
-RUN apt-get update
-RUN apt-get install -y \
-			flex \
-			bison \
-			pkg-config \
-			x11proto-dri2-dev \
-			python-docutils \
-			valgrind \
-			peg
-
 RUN dpkg --add-architecture mips
-RUN apt-get update
-RUN apt-get install -y \
-			gcc-mips-linux-gnu \
-			libatomic1:mips \
-			libpciaccess-dev:mips \
-			libkmod-dev:mips \
-			libprocps-dev:mips \
-			libunwind-dev:mips \
-			libdw-dev:mips \
-			zlib1g-dev:mips \
-			liblzma-dev:mips \
-			libcairo-dev:mips \
-			libpixman-1-dev:mips \
-			libudev-dev:mips \
-			libgsl-dev:mips \
-			libasound2-dev:mips \
-			libjson-c-dev:mips \
-			libcurl4-openssl-dev:mips \
-			libxrandr-dev:mips \
-			libxv-dev:mips
-
-RUN apt-get install -t stretch-backports -y \
-			meson \
-			libdrm-dev:mips \
-			qemu-user \
-			qemu-user-static
-
-RUN apt-get clean
+RUN apt-get update && apt-get install -y \
+    bison \
+    flex \
+    gcc-mips-linux-gnu \
+    libasound2-dev:mips \
+    libatomic1:mips \
+    libcairo-dev:mips \
+    libcurl4-openssl-dev:mips \
+    libdw-dev:mips \
+    libgsl-dev:mips \
+    libjson-c-dev:mips \
+    libkmod-dev:mips \
+    liblzma-dev:mips \
+    libpciaccess-dev:mips \
+    libpixman-1-dev:mips \
+    libprocps-dev:mips \
+    libudev-dev:mips \
+    libunwind-dev:mips \
+    libxrandr-dev:mips \
+    libxv-dev:mips \
+    peg \
+    pkg-config \
+    python-docutils \
+    valgrind \
+    x11proto-dri2-dev \
+    zlib1g-dev:mips \
+ && apt-get install -t stretch-backports -y \
+    libdrm-dev:mips \
+    meson \
+    qemu-user \
+    qemu-user-static \
+ && rm -rf /var/lib/apt/lists/*
diff --git a/Dockerfile.build-fedora b/Dockerfile.build-fedora
index dc5d1b16..34fff96b 100644
--- a/Dockerfile.build-fedora
+++ b/Dockerfile.build-fedora
@@ -1,50 +1,47 @@
 FROM fedora:31
 
 RUN dnf install -y \
-	gcc flex bison libatomic meson ninja-build xdotool \
-	'pkgconfig(libdrm)' \
-	'pkgconfig(pciaccess)' \
-	'pkgconfig(libkmod)' \
-	'pkgconfig(libprocps)' \
-	'pkgconfig(libunwind)' \
-	'pkgconfig(libdw)' \
-	'pkgconfig(pixman-1)' \
-	'pkgconfig(valgrind)' \
-	'pkgconfig(cairo)' \
-	'pkgconfig(libudev)' \
-	'pkgconfig(glib-2.0)' \
-	'pkgconfig(gsl)' \
-	'pkgconfig(alsa)' \
-	'pkgconfig(xmlrpc)' \
-	'pkgconfig(xmlrpc_util)' \
-	'pkgconfig(xmlrpc_client)' \
-	'pkgconfig(json-c)' \
-	'pkgconfig(gtk-doc)' \
-	'pkgconfig(xv)' \
-	'pkgconfig(xrandr)' \
-	python3-docutils
-
-# We need peg to build overlay
-RUN dnf install -y make
-RUN mkdir /tmp/peg
+    'pkgconfig(alsa)' \
+    'pkgconfig(cairo)' \
+    'pkgconfig(glib-2.0)' \
+    'pkgconfig(gsl)' \
+    'pkgconfig(gtk-doc)' \
+    'pkgconfig(json-c)' \
+    'pkgconfig(libdrm)' \
+    'pkgconfig(libdw)' \
+    'pkgconfig(libkmod)' \
+    'pkgconfig(libprocps)' \
+    'pkgconfig(libudev)' \
+    'pkgconfig(libunwind)' \
+    'pkgconfig(pciaccess)' \
+    'pkgconfig(pixman-1)' \
+    'pkgconfig(valgrind)' \
+    'pkgconfig(xmlrpc)' \
+    'pkgconfig(xmlrpc_client)' \
+    'pkgconfig(xmlrpc_util)' \
+    'pkgconfig(xrandr)' \
+    'pkgconfig(xv)' \
+    bison \
+    clang \
+    diffutils \
+    findutils \
+    flex \
+    gcc \
+    libatomic \
+    make \
+    meson \
+    ninja-build \
+    python3-docutils \
+    python3-pip \
+    xdotool \
+ && dnf clean all
 
 # originaly from http://piumarta.com/software/peg/
-RUN curl -o "/tmp/peg/#1" "https://intel-gfx-ci.01.org/mirror/peg/{peg-0.1.18.tar.gz}"
-RUN tar -C /tmp/peg -xf /tmp/peg/peg-0.1.18.tar.gz
-RUN make -C /tmp/peg/peg-0.1.18 PREFIX=/usr install
-RUN rm -fr /tmp/peg
-
-# For compile-testing on clang
-RUN dnf install -y clang
-
-# For test list comparison
-RUN dnf install -y diffutils
+RUN mkdir /tmp/peg \
+ && curl -o "/tmp/peg/#1" "https://intel-gfx-ci.01.org/mirror/peg/{peg-0.1.18.tar.gz}" \
+ && tar -C /tmp/peg -xf /tmp/peg/peg-0.1.18.tar.gz \
+ && ls /tmp/peg \
+ && make -C /tmp/peg/peg-0.1.18 PREFIX=/usr install \
+ && rm -fr /tmp/peg
 
-# For the helpers for the container with IGT inside
-RUN dnf install -y findutils
-
-# Meson version switching shenanigans
-RUN dnf install -y python3-pip
 RUN curl -o "/usr/src/#1" "https://files.pythonhosted.org/packages/e8/ec/3e6a68c9e0fd4b4f4fb6877a3ccfb6f6e6d09f2b4fc87674e671bf64b7b8/{meson-0.47.2.tar.gz}"
-
-RUN dnf clean all
-- 
2.17.1


More information about the igt-dev mailing list