From 4437214e782d92065e0159dd027e43a6dba50b96 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Sat, 6 Dec 2025 15:22:06 +0100 Subject: [PATCH 1/3] Make image smaller by removing stuff we don't need. --- .github/workflows/zswatch-ci-image.yml | 1 + Dockerfile.zswatch-ci | 34 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/zswatch-ci-image.yml b/.github/workflows/zswatch-ci-image.yml index 185d457..7c3e14c 100644 --- a/.github/workflows/zswatch-ci-image.yml +++ b/.github/workflows/zswatch-ci-image.yml @@ -6,6 +6,7 @@ on: - main - zswatch_* paths: + - Dockerfile.zswatch-ci - Dockerfile.base - Dockerfile.ci - .github/workflows/zswatch-ci-image.yml diff --git a/Dockerfile.zswatch-ci b/Dockerfile.zswatch-ci index 31255ef..05e45e4 100644 --- a/Dockerfile.zswatch-ci +++ b/Dockerfile.zswatch-ci @@ -12,6 +12,9 @@ ARG UBUNTU_MIRROR_PORTS=ports.ubuntu.com/ubuntu-ports ARG ZSDK_VERSION=0.17.4 ENV ZSDK_VERSION=$ZSDK_VERSION +# Limit installed SDK content to the toolchains used by ZSWatch to keep the image lean. +ARG ZSDK_TOOLCHAINS="arm-zephyr-eabi,x86_64-zephyr-elf" +ENV ZSDK_TOOLCHAINS=$ZSDK_TOOLCHAINS # Install minimal extra APT packages required for ZSWatch CI RUN < Date: Sat, 6 Dec 2025 19:32:45 +0100 Subject: [PATCH 2/3] Reclaim ci runner storage. --- .github/workflows/zswatch-ci-image.yml | 11 +++++++++++ Dockerfile.zswatch-ci | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/.github/workflows/zswatch-ci-image.yml b/.github/workflows/zswatch-ci-image.yml index 7c3e14c..58ef549 100644 --- a/.github/workflows/zswatch-ci-image.yml +++ b/.github/workflows/zswatch-ci-image.yml @@ -24,6 +24,14 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Free disk space + run: | + df -h + sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL + docker system prune -af || true + docker volume prune -f || true + df -h + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -44,6 +52,9 @@ jobs: ghcr.io/zswatch/ci-base:${{ github.ref_name }} ghcr.io/zswatch/ci-base:latest + - name: Prune buildx cache + run: docker buildx prune -af --keep-storage 5GB + - name: Build and push CI image uses: docker/build-push-action@v5 with: diff --git a/Dockerfile.zswatch-ci b/Dockerfile.zswatch-ci index 05e45e4..d90a725 100644 --- a/Dockerfile.zswatch-ci +++ b/Dockerfile.zswatch-ci @@ -45,6 +45,23 @@ RUN <<'EOF' doxygen \ thrift-compiler || true + apt-get purge --auto-remove -y \ + libgtk2.0-0 \ + libcairo2-dev \ + libglib2.0-dev \ + libpcap-dev \ + ovmf \ + parallel || true + + apt-get clean -y + rm -rf /var/lib/apt/lists/* + rm -rf /usr/share/doc /usr/share/man /usr/share/info +EOF + +# Reinstall SDL2 dev headers explicitly (native_sim needs sdl2.pc) +RUN < Date: Sat, 6 Dec 2025 23:31:41 +0100 Subject: [PATCH 3/3] Split into a slim base dockerfile. --- .github/workflows/zswatch-ci-image.yml | 9 +- Dockerfile.zswatch-base | 122 +++++++++++++++++++++++++ Dockerfile.zswatch-ci | 3 + 3 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 Dockerfile.zswatch-base diff --git a/.github/workflows/zswatch-ci-image.yml b/.github/workflows/zswatch-ci-image.yml index 58ef549..21a7ce9 100644 --- a/.github/workflows/zswatch-ci-image.yml +++ b/.github/workflows/zswatch-ci-image.yml @@ -6,6 +6,7 @@ on: - main - zswatch_* paths: + - Dockerfile.zswatch-base - Dockerfile.zswatch-ci - Dockerfile.base - Dockerfile.ci @@ -46,11 +47,11 @@ jobs: uses: docker/build-push-action@v5 with: context: . - file: ./Dockerfile.base + file: ./Dockerfile.zswatch-base push: true tags: | - ghcr.io/zswatch/ci-base:${{ github.ref_name }} - ghcr.io/zswatch/ci-base:latest + ghcr.io/zswatch/ci-base-slim:${{ github.ref_name }} + ghcr.io/zswatch/ci-base-slim:latest - name: Prune buildx cache run: docker buildx prune -af --keep-storage 5GB @@ -65,4 +66,4 @@ jobs: ghcr.io/zswatch/zswatch-ci:latest ghcr.io/zswatch/zswatch-ci:${{ github.ref_name }} build-args: | - BASE_IMAGE=ghcr.io/zswatch/ci-base:${{ github.ref_name }} + BASE_IMAGE=ghcr.io/zswatch/ci-base-slim:${{ github.ref_name }} diff --git a/Dockerfile.zswatch-base b/Dockerfile.zswatch-base new file mode 100644 index 0000000..7acfee5 --- /dev/null +++ b/Dockerfile.zswatch-base @@ -0,0 +1,122 @@ +# ZSWatch slim base image +# Minimal tooling for nRF5340 and native_sim builds; omits extras from the upstream base. + +FROM ubuntu:24.04 + +ARG USERNAME=user +ARG UID=1000 +ARG GID=1000 +ARG PYTHON_VENV_PATH=/opt/python/venv +ARG UBUNTU_MIRROR_ARCHIVE=archive.ubuntu.com/ubuntu +ARG UBUNTU_MIRROR_SECURITY=security.ubuntu.com/ubuntu +ARG UBUNTU_MIRROR_PORTS=ports.ubuntu.com/ubuntu-ports + +# Set default shell during Docker image build to bash +SHELL ["/bin/bash", "-eo", "pipefail", "-c"] + +# Set non-interactive frontend for apt-get to skip any user confirmations +ENV DEBIAN_FRONTEND=noninteractive + +# Install a trimmed set of APT packages +RUN <=5.0.2' \ + GitPython \ + imgtool \ + junitparser \ + junit2html \ + nrf-regtool~=9.0.1 \ + numpy \ + protobuf \ + grpcio-tools \ + PyGithub \ + pylint \ + sh \ + statistics \ + west +EOF + +# Make Zephyr Python virtual environment available globally +ENV PATH=${PYTHON_VENV_PATH}/bin:$PATH + +# Create user account +RUN < /etc/sudoers.d/$USERNAME + chmod 0440 /etc/sudoers.d/$USERNAME +EOF + +# Ensure that container runs in the 'root' user context +USER root diff --git a/Dockerfile.zswatch-ci b/Dockerfile.zswatch-ci index d90a725..6668c6e 100644 --- a/Dockerfile.zswatch-ci +++ b/Dockerfile.zswatch-ci @@ -31,6 +31,7 @@ EOF RUN <<'EOF' if [ "${HOSTTYPE}" = "x86_64" ]; then # Drop 32-bit support and multilib toolchains not needed for nRF/native_sim_64 + apt-get update -y apt-get purge --auto-remove -y \ gcc-multilib g++-multilib \ libc6-dbg:i386 libfuse-dev:i386 libsdl2-dev:i386 || true @@ -38,6 +39,7 @@ RUN <<'EOF' fi # Remove heavy debug/coverage/doc tools unused in ZSWatch CI builds + apt-get update -y apt-get purge --auto-remove -y \ valgrind \ lcov \ @@ -45,6 +47,7 @@ RUN <<'EOF' doxygen \ thrift-compiler || true + apt-get update -y apt-get purge --auto-remove -y \ libgtk2.0-0 \ libcairo2-dev \