@@ -1243,7 +1243,12 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE
12431243 }
12441244
12451245 if heredoc := parser .MustParseHeredoc (args [0 ]); heredoc != nil {
1246- if d .image .OS != "windows" && strings .HasPrefix (c .Files [0 ].Data , "#!" ) {
1246+ data := c .Files [0 ].Data
1247+ if c .Files [0 ].Chomp {
1248+ data = parser .ChompHeredocContent (data )
1249+ }
1250+
1251+ if d .image .OS != "windows" && strings .HasPrefix (data , "#!" ) {
12471252 // This is a single heredoc with a shebang, so create a file
12481253 // and run it.
12491254 // NOTE: choosing to expand doesn't really make sense here, so
@@ -1252,10 +1257,6 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE
12521257 destPath := "/dev/pipes/"
12531258
12541259 f := c .Files [0 ].Name
1255- data := c .Files [0 ].Data
1256- if c .Files [0 ].Chomp {
1257- data = parser .ChompHeredocContent (data )
1258- }
12591260 st := llb .Scratch ().Dir (sourcePath ).File (
12601261 llb .Mkfile (f , 0755 , []byte (data )),
12611262 dockerui .WithInternalName ("preparing inline document" ),
@@ -1272,10 +1273,6 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE
12721273 // the syntax can still be used for shells that don't support
12731274 // heredocs directly.
12741275 // NOTE: like above, we ignore the expand option.
1275- data := c .Files [0 ].Data
1276- if c .Files [0 ].Chomp {
1277- data = parser .ChompHeredocContent (data )
1278- }
12791276 args = []string {data }
12801277 }
12811278 customname += fmt .Sprintf (" (%s)" , summarizeHeredoc (c .Files [0 ].Data ))
0 commit comments