From aa3d70a42950eb222efa3a7b1778e7ea181187c8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 13 Jun 2024 16:56:12 +0200 Subject: [PATCH] osbuildexecutor: tweak `RunOSBuild()` signature and use opts Introduce a new OsbuildOpts struct to make the API a bit easier to extend and use in the packages. Also add a new `JobID` field in the `OsbuildOpts`. --- cmd/osbuild-worker/jobimpl-osbuild.go | 11 ++++++++++- internal/osbuildexecutor/osbuild-executor.go | 17 +++++++++++++++-- .../osbuildexecutor/runner-impl-aws-ec2.go | 19 +++++++++++++------ internal/osbuildexecutor/runner-impl-host.go | 9 ++++++--- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index e066eb0cb..98945de0b 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -526,7 +526,16 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { exportPaths = append(exportPaths, path.Join(jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename)) } - osbuildJobResult.OSBuildOutput, err = executor.RunOSBuild(jobArgs.Manifest, impl.Store, outputDirectory, exports, exportPaths, nil, extraEnv, true, os.Stderr) + opts := &osbuildexecutor.OsbuildOpts{ + StoreDir: impl.Store, + OutputDir: outputDirectory, + Exports: exports, + ExportPaths: exportPaths, + ExtraEnv: extraEnv, + Result: true, + JobID: job.Id().String(), + } + osbuildJobResult.OSBuildOutput, err = executor.RunOSBuild(jobArgs.Manifest, opts, os.Stderr) // First handle the case when "running" osbuild failed if err != nil { osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, "osbuild build failed", err.Error()) diff --git a/internal/osbuildexecutor/osbuild-executor.go b/internal/osbuildexecutor/osbuild-executor.go index 136b51425..9748d1e42 100644 --- a/internal/osbuildexecutor/osbuild-executor.go +++ b/internal/osbuildexecutor/osbuild-executor.go @@ -6,6 +6,19 @@ import ( "github.com/osbuild/images/pkg/osbuild" ) -type Executor interface { - RunOSBuild(manifest []byte, store, outputDirectory string, exports, exportPaths, checkpoints, extraEnv []string, result bool, errorWriter io.Writer) (*osbuild.Result, error) +type OsbuildOpts struct { + StoreDir string + OutputDir string + Exports []string + ExportPaths []string + Checkpoints []string + ExtraEnv []string + Result bool + + // not strict a osbuild opt + JobID string +} + +type Executor interface { + RunOSBuild(manifest []byte, opts *OsbuildOpts, errorWriter io.Writer) (*osbuild.Result, error) } diff --git a/internal/osbuildexecutor/runner-impl-aws-ec2.go b/internal/osbuildexecutor/runner-impl-aws-ec2.go index a68d8ea54..be23de914 100644 --- a/internal/osbuildexecutor/runner-impl-aws-ec2.go +++ b/internal/osbuildexecutor/runner-impl-aws-ec2.go @@ -30,7 +30,12 @@ type awsEC2Executor struct { func prepareSources(manifest []byte, store string, extraEnv []string, result bool, errorWriter io.Writer) error { hostExecutor := NewHostExecutor() - _, err := hostExecutor.RunOSBuild(manifest, store, "", nil, nil, nil, extraEnv, result, errorWriter) + opts := &OsbuildOpts{ + StoreDir: store, + ExtraEnv: extraEnv, + Result: result, + } + _, err := hostExecutor.RunOSBuild(manifest, opts, errorWriter) return err } @@ -243,10 +248,12 @@ func extractOutputArchive(outputDirectory, outputTar string) error { } -func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, store, outputDirectory string, exports, exportPaths, checkpoints, - extraEnv []string, result bool, errorWriter io.Writer) (*osbuild.Result, error) { +func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, opts *OsbuildOpts, errorWriter io.Writer) (*osbuild.Result, error) { + if opts == nil { + opts = &OsbuildOpts{} + } - err := prepareSources(manifest, store, extraEnv, result, errorWriter) + err := prepareSources(manifest, opts.StoreDir, opts.ExtraEnv, opts.Result, errorWriter) if err != nil { return nil, fmt.Errorf("Failed to prepare sources: %w", err) } @@ -280,7 +287,7 @@ func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, store, outputDirectory s return nil, fmt.Errorf("Timeout waiting for executor to come online") } - inputArchive, err := writeInputArchive(ec2e.tmpDir, store, exports, manifest) + inputArchive, err := writeInputArchive(ec2e.tmpDir, opts.StoreDir, opts.Exports, manifest) if err != nil { logrus.Errorf("Unable to write input archive: %v", err) return nil, err @@ -301,7 +308,7 @@ func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, store, outputDirectory s return nil, err } - err = extractOutputArchive(outputDirectory, outputArchive) + err = extractOutputArchive(opts.OutputDir, outputArchive) if err != nil { logrus.Errorf("Unable to extract executor output: %v", err) return nil, err diff --git a/internal/osbuildexecutor/runner-impl-host.go b/internal/osbuildexecutor/runner-impl-host.go index 8b6d839a8..5fa26cbfb 100644 --- a/internal/osbuildexecutor/runner-impl-host.go +++ b/internal/osbuildexecutor/runner-impl-host.go @@ -8,9 +8,12 @@ import ( type hostExecutor struct{} -func (he *hostExecutor) RunOSBuild(manifest []byte, store, outputDirectory string, exports, exportPaths, checkpoints, - extraEnv []string, result bool, errorWriter io.Writer) (*osbuild.Result, error) { - return osbuild.RunOSBuild(manifest, store, outputDirectory, exports, checkpoints, extraEnv, result, errorWriter) +func (he *hostExecutor) RunOSBuild(manifest []byte, opts *OsbuildOpts, errorWriter io.Writer) (*osbuild.Result, error) { + if opts == nil { + opts = &OsbuildOpts{} + } + + return osbuild.RunOSBuild(manifest, opts.StoreDir, opts.OutputDir, opts.Exports, opts.Checkpoints, opts.ExtraEnv, opts.Result, errorWriter) } func NewHostExecutor() Executor {