@@ -269,12 +269,20 @@ func (node *NodeLLB) stepScripts(root llb.State, i int, step v1alpha2.Step) llb.
269
269
for _ , script := range []struct {
270
270
Desc string
271
271
Instructions v1alpha2.Instructions
272
+ // Detached script modifications to the files are not propagated to the next steps.
273
+ Detached bool
272
274
}{
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 },
277
279
} {
280
+ if len (script .Instructions ) == 0 {
281
+ continue
282
+ }
283
+
284
+ scriptRoot := root
285
+
278
286
for _ , instruction := range script .Instructions {
279
287
runOptions := append ([]llb.RunOption (nil ), node .Graph .commonRunOptions ... )
280
288
@@ -311,7 +319,19 @@ func (node *NodeLLB) stepScripts(root llb.State, i int, step v1alpha2.Step) llb.
311
319
runOptions = append (runOptions , llb .IgnoreCache )
312
320
}
313
321
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
315
335
}
316
336
}
317
337
0 commit comments