mirror of
https://github.com/docker/compose.git
synced 2026-02-09 01:59:22 +08:00
bake only interpolates ${*}
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
committed by
Guillaume Lours
parent
a07f2b8ded
commit
a03f2562df
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user