Parcourir la source

bake only interpolates ${*}

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof il y a 2 mois
Parent
commit
a03f2562df

+ 3 - 9
pkg/compose/build_bake.go

@@ -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

+ 8 - 3
pkg/e2e/build_test.go

@@ -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 - 0
pkg/e2e/fixtures/build-test/escaped/compose.yaml

@@ -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}