bake only interpolates ${*}

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof
2025-10-08 12:20:34 +02:00
committed by Guillaume Lours
parent a07f2b8ded
commit a03f2562df
3 changed files with 28 additions and 12 deletions

View File

@@ -184,12 +184,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
build := *service.Build
labels := getImageBuildLabels(project, service)
args := types.Mapping{}
for k, v := range resolveAndMergeBuildArgs(s.dockerCli, project, service, options) {
if v == nil {
continue
}
args[k] = *v
args := resolveAndMergeBuildArgs(s.dockerCli, project, service, options).ToMapping()
for k, v := range args {
args[k] = strings.ReplaceAll(v, "${", "$${")
}
entitlements := build.Entitlements
@@ -280,9 +277,6 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
return nil, err
}
// escape all occurrences of '$' as we interpolated everything that has to
b = bytes.ReplaceAll(b, []byte("$"), []byte("$$"))
if options.Print {
_, err = fmt.Fprintln(s.stdout(), string(b))
return nil, err

View File

@@ -648,8 +648,13 @@ func TestBuildTLS(t *testing.T) {
func TestBuildEscaped(t *testing.T) {
c := NewParallelCLI(t)
// ensure local test run does not reuse previously build image
c.RunDockerOrExitError(t, "rmi", "build-test-tags")
res := c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache")
res := c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache", "foo")
res.Assert(t, icmd.Expected{Out: "foo is ${bar}"})
res = c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache", "echo")
res.Assert(t, icmd.Success)
res = c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache", "arg")
res.Assert(t, icmd.Success)
}

View File

@@ -4,3 +4,20 @@ services:
context: .
args:
foo: $${bar}
echo:
build:
dockerfile_inline: |
FROM bash
RUN <<'EOF'
echo $(seq 10)
EOF
arg:
build:
args:
BOOL: "true"
dockerfile_inline: |
FROM alpine:latest
ARG BOOL
RUN /bin/$${BOOL}