cloudapi: multiple upload targets in request

Add an array of targets in the imageRequest and return an array from
ImageRequest.GetTargets() (renamed from GetTarget()).  Currently, the
function still only returns one target, the default for the image type
with the top level upload options.
This commit is contained in:
Achilleas Koutsou 2023-10-23 18:51:43 +02:00 committed by Sanne Raymaekers
parent 9d990ea5da
commit d7ab1f2112
3 changed files with 17 additions and 15 deletions

View file

@ -139,7 +139,7 @@ type imageRequest struct {
arch distro.Arch
repositories []rpmmd.RepoConfig
imageOptions distro.ImageOptions
target *target.Target
targets []*target.Target
}
func (h *apiHandlers) PostCompose(ctx echo.Context) error {
@ -236,7 +236,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
return err
}
var irTarget *target.Target
var irTargets []*target.Target
if ir.UploadOptions == nil {
// nowhere to put the image, this is a user error
if request.Koji == nil {
@ -245,13 +245,14 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
} else if localSave {
// Override the image type upload selection and save it locally
// Final image is in /var/lib/osbuild-composer/artifacts/UUID/
irTarget = target.NewWorkerServerTarget()
irTarget.ImageName = imageType.Filename()
irTarget.OsbuildArtifact.ExportFilename = imageType.Filename()
irTarget.OsbuildArtifact.ExportName = imageType.Exports()[0]
srvTarget := target.NewWorkerServerTarget()
srvTarget.ImageName = imageType.Filename()
srvTarget.OsbuildArtifact.ExportFilename = imageType.Filename()
srvTarget.OsbuildArtifact.ExportName = imageType.Exports()[0]
irTargets = []*target.Target{srvTarget}
} else {
// Get the target for the selected image type
irTarget, err = ir.GetTarget(&request, imageType)
irTargets, err = ir.GetTargets(&request, imageType)
if err != nil {
return err
}
@ -262,7 +263,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
arch: arch,
repositories: repos,
imageOptions: imageOptions,
target: irTarget,
targets: irTargets,
})
}

View file

@ -283,8 +283,9 @@ func getDefaultTarget(imageType ImageTypes) (UploadTypes, error) {
}
}
// GetTarget returns the target for the selected image type.
func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.ImageType) (irTarget *target.Target, err error) {
// GetTargets returns all the targets for image request.
func (ir *ImageRequest) GetTargets(request *ComposeRequest, imageType distro.ImageType) ([]*target.Target, error) {
var irTarget *target.Target
uploadTarget, err := getDefaultTarget(ir.ImageType)
if err != nil {
return nil, err
@ -316,7 +317,7 @@ func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.Imag
}
irTarget.OsbuildArtifact.ExportName = imageType.Exports()[0]
return irTarget, nil
return []*target.Target{irTarget}, nil
}
// GetOSTreeOptions returns the image ostree options when included in the request

View file

@ -203,7 +203,7 @@ func (s *Server) enqueueCompose(distribution distro.Distro, bp blueprint.Bluepri
}
id, err = s.workers.EnqueueOSBuildAsDependency(ir.arch.Name(), &worker.OSBuildJob{
Targets: []*target.Target{ir.target},
Targets: ir.targets,
PipelineNames: &worker.PipelineNames{
Build: ir.imageType.BuildPipelines(),
Payload: ir.imageType.PayloadPipelines(),
@ -341,9 +341,9 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas
kojiTarget.ImageName = kojiFilename
targets := []*target.Target{kojiTarget}
// add any cloud upload target if defined
if ir.target != nil {
targets = append(targets, ir.target)
// add any cloud upload targets if defined
if ir.targets != nil {
targets = append(targets, ir.targets...)
}
buildID, err := s.workers.EnqueueOSBuildAsDependency(ir.arch.Name(), &worker.OSBuildJob{