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).
This commit is contained in:
David Rheinsberg 2020-05-11 09:14:17 +02:00 committed by Ondřej Budai
parent ccdc4b62f4
commit fdd7536152
2 changed files with 9 additions and 9 deletions

View file

@ -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,
)

View file

@ -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