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`.
This commit is contained in:
parent
fc1d1c3b8f
commit
aa3d70a429
4 changed files with 44 additions and 12 deletions
|
|
@ -526,7 +526,16 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
||||||
exportPaths = append(exportPaths, path.Join(jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename))
|
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
|
// First handle the case when "running" osbuild failed
|
||||||
if err != nil {
|
if err != nil {
|
||||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, "osbuild build failed", err.Error())
|
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, "osbuild build failed", err.Error())
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,19 @@ import (
|
||||||
"github.com/osbuild/images/pkg/osbuild"
|
"github.com/osbuild/images/pkg/osbuild"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Executor interface {
|
type OsbuildOpts struct {
|
||||||
RunOSBuild(manifest []byte, store, outputDirectory string, exports, exportPaths, checkpoints, extraEnv []string, result bool, errorWriter io.Writer) (*osbuild.Result, error)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,12 @@ type awsEC2Executor struct {
|
||||||
|
|
||||||
func prepareSources(manifest []byte, store string, extraEnv []string, result bool, errorWriter io.Writer) error {
|
func prepareSources(manifest []byte, store string, extraEnv []string, result bool, errorWriter io.Writer) error {
|
||||||
hostExecutor := NewHostExecutor()
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,10 +248,12 @@ func extractOutputArchive(outputDirectory, outputTar string) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, store, outputDirectory string, exports, exportPaths, checkpoints,
|
func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, opts *OsbuildOpts, errorWriter io.Writer) (*osbuild.Result, error) {
|
||||||
extraEnv []string, result bool, 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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to prepare sources: %w", err)
|
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")
|
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 {
|
if err != nil {
|
||||||
logrus.Errorf("Unable to write input archive: %v", err)
|
logrus.Errorf("Unable to write input archive: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -301,7 +308,7 @@ func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, store, outputDirectory s
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = extractOutputArchive(outputDirectory, outputArchive)
|
err = extractOutputArchive(opts.OutputDir, outputArchive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Unable to extract executor output: %v", err)
|
logrus.Errorf("Unable to extract executor output: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,12 @@ import (
|
||||||
|
|
||||||
type hostExecutor struct{}
|
type hostExecutor struct{}
|
||||||
|
|
||||||
func (he *hostExecutor) RunOSBuild(manifest []byte, store, outputDirectory string, exports, exportPaths, checkpoints,
|
func (he *hostExecutor) RunOSBuild(manifest []byte, opts *OsbuildOpts, errorWriter io.Writer) (*osbuild.Result, error) {
|
||||||
extraEnv []string, result bool, errorWriter io.Writer) (*osbuild.Result, error) {
|
if opts == nil {
|
||||||
return osbuild.RunOSBuild(manifest, store, outputDirectory, exports, checkpoints, extraEnv, result, errorWriter)
|
opts = &OsbuildOpts{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return osbuild.RunOSBuild(manifest, opts.StoreDir, opts.OutputDir, opts.Exports, opts.Checkpoints, opts.ExtraEnv, opts.Result, errorWriter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHostExecutor() Executor {
|
func NewHostExecutor() Executor {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue