osbuild-worker: add ostree resolve job
This job resolves an ostree ref. Similar to the depsolve and container resolve jobs, this should be a dependency of a manifest job.
This commit is contained in:
parent
b01792d9dd
commit
ebeb339f96
6 changed files with 217 additions and 0 deletions
79
cmd/osbuild-worker/jobimpl-ostree-resolve.go
Normal file
79
cmd/osbuild-worker/jobimpl-ostree-resolve.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
|
||||
)
|
||||
|
||||
type OSTreeResolveJobImpl struct {
|
||||
}
|
||||
|
||||
func setError(err error, result *worker.OSTreeResolveJobResult) {
|
||||
switch err.(type) {
|
||||
case ostree.RefError:
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
clienterrors.ErrorOSTreeRefInvalid,
|
||||
"Invalid OSTree ref",
|
||||
err,
|
||||
)
|
||||
case ostree.ResolveRefError:
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
clienterrors.ErrorOSTreeRefResolution,
|
||||
"Error resolving OSTree ref",
|
||||
err,
|
||||
)
|
||||
default:
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
clienterrors.ErrorOSTreeParamsInvalid,
|
||||
"Invalid OSTree parameters or parameter combination",
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func (impl *OSTreeResolveJobImpl) Run(job worker.Job) error {
|
||||
logWithId := logrus.WithField("jobId", job.Id())
|
||||
var args worker.OSTreeResolveJob
|
||||
err := job.Args(&args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result := worker.OSTreeResolveJobResult{
|
||||
Specs: make([]worker.OSTreeResolveResultSpec, len(args.Specs)),
|
||||
}
|
||||
|
||||
logWithId.Infof("Resolving (%d) ostree commits", len(args.Specs))
|
||||
|
||||
for _, s := range args.Specs {
|
||||
reqParams := ostree.RequestParams{
|
||||
URL: s.URL,
|
||||
Ref: s.Ref,
|
||||
Parent: s.Parent,
|
||||
}
|
||||
|
||||
ref, checksum, err := ostree.ResolveParams(reqParams)
|
||||
if err != nil {
|
||||
setError(err, &result)
|
||||
break
|
||||
}
|
||||
|
||||
result.Specs = append(result.Specs, worker.OSTreeResolveResultSpec{
|
||||
URL: s.URL,
|
||||
Ref: ref,
|
||||
Checksum: checksum,
|
||||
})
|
||||
}
|
||||
|
||||
err = job.Update(&result)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reporting job result: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -465,6 +465,7 @@ func main() {
|
|||
worker.JobTypeContainerResolve: &ContainerResolveJobImpl{
|
||||
AuthFilePath: containersAuthFilePath,
|
||||
},
|
||||
worker.JobTypeOSTreeResolve: &OSTreeResolveJobImpl{},
|
||||
worker.JobTypeAWSEC2Copy: &AWSEC2CopyJobImpl{
|
||||
AWSCreds: awsCredentials,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue