From 2cce81093f405787ccf98f9c8619c9837c6a8ef1 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Sat, 20 Feb 2021 19:12:10 +0100 Subject: [PATCH] osbuld-worker: call osbuild with --export flag osbuild now supports using the `--export` flag (can be invoked multiple times) to request the exporting of one or more artefacts. Omitting it causes the build job to export nothing. The Koji API doesn't support the new image types (yet) so it simply uses the "assembler" name, which is the final stage of the old (v1) Manifests. --- cmd/osbuild-worker/jobimpl-osbuild-koji.go | 3 ++- cmd/osbuild-worker/jobimpl-osbuild.go | 10 +++++++--- cmd/osbuild-worker/osbuild.go | 6 +++++- internal/weldr/api.go | 2 ++ internal/worker/json.go | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd/osbuild-worker/jobimpl-osbuild-koji.go b/cmd/osbuild-worker/jobimpl-osbuild-koji.go index 545546bfa..e23ee46fb 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild-koji.go +++ b/cmd/osbuild-worker/jobimpl-osbuild-koji.go @@ -85,8 +85,9 @@ func (impl *OSBuildKojiJobImpl) Run(job worker.Job) error { return err } + exports := []string{"assembler"} // NOTE: Koji API doesn't support new image types yet if initArgs.KojiError == "" { - result.OSBuildOutput, err = RunOSBuild(args.Manifest, impl.Store, outputDirectory, os.Stderr) + result.OSBuildOutput, err = RunOSBuild(args.Manifest, impl.Store, outputDirectory, exports, os.Stderr) if err != nil { return err } diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index 0bae9280c..3256a9ee9 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -89,7 +89,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { start_time := time.Now() - osbuildOutput, err := RunOSBuild(args.Manifest, impl.Store, outputDirectory, os.Stderr) + osbuildOutput, err := RunOSBuild(args.Manifest, impl.Store, outputDirectory, args.Exports, os.Stderr) if err != nil { return err } @@ -98,9 +98,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { streamOptimizedPath := "" + // NOTE: Currently OSBuild supports multiple exports, but this isn't used + // by any of the image types and it can't be specified during the request. + // Use the first (and presumably only) export for the imagePath. + exportPath := args.Exports[0] if osbuildOutput.Success && args.ImageName != "" { var f *os.File - imagePath := path.Join(outputDirectory, args.ImageName) + imagePath := path.Join(outputDirectory, exportPath, args.ImageName) if args.StreamOptimized { f, err = vmware.OpenAsStreamOptimizedVmdk(imagePath) if err != nil { @@ -129,7 +133,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { continue } var f *os.File - imagePath := path.Join(outputDirectory, options.Filename) + imagePath := path.Join(outputDirectory, exportPath, options.Filename) if options.StreamOptimized { f, err = vmware.OpenAsStreamOptimizedVmdk(imagePath) if err != nil { diff --git a/cmd/osbuild-worker/osbuild.go b/cmd/osbuild-worker/osbuild.go index 780fda30f..3e61e328c 100644 --- a/cmd/osbuild-worker/osbuild.go +++ b/cmd/osbuild-worker/osbuild.go @@ -16,13 +16,17 @@ import ( // Note that osbuild returns non-zero when the pipeline fails. This function // does not return an error in this case. Instead, the failure is communicated // with its corresponding logs through osbuild.Result. -func RunOSBuild(manifest distro.Manifest, store, outputDirectory string, errorWriter io.Writer) (*osbuild.Result, error) { +func RunOSBuild(manifest distro.Manifest, store, outputDirectory string, exports []string, errorWriter io.Writer) (*osbuild.Result, error) { cmd := exec.Command( "osbuild", "--store", store, "--output-directory", outputDirectory, "--json", "-", ) + + for _, export := range exports { + cmd.Args = append(cmd.Args, "--export", export) + } cmd.Stderr = errorWriter stdin, err := cmd.StdinPipe() diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 8a721c7e2..0e27ced0e 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -256,6 +256,7 @@ func (api *API) getComposeStatus(compose store.Compose) *composeStatus { if err != nil { panic(err) } + return &composeStatus{ State: composeStateFromJobStatus(jobStatus, &result), Queued: jobStatus.Queued, @@ -2024,6 +2025,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request Targets: targets, ImageName: imageType.Filename(), StreamOptimized: imageType.Name() == "vmdk", // https://github.com/osbuild/osbuild/issues/528 + Exports: imageType.Exports(), }) if err == nil { err = api.store.PushCompose(composeID, manifest, imageType, bp, size, targets, jobId) diff --git a/internal/worker/json.go b/internal/worker/json.go index 5b3f443de..753731852 100644 --- a/internal/worker/json.go +++ b/internal/worker/json.go @@ -18,6 +18,7 @@ type OSBuildJob struct { Targets []*target.Target `json:"targets,omitempty"` ImageName string `json:"image_name,omitempty"` StreamOptimized bool `json:"stream_optimized,omitempty"` + Exports []string `json:"export_stages,omitempty"` } type OSBuildJobResult struct {