Skip to content

Commit 854dd7b

Browse files
committed
wip: executor with logging
1 parent ee20f76 commit 854dd7b

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

cmd/osbuild-worker/jobimpl-osbuild.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
525525
ExtraEnv: extraEnv,
526526
JSONOutput: true,
527527
}
528-
osbuildJobResult.OSBuildOutput, err = executor.RunOSBuild(jobArgs.Manifest, exports, nil, os.Stderr, opts)
528+
osbuildJobResult.OSBuildOutput, err = executor.RunOSBuild(jobArgs.Manifest, exports, nil, os.Stderr, logWithId, opts)
529529
// First handle the case when "running" osbuild failed
530530
if err != nil {
531531
osbuildJobResult.JobError = clienterrors.New(clienterrors.ErrorBuildJob, "osbuild build failed", err.Error())

internal/osbuildexecutor/osbuild-executor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package osbuildexecutor
33
import (
44
"io"
55

6+
"github.com/sirupsen/logrus"
7+
68
"github.com/osbuild/images/pkg/osbuild"
79
)
810

911
type Executor interface {
10-
RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.Writer, opts *osbuild.OSBuildOptions) (*osbuild.Result, error)
12+
RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.Writer, logger *logrus.Entry, opts *osbuild.OSBuildOptions) (*osbuild.Result, error)
1113
}

internal/osbuildexecutor/runner-impl-aws-ec2.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
"strings"
1414
"time"
1515

16+
"github.com/sirupsen/logrus"
1617
"golang.org/x/exp/slices"
1718

1819
"github.com/osbuild/images/pkg/osbuild"
19-
"github.com/sirupsen/logrus"
2020

2121
"github.com/osbuild/osbuild-composer/internal/cloud/awscloud"
2222
)
@@ -28,9 +28,9 @@ type awsEC2Executor struct {
2828
tmpDir string
2929
}
3030

31-
func prepareSources(manifest []byte, errorWriter io.Writer, opts *osbuild.OSBuildOptions) error {
31+
func prepareSources(manifest []byte, errorWriter io.Writer, logger *logrus.Entry, opts *osbuild.OSBuildOptions) error {
3232
hostExecutor := NewHostExecutor()
33-
_, err := hostExecutor.RunOSBuild(manifest, nil, nil, errorWriter, opts)
33+
_, err := hostExecutor.RunOSBuild(manifest, nil, nil, errorWriter, logger, opts)
3434
return err
3535
}
3636

@@ -243,8 +243,8 @@ func extractOutputArchive(outputDirectory, outputTar string) error {
243243

244244
}
245245

246-
func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.Writer, opts *osbuild.OSBuildOptions) (*osbuild.Result, error) {
247-
err := prepareSources(manifest, errorWriter, opts)
246+
func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.Writer, logger *logrus.Entry, opts *osbuild.OSBuildOptions) (*osbuild.Result, error) {
247+
err := prepareSources(manifest, errorWriter, logger, opts)
248248
if err != nil {
249249
return nil, fmt.Errorf("Failed to prepare sources: %w", err)
250250
}

internal/osbuildexecutor/runner-impl-host.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
11
package osbuildexecutor
22

33
import (
4+
"fmt"
45
"io"
56

7+
"github.com/sirupsen/logrus"
8+
69
"github.com/osbuild/images/pkg/osbuild"
710
)
811

912
type hostExecutor struct{}
1013

11-
func (he *hostExecutor) RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.Writer, opts *osbuild.OSBuildOptions) (*osbuild.Result, error) {
12-
return osbuild.RunOSBuild(manifest, exports, checkpoints, errorWriter, opts)
14+
func (he *hostExecutor) RunOSBuild(manifest []byte, exports, checkpoints []string, errorWriter io.Writer, logger *logrus.Entry, opts *osbuild.OSBuildOptions) (*osbuild.Result, error) {
15+
opts.Monitor = osbuild.MonitorJSONSeq
16+
17+
cmd := osbuild.NewOSBuildCmd(manifest, exports, checkpoints, opts)
18+
stdOut, err := cmd.StdoutPipe()
19+
if err != nil {
20+
return nil, err
21+
}
22+
defer stdOut.Close()
23+
cmd.Stderr = errorWriter
24+
25+
osbuildStatus := osbuild.NewStatusScanner(stdOut)
26+
if err := cmd.Start(); err != nil {
27+
return nil, fmt.Errorf("error starting osbuild: %v", err)
28+
}
29+
for {
30+
st, err := osbuildStatus.Status()
31+
if err != nil {
32+
return nil, fmt.Errorf(`error parsing osbuild status, please report a bug: %w`, err)
33+
}
34+
if st == nil {
35+
break
36+
}
37+
38+
if st.Progress != nil {
39+
// TODO
40+
logger.Infof("%s (step %d out of %d)", st.Message, st.Progress.Done, st.Progress.Total)
41+
}
42+
}
43+
44+
if err := cmd.Wait(); err != nil {
45+
return nil, fmt.Errorf("error running osbuild: %w", err)
46+
}
47+
48+
result, err := osbuildStatus.Result()
49+
if err != nil {
50+
return nil, fmt.Errorf("unable to construct osbuild result: %w", err)
51+
}
52+
return result, nil
1353
}
1454

1555
func NewHostExecutor() Executor {

0 commit comments

Comments
 (0)