cloudapi: move blueprint into an image request

The goal of this commit is primarily to simplify the API of the enqueue
methods. This way, basically everything needed to generate manifests
is in the imageRequest structure, which simplifies the amount of structures
that we need to think about.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2024-02-16 14:15:09 +01:00 committed by Tomáš Hozza
parent ab8c1ae4f7
commit 7385cab165
2 changed files with 10 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"math"
"math/big"
"net/http"
@ -139,6 +140,7 @@ type imageRequest struct {
repositories []rpmmd.RepoConfig
imageOptions distro.ImageOptions
targets []*target.Target
blueprint blueprint.Blueprint
}
func (h *apiHandlers) PostCompose(ctx echo.Context) error {
@ -268,17 +270,18 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
repositories: repos,
imageOptions: imageOptions,
targets: irTargets,
blueprint: bp,
})
}
var id uuid.UUID
if request.Koji != nil {
id, err = h.server.enqueueKojiCompose(uint64(request.Koji.TaskId), request.Koji.Server, request.Koji.Name, request.Koji.Version, request.Koji.Release, bp, manifestSeed, irs, channel)
id, err = h.server.enqueueKojiCompose(uint64(request.Koji.TaskId), request.Koji.Server, request.Koji.Name, request.Koji.Version, request.Koji.Release, manifestSeed, irs, channel)
if err != nil {
return err
}
} else {
id, err = h.server.enqueueCompose(bp, manifestSeed, irs, channel)
id, err = h.server.enqueueCompose(manifestSeed, irs, channel)
if err != nil {
return err
}

View file

@ -117,14 +117,14 @@ func (s *Server) Shutdown() {
s.goroutinesGroup.Wait()
}
func (s *Server) enqueueCompose(bp blueprint.Blueprint, manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) {
func (s *Server) enqueueCompose(manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) {
var id uuid.UUID
if len(irs) != 1 {
return id, HTTPError(ErrorInvalidNumberOfImageBuilds)
}
ir := irs[0]
ibp := blueprint.Convert(bp)
ibp := blueprint.Convert(ir.blueprint)
// shortcuts
arch := ir.imageType.Arch()
distribution := arch.Distro()
@ -233,7 +233,7 @@ func (s *Server) enqueueCompose(bp blueprint.Blueprint, manifestSeed int64, irs
return id, nil
}
func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, release string, bp blueprint.Blueprint, manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) {
func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, release string, manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) {
var id uuid.UUID
kojiDirectory := "osbuild-cg/osbuild-composer-koji-" + uuid.New().String()
@ -250,7 +250,7 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas
var kojiFilenames []string
var buildIDs []uuid.UUID
for _, ir := range irs {
ibp := blueprint.Convert(bp)
ibp := blueprint.Convert(ir.blueprint)
// shortcuts
arch := ir.imageType.Arch()
@ -296,7 +296,7 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas
job := worker.ContainerResolveJob{
Arch: arch.Name(),
Specs: make([]worker.ContainerSpec, len(bp.Containers)),
Specs: make([]worker.ContainerSpec, len(ir.blueprint.Containers)),
}
jobId, err := s.workers.EnqueueContainerResolveJob(&job, channel)