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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions pkg/compose/build_bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions pkg/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 17 additions & 0 deletions pkg/e2e/fixtures/build-test/escaped/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}