Skip to content

Commit 66c856d

Browse files
committed
wip: executor with logging
1 parent ee20f76 commit 66c856d

File tree

22 files changed

+748
-59
lines changed

22 files changed

+748
-59
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())

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,5 @@ require (
237237
gopkg.in/yaml.v2 v2.4.0 // indirect
238238
gopkg.in/yaml.v3 v3.0.1 // indirect
239239
)
240+
241+
replace github.com/osbuild/images => github.com/croissanne/images v0.0.0-20251027100746-72ef9ec548c0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5z
171171
github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU=
172172
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
173173
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
174+
github.com/croissanne/images v0.0.0-20251027100746-72ef9ec548c0 h1:OZKU0+4qnZAQG0ggWNv/wtHrZn+EWpSBqLCwDQhBWbo=
175+
github.com/croissanne/images v0.0.0-20251027100746-72ef9ec548c0/go.mod h1:tZqcrs3eNUA0VPs1h3YCnbnpAskVVfo36CIi2USSfDs=
174176
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 h1:uX1JmpONuD549D73r6cgnxyUu18Zb7yHAy5AYU0Pm4Q=
175177
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467/go.mod h1:uzvlm1mxhHkdfqitSA92i7Se+S9ksOn3a3qmv/kyOCw=
176178
github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s=
@@ -520,8 +522,6 @@ github.com/oracle/oci-go-sdk/v54 v54.0.0 h1:CDLjeSejv2aDpElAJrhKpi6zvT/zhZCZuXch
520522
github.com/oracle/oci-go-sdk/v54 v54.0.0/go.mod h1:+t+yvcFGVp+3ZnztnyxqXfQDsMlq8U25faBLa+mqCMc=
521523
github.com/osbuild/blueprint v1.16.0 h1:f/kHih+xpeJ1v7wtIfzdHPZTsiXsqKeDQ1+rrue6298=
522524
github.com/osbuild/blueprint v1.16.0/go.mod h1:HPlJzkEl7q5g8hzaGksUk7ifFAy9QFw9LmzhuFOAVm4=
523-
github.com/osbuild/images v0.209.0 h1:9BRf+N0op1WbQkc+7zVRBZxg4dqS4lty3i2stF3G9lo=
524-
github.com/osbuild/images v0.209.0/go.mod h1:tZqcrs3eNUA0VPs1h3YCnbnpAskVVfo36CIi2USSfDs=
525525
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d h1:r9BFPDv0uuA9k1947Jybcxs36c/pTywWS1gjeizvtcQ=
526526
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d/go.mod h1:zR1iu/hOuf+OQNJlk70tju9IqzzM4ycq0ectkFBm94U=
527527
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=

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 {

vendor/github.com/osbuild/images/data/distrodefs/fedora/imagetypes.yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/osbuild/images/pkg/bib/osinfo/osinfo.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/osbuild/images/pkg/distro/bootc/bootc.go

Lines changed: 7 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)