From cf7e31f731f343f14f819f109eec97df406628f0 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 3 Oct 2025 09:05:09 +0200 Subject: [PATCH] escape $ in bake.json as interpolation already has been managed by compose Signed-off-by: Nicolas De Loof --- pkg/compose/build_bake.go | 3 +++ pkg/e2e/build_test.go | 8 ++++++++ pkg/e2e/fixtures/build-test/escaped/Dockerfile | 17 +++++++++++++++++ .../fixtures/build-test/escaped/compose.yaml | 6 ++++++ 4 files changed, 34 insertions(+) create mode 100644 pkg/e2e/fixtures/build-test/escaped/Dockerfile create mode 100644 pkg/e2e/fixtures/build-test/escaped/compose.yaml diff --git a/pkg/compose/build_bake.go b/pkg/compose/build_bake.go index 3f2d5febf..71735dcb0 100644 --- a/pkg/compose/build_bake.go +++ b/pkg/compose/build_bake.go @@ -280,6 +280,9 @@ 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 diff --git a/pkg/e2e/build_test.go b/pkg/e2e/build_test.go index e70cce4fd..e05332616 100644 --- a/pkg/e2e/build_test.go +++ b/pkg/e2e/build_test.go @@ -645,3 +645,11 @@ func TestBuildTLS(t *testing.T) { res := icmd.RunCmd(cmd) 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}"}) +} diff --git a/pkg/e2e/fixtures/build-test/escaped/Dockerfile b/pkg/e2e/fixtures/build-test/escaped/Dockerfile new file mode 100644 index 000000000..dd507f4ff --- /dev/null +++ b/pkg/e2e/fixtures/build-test/escaped/Dockerfile @@ -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 diff --git a/pkg/e2e/fixtures/build-test/escaped/compose.yaml b/pkg/e2e/fixtures/build-test/escaped/compose.yaml new file mode 100644 index 000000000..997af4e92 --- /dev/null +++ b/pkg/e2e/fixtures/build-test/escaped/compose.yaml @@ -0,0 +1,6 @@ +services: + foo: + build: + context: . + args: + foo: $${bar}