worker: add new container resolve job type
This is a new job that can be used to resolve containers. It uses the existing `container.Resolver` class to do the actual work.
This commit is contained in:
parent
c2f3f76d96
commit
50e630a76f
5 changed files with 115 additions and 8 deletions
59
cmd/osbuild-worker/jobimpl-container-resolve.go
Normal file
59
cmd/osbuild-worker/jobimpl-container-resolve.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/container"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
|
||||
)
|
||||
|
||||
type ContainerResolveJobImpl struct {
|
||||
AuthFilePath string
|
||||
}
|
||||
|
||||
func (impl *ContainerResolveJobImpl) Run(job worker.Job) error {
|
||||
logWithId := logrus.WithField("jobId", job.Id())
|
||||
var args worker.ContainerResolveJob
|
||||
err := job.Args(&args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result := worker.ContainerResolveJobResult{
|
||||
Specs: make([]worker.ContainerSpec, len(args.Specs)),
|
||||
}
|
||||
|
||||
logWithId.Infof("Resolving containers (%d)", len(args.Specs))
|
||||
|
||||
resolver := container.NewResolver(args.Arch)
|
||||
|
||||
for _, s := range args.Specs {
|
||||
resolver.Add(s.Source, s.Name, s.TLSVerify)
|
||||
}
|
||||
|
||||
specs, err := resolver.Finish()
|
||||
|
||||
if err != nil {
|
||||
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorContainerResolution, err.Error())
|
||||
} else {
|
||||
for i, spec := range specs {
|
||||
result.Specs[i] = worker.ContainerSpec{
|
||||
Source: spec.Source,
|
||||
Name: spec.LocalName,
|
||||
TLSVerify: spec.TLSVerify,
|
||||
ImageID: spec.ImageID,
|
||||
Digest: spec.Digest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = job.Update(&result)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reporting job result: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -434,9 +434,7 @@ func main() {
|
|||
worker.JobTypeKojiInit: &KojiInitJobImpl{
|
||||
KojiServers: kojiServers,
|
||||
},
|
||||
worker.JobTypeKojiFinalize: &KojiFinalizeJobImpl{
|
||||
KojiServers: kojiServers,
|
||||
},
|
||||
worker.JobTypeKojiFinalize: &KojiFinalizeJobImpl{},
|
||||
}
|
||||
|
||||
acceptedJobTypes := []string{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue