From d517ec0dc937149f80829a2ab8f627ad42413bd1 Mon Sep 17 00:00:00 2001 From: Jan R Date: Sat, 24 Feb 2024 13:55:39 +0100 Subject: [PATCH 1/2] [docker] reduce layer size - move apt list cleanup into layers -> reduces image size by ~40MB (2.92GB -> 2.88GB) - remove apt cleanup (automatically done in ubuntu docker images) details to both changes: https://docs.docker.com/develop/develop-images/instructions/#run --- .devcontainer/Dockerfile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e948180e..05f406e1 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -11,7 +11,8 @@ RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ software-properties-common wget apt-utils file zip \ openssh-client gpg-agent socat rsync \ make ninja-build git \ - python3 python3-pip + python3 python3-pip \ + && rm -rf /var/lib/apt/lists/* # Install conan RUN python3 -m pip install --upgrade pip setuptools && \ @@ -35,7 +36,8 @@ ARG GCC_VER="11" RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends \ - gcc-${GCC_VER} g++-${GCC_VER} gdb + gcc-${GCC_VER} g++-${GCC_VER} gdb \ + && rm -rf /var/lib/apt/lists/* # Set gcc-${GCC_VER} as default gcc RUN update-alternatives --install /usr/bin/gcc gcc $(which gcc-${GCC_VER}) 100 @@ -50,7 +52,8 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 2>/dev/ apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends \ clang-${LLVM_VER} lldb-${LLVM_VER} lld-${LLVM_VER} clangd-${LLVM_VER} \ - llvm-${LLVM_VER}-dev libclang-${LLVM_VER}-dev clang-tidy-${LLVM_VER} + llvm-${LLVM_VER}-dev libclang-${LLVM_VER}-dev clang-tidy-${LLVM_VER} \ + && rm -rf /var/lib/apt/lists/* # Set the default clang-tidy, so CMake can find it RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy $(which clang-tidy-${LLVM_VER}) 1 @@ -66,17 +69,20 @@ RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/nul | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \ apt-add-repository -y "deb ${CMAKE_URL} ${CMAKE_PKG} main" && \ apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ - apt-get install -y --no-install-recommends cmake cmake-curses-gui + apt-get install -y --no-install-recommends cmake cmake-curses-gui \ + && rm -rf /var/lib/apt/lists/* # Install editors RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends \ - neovim emacs nano + neovim emacs nano \ + && rm -rf /var/lib/apt/lists/* # Install optional dependecies RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends \ - doxygen graphviz ccache cppcheck + doxygen graphviz ccache cppcheck \ + && rm -rf /var/lib/apt/lists/* # Install include-what-you-use ENV IWYU /home/iwyu @@ -100,9 +106,6 @@ RUN mkdir -p $(include-what-you-use -print-resource-dir 2>/dev/null) RUN ln -s $(readlink -f /usr/lib/clang/${LLVM_VER}/include) \ $(include-what-you-use -print-resource-dir 2>/dev/null)/include -## Cleanup cached apt data we don't need anymore -RUN apt-get autoremove -y && apt-get clean && \ - rm -rf /var/lib/apt/lists/* # Allow the user to set compiler defaults ARG USE_CLANG From 9296336794a2f300cd434a799799131271003e61 Mon Sep 17 00:00:00 2001 From: Jan R Date: Sat, 24 Feb 2024 13:56:34 +0100 Subject: [PATCH 2/2] [docker] reduce layer size - disable pip cache no significant reduction of image size, but good practice. --- .devcontainer/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 05f406e1..fcfe1a82 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -15,8 +15,8 @@ RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ && rm -rf /var/lib/apt/lists/* # Install conan -RUN python3 -m pip install --upgrade pip setuptools && \ - python3 -m pip install conan && \ +RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools && \ + python3 -m pip install --no-cache-dir conan && \ conan --version # By default, anything you run in Docker is done as superuser.