Skip to content

fix(docker/v2): expand global ARG references when resolving the base image - #7203

Merged
caarlos0 merged 3 commits into
goreleaser:mainfrom
LemonCondor:fix/docker-v2-nested-arg-base-image
Oct 21, 2026
Merged

caarlos0 merged 3 commits into
goreleaser:mainfrom
LemonCondor:fix/docker-v2-nested-arg-base-image

Conversation

@LemonCondor

Copy link
Copy Markdown
Contributor

A global ARG default can reference a previously declared global ARG:

ARG ALPINE_VERSION=3.20
ARG BASE=alpine:${ALPINE_VERSION}
FROM ${BASE}

parseBaseImage stored the raw default, so .BaseImage became alpine:${ALPINE_VERSION}. The org.opencontainers.image.base.name annotation then got the unexpanded string, and digest resolution failed. A build_args override of the referenced ARG (ALPINE_VERSION) was also ignored, because baseImageBuildArgs only collected ARGs named directly in FROM lines.

This PR changes two things:

  • ARG defaults are expanded with the global ARGs declared before them.
  • ARGs referenced by global ARG defaults are also collected as base-image build args, so their overrides are rendered and applied.

This is related to #6923 (direct overrides, fixed in #7095). This PR covers the nested case.

Tests: I added testdata/dockerfiles/arg-references-arg and TestMakeArgsWithBaseImageNestedBuildArgOverride. Without the fix both fail:

  • actual: "alpine:${ALPINE_VERSION}"
  • base.name=${ALPINE_REF}

With the fix, go test ./internal/pipe/docker/v2/ passes.

AI disclosure: this change was prepared with the help of an AI assistant (Claude). The commit carries Assisted-by: Claude. I reviewed and tested the change.

🤖 Generated with Claude Code

…image

A global ARG default can reference a previously declared ARG, e.g.

    ARG ALPINE_VERSION=3.20
    ARG BASE=alpine:${ALPINE_VERSION}
    FROM ${BASE}

parseBaseImage stored the raw default, so .BaseImage became
"alpine:${ALPINE_VERSION}" and digest resolution failed. Build-arg
overrides of the referenced ARG were also ignored, because only ARGs
named directly in FROM lines were considered.

Expand ARG defaults with the ARGs declared before them, and consider
ARGs referenced by global ARG defaults when collecting overrides.

Assisted-by: Claude
Signed-off-by: Guillaume Marty <[email protected]>
@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 13, 2026

@caarlos0 caarlos0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot, on behalf of Carlos.

One blocking regression found. Both independent read-only checks are complete.

Validation limits: source inspection only; no local builds or tests were run. The reported PR checks show only WIP passing, not test results.

Comment thread internal/pipe/docker/v2/baseimage.go Resolved
Address PR goreleaser#7203 feedback about unrelated global ARG defaults forcing BaseImage and BaseImageDigest templates to render before those fields exist. Trace defaults backward from FROM references and cover unrelated defaults and transitive overrides.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 812fd81f-41a3-4ce7-8fe0-7d06c880c5d0
Signed-off-by: Carlos Alexandro Becker <[email protected]>
@caarlos0
caarlos0 dismissed their stale review October 21, 2026 02:13

Superseded: ec3251c fixes the reported regression, adds coverage, and passes the Docker v2 package tests. The review thread is resolved.

@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.61%. Comparing base (1015c53) to head (ec3251c).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7203   +/-   ##
=======================================
  Coverage   91.61%   91.61%           
=======================================
  Files         192      192           
  Lines       15984    16001   +17     
=======================================
+ Hits        14643    14660   +17     
  Misses       1341     1341           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@caarlos0
caarlos0 added this pull request to the merge queue Oct 21, 2026
Merged via the queue into goreleaser:main with commit 26ffaba Oct 21, 2026
17 of 18 checks passed
@github-actions github-actions Bot added this to the v2.18.0 milestone Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants