From fdd7536152a91aea0abd724eeaed16be7fb9c86a Mon Sep 17 00:00:00 2001 From: David Rheinsberg Date: Mon, 11 May 2020 09:14:17 +0200 Subject: [PATCH] worker: switch to `--output-directory=DIR` Since 2 releases `osbuild` accepts an `--output-directory=DIR` argument which lets us decide where to place generated artifacts. Switch over to it, rather than digging into the store, to make sure we will not access the osbuild store when parallel cleanups are ongoing (which are not yet a thing, though). --- cmd/osbuild-worker/main.go | 14 +++++++------- cmd/osbuild-worker/osbuild.go | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/osbuild-worker/main.go b/cmd/osbuild-worker/main.go index ce1c856cf..d80cf65f7 100644 --- a/cmd/osbuild-worker/main.go +++ b/cmd/osbuild-worker/main.go @@ -64,14 +64,14 @@ func (e *TargetsError) Error() string { } func RunJob(job *worker.Job, uploadFunc func(uuid.UUID, int, io.Reader) error) (*common.ComposeResult, error) { - tmpStore, err := ioutil.TempDir("/var/tmp", "osbuild-store") + tmpOutput, err := ioutil.TempDir("/var/tmp", "osbuild-output-*") if err != nil { - return nil, fmt.Errorf("error setting up osbuild store: %v", err) + return nil, fmt.Errorf("error setting up osbuild output directory: %v", err) } // FIXME: how to handle errors in defer? - defer os.RemoveAll(tmpStore) + defer os.RemoveAll(tmpOutput) - result, err := RunOSBuild(job.Manifest, tmpStore, os.Stderr) + result, err := RunOSBuild(job.Manifest, tmpOutput, os.Stderr) if err != nil { return nil, err } @@ -81,7 +81,7 @@ func RunJob(job *worker.Job, uploadFunc func(uuid.UUID, int, io.Reader) error) ( for _, t := range job.Targets { switch options := t.Options.(type) { case *target.LocalTargetOptions: - f, err := os.Open(path.Join(tmpStore, "refs", result.OutputID, options.Filename)) + f, err := os.Open(path.Join(tmpOutput, options.Filename)) if err != nil { r = append(r, err) continue @@ -105,7 +105,7 @@ func RunJob(job *worker.Job, uploadFunc func(uuid.UUID, int, io.Reader) error) ( options.Key = job.Id.String() } - _, err = a.Upload(path.Join(tmpStore, "refs", result.OutputID, options.Filename), options.Bucket, options.Key) + _, err = a.Upload(path.Join(tmpOutput, options.Filename), options.Bucket, options.Key) if err != nil { r = append(r, err) continue @@ -132,7 +132,7 @@ func RunJob(job *worker.Job, uploadFunc func(uuid.UUID, int, io.Reader) error) ( err := azure.UploadImage( credentials, metadata, - path.Join(tmpStore, "refs", result.OutputID, options.Filename), + path.Join(tmpOutput, options.Filename), azureMaxUploadGoroutines, ) diff --git a/cmd/osbuild-worker/osbuild.go b/cmd/osbuild-worker/osbuild.go index b8a32da21..2da5dd167 100644 --- a/cmd/osbuild-worker/osbuild.go +++ b/cmd/osbuild-worker/osbuild.go @@ -19,10 +19,10 @@ func (e *OSBuildError) Error() string { return e.Message } -func RunOSBuild(manifest *osbuild.Manifest, store string, errorWriter io.Writer) (*common.ComposeResult, error) { +func RunOSBuild(manifest *osbuild.Manifest, outputDirectory string, errorWriter io.Writer) (*common.ComposeResult, error) { cmd := exec.Command( "osbuild", - "--store", store, + "--output-directory", outputDirectory, "--json", "-", ) cmd.Stderr = errorWriter