From 7385cab1656d2e82aa326e0abeb3621b6634d922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Fri, 16 Feb 2024 14:15:09 +0100 Subject: [PATCH] cloudapi: move blueprint into an image request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/cloudapi/v2/handler.go | 7 +++++-- internal/cloudapi/v2/server.go | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/cloudapi/v2/handler.go b/internal/cloudapi/v2/handler.go index 90c91de79..05d61f6ea 100644 --- a/internal/cloudapi/v2/handler.go +++ b/internal/cloudapi/v2/handler.go @@ -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 } diff --git a/internal/cloudapi/v2/server.go b/internal/cloudapi/v2/server.go index 53b798bcb..9c07ecce8 100644 --- a/internal/cloudapi/v2/server.go +++ b/internal/cloudapi/v2/server.go @@ -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)