osbuildexecutor: introduce osbuildexecutor.Executor interface
Wrap the current osbuildexecutor.Executor in an interface so it's easier to add different executors, which for instance can run osbuild in a VM.
This commit is contained in:
parent
9e85050633
commit
e10424de2f
4 changed files with 51 additions and 3 deletions
|
|
@ -28,6 +28,7 @@ import (
|
|||
|
||||
"github.com/osbuild/osbuild-composer/internal/cloud/awscloud"
|
||||
"github.com/osbuild/osbuild-composer/internal/cloud/gcp"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuildexecutor"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/azure"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/koji"
|
||||
|
|
@ -75,9 +76,15 @@ type PulpConfiguration struct {
|
|||
ServerAddress string
|
||||
}
|
||||
|
||||
type ExecutorConfiguration struct {
|
||||
Type string
|
||||
IAMProfile string
|
||||
}
|
||||
|
||||
type OSBuildJobImpl struct {
|
||||
Store string
|
||||
Output string
|
||||
OSBuildExecutor ExecutorConfiguration
|
||||
KojiServers map[string]kojiServer
|
||||
GCPConfig GCPConfiguration
|
||||
AzureConfig AzureConfiguration
|
||||
|
|
@ -476,7 +483,16 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
}
|
||||
|
||||
// Run osbuild and handle two kinds of errors
|
||||
osbuildJobResult.OSBuildOutput, err = osbuild.RunOSBuild(jobArgs.Manifest, impl.Store, outputDirectory, exports, nil, extraEnv, true, os.Stderr)
|
||||
var executor osbuildexecutor.Executor
|
||||
switch impl.OSBuildExecutor.Type {
|
||||
case "host":
|
||||
executor = osbuildexecutor.NewHostExecutor()
|
||||
default:
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, "No osbuild executor defined", nil)
|
||||
return err
|
||||
}
|
||||
|
||||
osbuildJobResult.OSBuildOutput, err = executor.RunOSBuild(jobArgs.Manifest, impl.Store, outputDirectory, exports, nil, extraEnv, true, os.Stderr)
|
||||
// First handle the case when "running" osbuild failed
|
||||
if err != nil {
|
||||
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, "osbuild build failed", err)
|
||||
|
|
|
|||
|
|
@ -471,8 +471,11 @@ func main() {
|
|||
// non-depsolve job
|
||||
jobImpls := map[string]JobImplementation{
|
||||
worker.JobTypeOSBuild: &OSBuildJobImpl{
|
||||
Store: store,
|
||||
Output: output,
|
||||
Store: store,
|
||||
Output: output,
|
||||
OSBuildExecutor: ExecutorConfiguration{
|
||||
Type: config.OSBuildExecutor.Type,
|
||||
},
|
||||
KojiServers: kojiServers,
|
||||
GCPConfig: gcpConfig,
|
||||
AzureConfig: azureConfig,
|
||||
|
|
|
|||
11
internal/osbuildexecutor/osbuild-executor.go
Normal file
11
internal/osbuildexecutor/osbuild-executor.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package osbuildexecutor
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/osbuild/images/pkg/osbuild"
|
||||
)
|
||||
|
||||
type Executor interface {
|
||||
RunOSBuild(manifest []byte, store, outputDirectory string, exports, checkpoints, extraEnv []string, result bool, errorWriter io.Writer) (*osbuild.Result, error)
|
||||
}
|
||||
18
internal/osbuildexecutor/runner-impl-host.go
Normal file
18
internal/osbuildexecutor/runner-impl-host.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package osbuildexecutor
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/osbuild/images/pkg/osbuild"
|
||||
)
|
||||
|
||||
type hostExecutor struct{}
|
||||
|
||||
func (he *hostExecutor) RunOSBuild(manifest []byte, store, outputDirectory string, exports, checkpoints,
|
||||
extraEnv []string, result bool, errorWriter io.Writer) (*osbuild.Result, error) {
|
||||
return osbuild.RunOSBuild(manifest, store, outputDirectory, exports, checkpoints, extraEnv, result, errorWriter)
|
||||
}
|
||||
|
||||
func NewHostExecutor() Executor {
|
||||
return &hostExecutor{}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue