Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit daf701c

Browse files
committed
bake only interpolates ${*}
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent ce463d5 commit daf701c

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

pkg/compose/build_bake.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
184184
build := *service.Build
185185
labels := getImageBuildLabels(project, service)
186186

187-
args := types.Mapping{}
188-
for k, v := range resolveAndMergeBuildArgs(s.dockerCli, project, service, options) {
189-
if v == nil {
190-
continue
191-
}
192-
args[k] = *v
187+
args := resolveAndMergeBuildArgs(s.dockerCli, project, service, options).ToMapping()
188+
for k, v := range args {
189+
args[k] = strings.ReplaceAll(v, "${", "$${")
193190
}
194191

195192
entitlements := build.Entitlements
@@ -280,9 +277,6 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
280277
return nil, err
281278
}
282279

283-
// escape all occurrences of '$' as we interpolated everything that has to
284-
b = bytes.ReplaceAll(b, []byte("$"), []byte("$$"))
285-
286280
if options.Print {
287281
_, err = fmt.Fprintln(s.stdout(), string(b))
288282
return nil, err

pkg/e2e/build_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,13 @@ func TestBuildTLS(t *testing.T) {
648648

649649
func TestBuildEscaped(t *testing.T) {
650650
c := NewParallelCLI(t)
651-
// ensure local test run does not reuse previously build image
652-
c.RunDockerOrExitError(t, "rmi", "build-test-tags")
653-
res := c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache")
651+
652+
res := c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache", "foo")
654653
res.Assert(t, icmd.Expected{Out: "foo is ${bar}"})
654+
655+
res = c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache", "echo")
656+
res.Assert(t, icmd.Success)
657+
658+
res = c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/build-test/escaped", "build", "--no-cache", "arg")
659+
res.Assert(t, icmd.Success)
655660
}

pkg/e2e/fixtures/build-test/escaped/compose.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,20 @@ services:
44
context: .
55
args:
66
foo: $${bar}
7+
8+
echo:
9+
build:
10+
dockerfile_inline: |
11+
FROM bash
12+
RUN <<'EOF'
13+
echo $(seq 10)
14+
EOF
15+
16+
arg:
17+
build:
18+
args:
19+
BOOL: "true"
20+
dockerfile_inline: |
21+
FROM alpine:latest
22+
ARG BOOL
23+
RUN /bin/$${BOOL}

0 commit comments

Comments
 (0)