feat(earthly): pass custom Docker build args via CUSTOM_ARG_ prefix - #801
Open
Yogeshwar-Pawade wants to merge 1 commit into
Open
feat(earthly): pass custom Docker build args via CUSTOM_ARG_ prefix#801Yogeshwar-Pawade wants to merge 1 commit into
Yogeshwar-Pawade wants to merge 1 commit into
Conversation
The Earthfile's base-image target forwards only a fixed --build-arg list into the user Dockerfile, and Earthly's `FROM DOCKERFILE` cannot forward build args dynamically. Any custom `ARG` a user added to ./Dockerfile therefore never received a value from .arg and silently resolved to its default, with no build-time indication -- discarding per-build customization (e.g. BRAND, DHCP_VENDOR_CLASS). earthly.sh now injects values into the matching Dockerfile `ARG` defaults before Earthly runs, driven by CUSTOM_ARG_<NAME> entries in .arg. The upstream Earthfile is untouched (survives CanvOS upgrades) and the original Dockerfile is restored on exit. Fail-closed guards turn the old silent drop into loud errors: typo / undeclared ARG, Earthfile-managed name, empty value, injection that did not take effect, and an unsatisfied bare ARG on an image/ISO build. Normal Earthfile .arg keys are ignored (no false positives). A build-time report prints exactly which args were injected vs left at default. - scripts/custom-build-args.sh: sourceable mechanism + guards - test/custom-build-args_test.sh: 9 unit tests (no Docker required) - README + .arg.template: document the CUSTOM_ARG_ workflow Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Issue
Custom Docker build arguments added to
./Dockerfilenever received a value and silently fell back to their defaults — with no build-time indication.base-imagetarget forwards only a fixed--build-arglist into the user Dockerfile (BASE,OS_*, proxies,DRBD_VERSION), and Earthly'sFROM DOCKERFILEcannot forward build args dynamically.ARG BRAND/ARG DHCP_VENDOR_CLASSto the Dockerfile and set the value in.arggot the default, not their value.Solution
earthly.shnow bridges the gap the Earthfile can't: before Earthly runs, it injects.argvalues into the matchingARGdefaults of a staged Dockerfile, then restores the original on exit. The upstreamEarthfileis not modified (it survives CanvOS upgrades untouched).Custom args are declared in
.argwith aCUSTOM_ARG_prefix, which makes intent explicit and lets typos be caught (a plain.argkey can't be distinguished from a normal Earthfile arg):# .arg CUSTOM_ARG_BRAND=kfc-uk CUSTOM_ARG_DHCP_VENDOR_CLASS=retailThe wrapper prints exactly what it did (killing the original "no build-time indication"):
Fail-closed guards (silent drop → loud error)
CUSTOM_ARG_<NAME>with no matchingARG <NAME>in the Dockerfile (typo)CUSTOM_ARG_<NAME>where<NAME>is Earthfile-managed (BASE,OS_DISTRIBUTION, proxies, …)CUSTOM_ARG_<NAME>with an empty value./DockerfilepresentARGwith no default and no value, on an image/ISO targetNormal Earthfile
.argkeys (CUSTOM_TAG,ISO_NAME,ARCH, …) are ignored — no false positives. Secrets must not be passed this way (build args leak intodocker history/ the build cache); the existing--secretflow is unchanged.Files
scripts/custom-build-args.sh— sourceable mechanism + guards (new)earthly.sh— sources the lib and callsinject_custom_build_args "$1"before the build (+11 lines)test/custom-build-args_test.sh— 9 unit tests, no Docker required (new)README.md— new "Custom Docker Build Arguments" section; corrected the misleading "Earthfile merges custom packages" line.arg.template— documentedCUSTOM_ARG_usageManual Test Plan (what was verified)
All run on this branch against a real dev
.arg.bash test/custom-build-args_test.shPASS: 9 FAIL: 0./earthly.sh +base-imageCustom Docker build args: injected: BRAND=kfc-ukCUSTOM_ARG_BRAN=…withARG BRANDin DockerfileCUSTOM_ARG_OS_DISTRIBUTION=…CUSTOM_ARG_BRAND=ARG BRAND+RUN echo "CANVOS-BRAND-CHECK: [$BRAND]", ran+base-imageCANVOS-BRAND-CHECK: [kfc-uk]./earthly.sh +base-image🌍 Earthly Build ✅ SUCCESS(exit 0)./Dockerfileafter the runDockerfile.canvos.bakleft behindThe contrast case (plain
BRAND=…without the prefix) reproduces the old empty-value behavior, confirming why the mechanism is needed.Notes
fatal: No tags can describe …fromgit describeinearthly.shon a branch with no reachable tags — harmless (only affects the version tag on a full build).