Skip to content

Commit f84927b

Browse files
committed
osbuild/osbuild-exec: move exports and checkpoints into options
1 parent 487b7dd commit f84927b

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

cmd/build/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ func run() error {
136136
fmt.Printf("Building manifest: %s\n", manifestPath)
137137

138138
jobOutput := filepath.Join(outputDir, buildName)
139-
_, err = osbuild.RunOSBuild(mf, imgType.Exports(), checkpoints, os.Stderr, &osbuild.OSBuildOptions{
140-
StoreDir: osbuildStore,
141-
OutputDir: jobOutput,
142-
JSONOutput: false,
139+
_, err = osbuild.RunOSBuild(mf, nil, &osbuild.OSBuildOptions{
140+
StoreDir: osbuildStore,
141+
OutputDir: jobOutput,
142+
Exports: imgType.Exports(),
143+
Checkpoints: checkpoints,
144+
JSONOutput: false,
143145
})
144146
if err != nil {
145147
return err

cmd/osbuild-playground/playground.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ func RunPlayground(img image.ImageKind, d distro.Distro, arch distro.Arch, repos
5757

5858
store := path.Join(state_dir, "osbuild-store")
5959

60-
_, err = osbuild.RunOSBuild(bytes, manifest.GetExports(), manifest.GetCheckpoints(), os.Stdout, &osbuild.OSBuildOptions{
61-
StoreDir: store,
62-
OutputDir: "./",
63-
JSONOutput: false,
60+
_, err = osbuild.RunOSBuild(bytes, nil, &osbuild.OSBuildOptions{
61+
StoreDir: store,
62+
OutputDir: "./",
63+
Exports: manifest.GetExports(),
64+
Checkpoints: manifest.GetCheckpoints(),
65+
JSONOutput: false,
6466
})
6567
if err != nil {
6668
fmt.Fprintf(os.Stderr, "could not run osbuild: %s", err.Error())

pkg/osbuild/osbuild-exec.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ var osbuildCmd = "osbuild"
2929
type OSBuildOptions struct {
3030
StoreDir string
3131
OutputDir string
32-
ExtraEnv []string
32+
33+
Exports []string
34+
Checkpoints []string
35+
ExtraEnv []string
3336

3437
Monitor MonitorType
3538
MonitorFD uintptr
@@ -39,7 +42,7 @@ type OSBuildOptions struct {
3942
CacheMaxSize int64
4043
}
4144

42-
func NewOSBuildCmd(manifest []byte, exports, checkpoints []string, optsPtr *OSBuildOptions) *exec.Cmd {
45+
func NewOSBuildCmd(manifest []byte, optsPtr *OSBuildOptions) *exec.Cmd {
4346
opts := common.ValueOrEmpty(optsPtr)
4447

4548
cacheMaxSize := int64(20 * datasizes.GiB)
@@ -56,11 +59,11 @@ func NewOSBuildCmd(manifest []byte, exports, checkpoints []string, optsPtr *OSBu
5659
"-",
5760
)
5861

59-
for _, export := range exports {
62+
for _, export := range opts.Exports {
6063
cmd.Args = append(cmd.Args, "--export", export)
6164
}
6265

63-
for _, checkpoint := range checkpoints {
66+
for _, checkpoint := range opts.Checkpoints {
6467
cmd.Args = append(cmd.Args, "--checkpoint", checkpoint)
6568
}
6669

@@ -84,7 +87,7 @@ func NewOSBuildCmd(manifest []byte, exports, checkpoints []string, optsPtr *OSBu
8487
// Note that osbuild returns non-zero when the pipeline fails. This function
8588
// does not return an error in this case. Instead, the failure is communicated
8689
// with its corresponding logs through osbuild.Result.
87-
func RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.Writer, optsPtr *OSBuildOptions) (*Result, error) {
90+
func RunOSBuild(manifest []byte, errorWriter io.Writer, optsPtr *OSBuildOptions) (*Result, error) {
8891
opts := common.ValueOrEmpty(optsPtr)
8992

9093
if err := CheckMinimumOSBuildVersion(); err != nil {
@@ -93,7 +96,7 @@ func RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.W
9396

9497
var stdoutBuffer bytes.Buffer
9598
var res Result
96-
cmd := NewOSBuildCmd(manifest, exports, checkpoints, &opts)
99+
cmd := NewOSBuildCmd(manifest, &opts)
97100

98101
if opts.JSONOutput {
99102
cmd.Stdout = &stdoutBuffer
@@ -106,8 +109,8 @@ func RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.W
106109
if err != nil {
107110
return nil, fmt.Errorf("error starting osbuild: %v", err)
108111
}
109-
110112
err = cmd.Wait()
113+
111114
if opts.JSONOutput {
112115
// try to decode the output even though the job could have failed
113116
if stdoutBuffer.Len() == 0 {

pkg/osbuild/osbuild-exec_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func makeFakeOsbuild(t *testing.T, content string) string {
2222

2323
func TestNewOSBuildCmdNilOptions(t *testing.T) {
2424
mf := []byte(`{"real": "manifest"}`)
25-
cmd := osbuild.NewOSBuildCmd(mf, nil, nil, nil)
25+
cmd := osbuild.NewOSBuildCmd(mf, nil)
2626
assert.NotNil(t, cmd)
2727

2828
assert.Equal(
@@ -48,17 +48,14 @@ func TestNewOSBuildCmdFullOptions(t *testing.T) {
4848
mf := []byte(`{"real": "manifest"}`)
4949
cmd := osbuild.NewOSBuildCmd(
5050
mf,
51-
[]string{
52-
"export-1",
53-
"export-2",
54-
},
55-
[]string{
56-
"checkpoint-1",
57-
"checkpoint-2",
58-
},
5951
&osbuild.OSBuildOptions{
60-
StoreDir: "store",
61-
OutputDir: "output",
52+
StoreDir: "store",
53+
OutputDir: "output",
54+
Exports: []string{
55+
"export-1",
56+
"export-2",
57+
},
58+
Checkpoints: []string{"checkpoint-1", "checkpoint-2"},
6259
ExtraEnv: []string{"EXTRA_ENV_1=1", "EXTRA_ENV_2=2"},
6360
Monitor: osbuild.MonitorLog,
6461
MonitorFD: 10,
@@ -115,7 +112,7 @@ fi
115112
opts := &osbuild.OSBuildOptions{
116113
JSONOutput: true,
117114
}
118-
result, err := osbuild.RunOSBuild([]byte(`{"fake":"manifest"}`), nil, nil, nil, opts)
115+
result, err := osbuild.RunOSBuild([]byte(`{"fake":"manifest"}`), nil, opts)
119116
assert.NoError(t, err)
120117
assert.NotNil(t, result)
121118
assert.True(t, result.Success)

0 commit comments

Comments
 (0)