@@ -40,6 +40,7 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){
40
40
testBakePrint ,
41
41
testBakePrintSensitive ,
42
42
testBakePrintOverrideEmpty ,
43
+ testBakePrintKeepEscaped ,
43
44
testBakeLocal ,
44
45
testBakeLocalMulti ,
45
46
testBakeRemote ,
@@ -329,6 +330,66 @@ target "default" {
329
330
}` , stdout .String ())
330
331
}
331
332
333
+ func testBakePrintKeepEscaped (t * testing.T , sb integration.Sandbox ) {
334
+ bakefile := []byte (`
335
+ target "default" {
336
+ dockerfile-inline = <<EOT
337
+ ARG VERSION=latest
338
+ FROM alpine:$${VERSION}
339
+ EOT
340
+ args = {
341
+ VERSION = "3.21"
342
+ }
343
+ annotations = [
344
+ "org.opencontainers.image.authors=$${user}"
345
+ ]
346
+ labels = {
347
+ foo = "hello %%{bar}"
348
+ }
349
+ }
350
+ ` )
351
+
352
+ dir := tmpdir (t , fstest .CreateFile ("docker-bake.hcl" , bakefile , 0600 ))
353
+ cmd := buildxCmd (sb , withDir (dir ), withArgs ("bake" , "--print" ))
354
+ stdout := bytes.Buffer {}
355
+ stderr := bytes.Buffer {}
356
+ cmd .Stdout = & stdout
357
+ cmd .Stderr = & stderr
358
+ require .NoError (t , cmd .Run (), stdout .String (), stderr .String ())
359
+
360
+ require .JSONEq (t , `{
361
+ "group": {
362
+ "default": {
363
+ "targets": [
364
+ "default"
365
+ ]
366
+ }
367
+ },
368
+ "target": {
369
+ "default": {
370
+ "annotations": [
371
+ "org.opencontainers.image.authors=$${user}"
372
+ ],
373
+ "context": ".",
374
+ "dockerfile": "Dockerfile",
375
+ "dockerfile-inline": "ARG VERSION=latest\nFROM alpine:$${VERSION}\n",
376
+ "args": {
377
+ "VERSION": "3.21"
378
+ },
379
+ "labels": {
380
+ "foo": "hello %%{bar}"
381
+ }
382
+ }
383
+ }
384
+ }` , stdout .String ())
385
+
386
+ // test build with definition from print output
387
+ dir = tmpdir (t , fstest .CreateFile ("docker-bake.json" , stdout .Bytes (), 0600 ))
388
+ cmd = buildxCmd (sb , withDir (dir ), withArgs ("bake" ))
389
+ out , err := cmd .CombinedOutput ()
390
+ require .NoError (t , err , string (out ))
391
+ }
392
+
332
393
func testBakeLocal (t * testing.T , sb integration.Sandbox ) {
333
394
dockerfile := []byte (`
334
395
FROM scratch
0 commit comments