docker: fix ARG scoping, remove cache-defeating cleanup, quiet tar#17
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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=cachemounts on/var/cache/aptand/var/lib/apt/listskeep those directories in BuildKit's persistent cache — they are never written to the image layer. Callingapt-get cleanandrm -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 autoremoveis 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
FROMgo out of scope afterFROM. Both child Dockerfiles re-declaredARG ZEPHYR_SDK_INSTALL_DIRwith no default, so the variable resolved to an empty string post-FROM, making${ZEPHYR_SDK_INSTALL_DIR}/setup.shresolve to/setup.sh. The BuildKit 1.7 linter warns about undefined variables used in commands.Fix: re-declare all consumed ARGs after
FROMwith explicit defaults (ZEPHYR_SDK_VERSION=1.0.0,ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-${ZEPHYR_SDK_VERSION}, andZEPHYR_SDK_TOOLCHAINSinzephyr/Dockerfile). CI-supplied--build-argvalues override these defaults as before.W3 —
tar -xvftotar -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 togcc-multilib)Build output is clean: no verbose tar listing, no BuildKit ARG-undefined warnings.