escape $ in bake.json as interpolation already has been managed by compose

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2025-10-03 09:05:09 +02:00 committed by Guillaume Lours
parent fa08127456
commit cf7e31f731
4 changed files with 34 additions and 0 deletions

View File

@ -280,6 +280,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
return nil, err return nil, err
} }
// escape all occurrences of '$' as we interpolated everything that has to
b = bytes.ReplaceAll(b, []byte("$"), []byte("$$"))
if options.Print { if options.Print {
_, err = fmt.Fprintln(s.stdout(), string(b)) _, err = fmt.Fprintln(s.stdout(), string(b))
return nil, err return nil, err

View File

@ -645,3 +645,11 @@ func TestBuildTLS(t *testing.T) {
res := icmd.RunCmd(cmd) res := icmd.RunCmd(cmd)
res.Assert(t, icmd.Expected{Err: "Built"}) res.Assert(t, icmd.Expected{Err: "Built"})
} }
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.Assert(t, icmd.Expected{Out: "foo is ${bar}"})
}

View File

@ -0,0 +1,17 @@
# Copyright 2020 Docker Compose CLI authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM alpine
ARG foo
RUN echo foo is $foo

View File

@ -0,0 +1,6 @@
services:
foo:
build:
context: .
args:
foo: $${bar}