Skip to content

docker: fix ARG scoping, remove cache-defeating cleanup, quiet tar#17

Merged
beriberikix merged 1 commit into
mainfrom
fix/dockerfile-warnings
Mar 15, 2026
Merged

docker: fix ARG scoping, remove cache-defeating cleanup, quiet tar#17
beriberikix merged 1 commit into
mainfrom
fix/dockerfile-warnings

Conversation

@beriberikix

Copy link
Copy Markdown
Contributor

Summary

Fix three categories of Docker build warnings identified in GHA annotations and local build output.

Changes

W1 — Remove cache-defeating apt-get clean / rm -rf /var/lib/apt/lists/* (all 3 Dockerfiles)

The --mount=type=cache mounts on /var/cache/apt and /var/lib/apt/lists keep those directories in BuildKit's persistent cache — they are never written to the image layer. Calling apt-get clean and rm -rf /var/lib/apt/lists/* at the end of those same RUN steps wiped the BuildKit cache on every build, forcing a full apt list re-download on the next run. Removing these lines means the cache actually persists between builds as intended.

apt-get autoremove is kept — it removes unneeded packages from the image layer, which is correct.

W2 — Re-declare ARGs with defaults after FROM (zephyr/Dockerfile, zephyr-posix/Dockerfile)

Docker ARGs declared before FROM go out of scope after FROM. Both child Dockerfiles re-declared ARG ZEPHYR_SDK_INSTALL_DIR with no default, so the variable resolved to an empty string post-FROM, making ${ZEPHYR_SDK_INSTALL_DIR}/setup.sh resolve to /setup.sh. The BuildKit 1.7 linter warns about undefined variables used in commands.

Fix: re-declare all consumed ARGs after FROM with explicit defaults (ZEPHYR_SDK_VERSION=1.0.0, ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-${ZEPHYR_SDK_VERSION}, and ZEPHYR_SDK_TOOLCHAINS in zephyr/Dockerfile). CI-supplied --build-arg values override these defaults as before.

W3 — tar -xvf to tar -xf (zephyr-base/Dockerfile)

The -v (verbose) flag printed every filename in the SDK archive to stdout, producing thousands of lines of build output that obscured real warnings. Quieted to -xf.

Testing

All three images built successfully locally:

  • zephyr:base-1.0.0SDK (arm64)
  • zephyr:arm-1.0.0SDK (arm64)
  • zephyr:posix-1.0.0SDK (amd64 — pre-existing platform constraint due to gcc-multilib)

Build output is clean: no verbose tar listing, no BuildKit ARG-undefined warnings.

@beriberikix beriberikix merged commit 163cdc5 into main Mar 15, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant