@@ -269,12 +269,20 @@ func (node *NodeLLB) stepScripts(root llb.State, i int, step v1alpha2.Step) llb.
269269 for _ , script := range []struct {
270270 Desc string
271271 Instructions v1alpha2.Instructions
272+ // Detached script modifications to the files are not propagated to the next steps.
273+ Detached bool
272274 }{
273- {"prepare" , step .Prepare },
274- {"build" , step .Build },
275- {"install" , step .Install },
276- {"test" , step .Test },
275+ {"prepare" , step .Prepare , false },
276+ {"build" , step .Build , false },
277+ {"install" , step .Install , false },
278+ {"test" , step .Test , true },
277279 } {
280+ if len (script .Instructions ) == 0 {
281+ continue
282+ }
283+
284+ scriptRoot := root
285+
278286 for _ , instruction := range script .Instructions {
279287 runOptions := append ([]llb.RunOption (nil ), node .Graph .commonRunOptions ... )
280288
@@ -311,7 +319,19 @@ func (node *NodeLLB) stepScripts(root llb.State, i int, step v1alpha2.Step) llb.
311319 runOptions = append (runOptions , llb .IgnoreCache )
312320 }
313321
314- root = root .Run (runOptions ... ).Root ()
322+ scriptRoot = scriptRoot .Run (runOptions ... ).Root ()
323+ }
324+
325+ if script .Detached {
326+ scriptRoot = scriptRoot .File (
327+ llb .Mkdir ("/empty" , constants .DefaultDirMode ),
328+ )
329+
330+ root = root .File (
331+ llb .Copy (scriptRoot , "/empty" , "/" , defaultCopyOptions (node .Graph .Options , false )),
332+ )
333+ } else {
334+ root = scriptRoot
315335 }
316336 }
317337
0 commit comments