Skip to content

Commit b2a223d

Browse files
committed
fix: exclude test script output from the result
Now if `test` script does any changes to the build root, they don't propagate to the final result. Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 76a2c8f commit b2a223d

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ require (
1717
github.com/siderolabs/gen v0.8.0
1818
github.com/spf13/cobra v1.8.1
1919
github.com/stretchr/testify v1.10.0
20-
golang.org/x/oauth2 v0.25.0
21-
golang.org/x/sync v0.10.0
20+
golang.org/x/oauth2 v0.26.0
21+
golang.org/x/sync v0.11.0
2222
gopkg.in/yaml.v3 v3.0.1
2323
)
2424

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,15 @@ golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
182182
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
183183
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
184184
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
185+
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
186+
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
185187
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
186188
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
187189
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
188190
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
189191
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
192+
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
193+
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
190194
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
191195
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
192196
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

internal/pkg/convert/node.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

internal/pkg/integration/testdata/stages/final/pkg.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ steps:
88
- test:
99
- test -f /stage-a/a
1010
- test -f /stage-b/b
11+
- test ! -f /stage-b/bb # stage-b/bb should not exist
1112
- test -f /stage-d/c
1213
- test -f /stage-d/d
1314
finalize:

internal/pkg/integration/testdata/stages/stage-b/pkg.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ steps:
77
build:
88
- touch /root/b
99

10+
test:
11+
- test -f /root/b
12+
- touch /root/bb # this should not persist, as it's part of test instructions
13+
1014
finalize:
1115
- from: /root
1216
to: /stage-b

0 commit comments

Comments
 (0)