@@ -458,39 +458,26 @@ func getCmd(n *ExtendedNode, shouldSplitNode bool) []string {
458
458
return cmd
459
459
}
460
460
461
- func formatEntrypoint ( n * ExtendedNode , c * Config ) string {
462
- // this can technically change behavior. https://docs.docker.com/reference/dockerfile/#understand-how-cmd-and- entrypoint-interact
463
- isJSON , ok := n . Node . Attributes [ "json" ]
464
- if ! ok {
465
- isJSON = false
461
+ func shouldRunInShell ( node string ) bool {
462
+ // https://docs.docker.com/reference/dockerfile/#entrypoint
463
+ parts , err := shlex . Split ( node )
464
+ if err != nil {
465
+ log . Fatalf ( "Error splitting: %s \n " , node )
466
466
}
467
- if ! isJSON {
468
- // https://docs.docker.com/reference/dockerfile/#entrypoint
469
- node := n .Next .Node .Value
470
- parts , err := shlex .Split (node )
471
- if err != nil {
472
- log .Fatalf ("Error splitting: %s\n " , node )
473
- }
474
467
475
- doNotSplit := false
476
- // This is a simplistic check to determine if we need to run in a full shell.
477
- for _ , part := range parts {
478
- if part == "&&" || part == ";" || part == "||" {
479
- doNotSplit = true
480
- break
481
- }
482
- }
483
-
484
- if doNotSplit {
485
- n .Next .Node .Flags = append (n .Next .Node .Flags , []string {"/bin/sh" , "-c" }... )
486
- // Hacky workaround to tell getCmd to not split the command
487
- if n .Node .Attributes == nil {
488
- n .Node .Attributes = make (map [string ]bool )
489
- }
490
- n .Node .Attributes ["json" ] = true
468
+ needsShell := false
469
+ // This is a simplistic check to determine if we need to run in a full shell.
470
+ for _ , part := range parts {
471
+ if part == "&&" || part == ";" || part == "||" {
472
+ needsShell = true
473
+ break
491
474
}
492
475
}
493
- // printAST(n, 0)
476
+
477
+ return needsShell
478
+ }
479
+ func formatEntrypoint (n * ExtendedNode , c * Config ) string {
480
+ // this can technically change behavior. https://docs.docker.com/reference/dockerfile/#understand-how-cmd-and-entrypoint-interact
494
481
return formatCmd (n , c )
495
482
}
496
483
func formatCmd (n * ExtendedNode , c * Config ) string {
@@ -499,6 +486,16 @@ func formatCmd(n *ExtendedNode, c *Config) string {
499
486
if ! ok {
500
487
isJSON = false
501
488
}
489
+
490
+ if ! isJSON {
491
+ doNotSplit := shouldRunInShell (n .Node .Next .Value )
492
+ if doNotSplit {
493
+ n .Next .Node .Flags = append (n .Next .Node .Flags , []string {"/bin/sh" , "-c" }... )
494
+ // Hacky workaround to tell getCmd to not split the command
495
+ isJSON = true
496
+ }
497
+ }
498
+
502
499
cmd := getCmd (n .Next , ! isJSON )
503
500
b , err := Marshal (cmd )
504
501
if err != nil {
0 commit comments