Skip to content

Commit e21c90e

Browse files
authored
chore: remove python cache artifacts in the images (#842)
* chore: disable bytecode compilation during pip install This prevents creation of *.pyc files which helps with: - Reducing container size - Making the build reproducible * chore: add a container diff to find unexpected changes * chore: upload container diff per flavor * chore: fix shellcheck findings * chore: fix workflow syntax issue in container diff job * chore: correct diffoci option name * chore: diffoci has some issues * chore: remove more cruft from image * chore: update python3-pip * chore: consolidate python cache removal * chore: keep cache empty during entire build * chore: fix pr image cleanup * chore: keep container diff out for now * chore: better emoji
1 parent 2366d49 commit e21c90e

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

.devcontainer/cpp/Dockerfile

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,31 @@ HEALTHCHECK NONE
1313

1414
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1515

16+
# Set default environment options
17+
ENV CCACHE_DIR=/cache/.ccache \
18+
CMAKE_EXPORT_COMPILE_COMMANDS="On" \
19+
CMAKE_GENERATOR="Ninja" \
20+
CONAN_HOME=/opt/conan \
21+
CPM_SOURCE_CACHE=/cache/.cpm \
22+
PATH="$PATH:/usr/lib/llvm-${CLANG_VERSION}/bin:/opt/gcc-arm-none-eabi/bin" \
23+
PYTHONPYCACHEPREFIX=/cache/.python
24+
1625
# Install the base system with all tool dependencies
1726
# hadolint ignore=DL3008
1827
RUN --mount=type=bind,source=.devcontainer/cpp/apt-requirements-base.json,target=/tmp/apt-requirements-base.json \
28+
--mount=type=bind,source=.devcontainer/cpp/requirements.txt,target=/tmp/requirements.txt \
29+
--mount=type=cache,target=/cache,sharing=locked \
1930
--mount=type=cache,target=/var/cache/apt,sharing=locked \
2031
--mount=type=cache,target=/var/lib/apt,sharing=locked \
2132
--mount=type=cache,target=/var/log,sharing=locked \
2233
apt-get update && apt-get install -y --no-install-recommends jq \
23-
&& jq -r 'to_entries | .[] | .key + "=" + .value' /tmp/apt-requirements-base.json | xargs apt-get install -y --no-install-recommends
24-
25-
# Include the Cisco Umbrella PKI Root
26-
RUN wget -qO /usr/local/share/ca-certificates/Cisco_Umbrella_Root_CA.crt https://www.cisco.com/security/pki/certs/ciscoumbrellaroot.pem \
27-
&& update-ca-certificates
28-
29-
# Install some tools via pip to get more recent versions
30-
RUN --mount=type=bind,source=.devcontainer/cpp/requirements.txt,target=/tmp/requirements.txt \
31-
python3 -m pip install --break-system-packages --require-hashes --no-cache-dir -r /tmp/requirements.txt
32-
33-
# Set default environment options for CMake and ccache
34-
ENV CCACHE_DIR=/cache/.ccache \
35-
CMAKE_EXPORT_COMPILE_COMMANDS="On" \
36-
CMAKE_GENERATOR="Ninja" \
37-
CONAN_HOME=/opt/conan \
38-
CPM_SOURCE_CACHE=/cache/.cpm-cache
34+
&& jq -r 'to_entries | .[] | .key + "=" + .value' /tmp/apt-requirements-base.json | \
35+
xargs apt-get install -y --no-install-recommends \
36+
# Include the Cisco Umbrella PKI Root
37+
&& wget -qO /usr/local/share/ca-certificates/Cisco_Umbrella_Root_CA.crt https://www.cisco.com/security/pki/certs/ciscoumbrellaroot.pem \
38+
&& update-ca-certificates \
39+
# Install some tools via pip to get more recent versions
40+
&& python3 -m pip install --break-system-packages --require-hashes --no-cache-dir --no-compile -r /tmp/requirements.txt
3941

4042
# Install clang toolchain and mull mutation testing framework
4143
RUN --mount=type=bind,source=.devcontainer/cpp/apt-requirements-clang.json,target=/tmp/apt-requirements-clang.json \
@@ -51,12 +53,10 @@ RUN --mount=type=bind,source=.devcontainer/cpp/apt-requirements-clang.json,targe
5153
&& echo -e 'Package: *\nPin: origin "apt.llvm.org"\nPin-Priority: 1000' > /etc/apt/preferences \
5254
&& apt-get update \
5355
&& jq -r 'to_entries | .[] | .key + "=" + .value' /tmp/apt-requirements-clang.json | xargs apt-get install -y --no-install-recommends
54-
ENV PATH="$PATH:/usr/lib/llvm-${CLANG_VERSION}/bin"
5556

5657
# Install arm-gcc toolchain
5758
RUN mkdir /opt/gcc-arm-none-eabi \
5859
&& wget -qO - "https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-$(uname -m)-arm-none-eabi.tar.xz" | tar --exclude='*arm-none-eabi-gdb*' --exclude='share' --strip-components=1 -xJC /opt/gcc-arm-none-eabi
59-
ENV PATH="$PATH:/opt/gcc-arm-none-eabi/bin"
6060

6161
# Install bats
6262
RUN batstmp="$(mktemp -d /tmp/bats-core-${BATS_VERSION}.XXXX)" \
@@ -71,19 +71,20 @@ RUN wget -qO - "https://github.com/Jake-Shadle/xwin/releases/download/${XWIN_VER
7171

7272
# Compile and install additional clang tools; often necessary as binary arm64 builds are lacking, or packages are out-of-date
7373
# Install ccache from source for a recent version
74-
RUN wget -qO - https://github.com/ccache/ccache/archive/refs/tags/v${CCACHE_VERSION}.tar.gz | tar xz -C /tmp \
74+
RUN --mount=type=cache,target=/cache,sharing=locked \
75+
wget -qO - https://github.com/ccache/ccache/archive/refs/tags/v${CCACHE_VERSION}.tar.gz | tar xz -C /tmp \
7576
&& CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=Off -DENABLE_DOCUMENTATION=Off -S /tmp/ccache-${CCACHE_VERSION} -B /tmp/ccache-${CCACHE_VERSION}/build \
7677
&& cmake --build /tmp/ccache-${CCACHE_VERSION}/build --target install \
7778
&& rm -rf /tmp/ccache-${CCACHE_VERSION}
7879

7980
# Install include-what-you-use (iwyu) from source
8081
# hadolint ignore=DL3008
81-
RUN --mount=type=cache,target=/root/.ccache,sharing=locked \
82+
RUN --mount=type=cache,target=/cache,sharing=locked \
8283
--mount=type=cache,target=/var/cache/apt,sharing=locked \
8384
--mount=type=cache,target=/var/lib/apt,sharing=locked \
8485
apt-get update && apt-get install -y --no-install-recommends libclang-${CLANG_VERSION}-dev llvm-${CLANG_VERSION}-dev \
8586
&& wget -qO - https://github.com/include-what-you-use/include-what-you-use/archive/refs/tags/${INCLUDE_WHAT_YOU_USE_VERSION}.tar.gz | tar xz -C /tmp \
86-
&& CC=clang CXX=clang++ cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -S /tmp/include-what-you-use-${INCLUDE_WHAT_YOU_USE_VERSION} -B /tmp/include-what-you-use-${INCLUDE_WHAT_YOU_USE_VERSION}/build \
87+
&& CC=clang CXX=clang++ cmake -S /tmp/include-what-you-use-${INCLUDE_WHAT_YOU_USE_VERSION} -B /tmp/include-what-you-use-${INCLUDE_WHAT_YOU_USE_VERSION}/build \
8788
&& cmake --build /tmp/include-what-you-use-${INCLUDE_WHAT_YOU_USE_VERSION}/build --target install \
8889
&& rm -rf /tmp/include-what-you-use-${INCLUDE_WHAT_YOU_USE_VERSION} \
8990
&& apt-get purge -y libclang-${CLANG_VERSION}-dev llvm-${CLANG_VERSION}-dev \
@@ -108,6 +109,7 @@ RUN --mount=type=cache,target=/var/log,sharing=locked \
108109
# Set up package managers CPM and Conan
109110
# - Install CPM.cmake to the CMake module path
110111
# - Configure a default profile for Conan and set the CMake generator to Ninja
111-
RUN wget -qP /usr/local/lib/python*/dist-packages/cmake/data/share/cmake-*/Modules/ https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_VERSION}/CPM.cmake \
112+
RUN --mount=type=cache,target=/cache,sharing=locked \
113+
wget -qP /usr/local/lib/python*/dist-packages/cmake/data/share/cmake-*/Modules/ https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_VERSION}/CPM.cmake \
112114
&& conan profile detect \
113115
&& echo -e "\n[conf]\ntools.cmake.cmaketoolchain:generator=Ninja" >> "$(conan profile path default)"

.github/workflows/pr-image-cleanup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
2323
with:
24-
disable-sudo-and-containers: true
24+
disable-sudo: true
2525
egress-policy: audit
2626
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
2727
with:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ This repository contains [devcontainers](https://docs.github.com/en/codespaces/s
2929
### Key Features
3030

3131
- **Batteries Included** 🔋: Pre-configured tools for local development and continuous integration.
32-
- **Multi-platform Support** 🌍: Compatible with x64 and arm64 hardware on Windows, Linux, and macOS.
33-
- **Image Flavors** 🖼️: Dedicated containers for C++ and Rust development.
32+
- **Multi-platform Support** ⚙️: Compatible with x64 and arm64 hardware on Windows, Linux, and macOS.
33+
- **Image Flavors** 🍨: Dedicated containers for C++ and Rust development.
3434
- **IDE Integration** 💻: Fully compatible with GitHub Codespaces and VS Code.
3535
- **Semantic Versioning** 🔢: Clear versioning strategy for container images.
3636
- **Secure** 🔒: Emphasis on supply-chain security and compatible with Dependabot.

0 commit comments

Comments
 (0)