Skip to content

Commit 0c95d16

Browse files
committed
escape $ in bake.json as interpolation already has been managed by compose
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent fa08127 commit 0c95d16

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

pkg/compose/build_bake.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
280280
return nil, err
281281
}
282282

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

pkg/e2e/build_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,11 @@ func TestBuildTLS(t *testing.T) {
645645
res := icmd.RunCmd(cmd)
646646
res.Assert(t, icmd.Expected{Err: "Built"})
647647
}
648+
649+
func TestBuildEscaped(t *testing.T) {
650+
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")
654+
res.Assert(t, icmd.Expected{Out: "foo is ${bar}"})
655+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2020 Docker Compose CLI authors
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM alpine
16+
ARG foo
17+
RUN echo foo is $foo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
foo:
3+
build:
4+
context: .
5+
args:
6+
foo: $${bar}

0 commit comments

Comments
 (0)