Skip to content

Commit

Permalink
cloudapi: move manifest seed into an image request
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ondrejbudai authored and thozza committed Feb 21, 2024
1 parent 7385cab commit 28ef0bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions internal/cloudapi/v2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type imageRequest struct {
imageOptions distro.ImageOptions
targets []*target.Target
blueprint blueprint.Blueprint
manifestSeed int64
}

func (h *apiHandlers) PostCompose(ctx echo.Context) error {
Expand Down Expand Up @@ -271,17 +272,18 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
imageOptions: imageOptions,
targets: irTargets,
blueprint: bp,
manifestSeed: manifestSeed,
})
}

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, manifestSeed, irs, channel)
id, err = h.server.enqueueKojiCompose(uint64(request.Koji.TaskId), request.Koji.Server, request.Koji.Name, request.Koji.Version, request.Koji.Release, irs, channel)
if err != nil {
return err
}
} else {
id, err = h.server.enqueueCompose(manifestSeed, irs, channel)
id, err = h.server.enqueueCompose(irs, channel)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions internal/cloudapi/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *Server) Shutdown() {
s.goroutinesGroup.Wait()
}

func (s *Server) enqueueCompose(manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) {
func (s *Server) enqueueCompose(irs []imageRequest, channel string) (uuid.UUID, error) {
var id uuid.UUID
if len(irs) != 1 {
return id, HTTPError(ErrorInvalidNumberOfImageBuilds)
Expand All @@ -129,7 +129,7 @@ func (s *Server) enqueueCompose(manifestSeed int64, irs []imageRequest, channel
arch := ir.imageType.Arch()
distribution := arch.Distro()

manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, manifestSeed)
manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, ir.manifestSeed)
if err != nil {
logrus.Warningf("ErrorEnqueueingJob, failed generating manifest: %v", err)
return id, HTTPErrorWithInternal(ErrorEnqueueingJob, err)
Expand Down Expand Up @@ -226,14 +226,14 @@ func (s *Server) enqueueCompose(manifestSeed int64, irs []imageRequest, channel

s.goroutinesGroup.Add(1)
go func() {
serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, manifestSeed)
serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, ir.manifestSeed)
defer s.goroutinesGroup.Done()
}()

return id, nil
}

func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, release string, manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) {
func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, release string, irs []imageRequest, channel string) (uuid.UUID, error) {
var id uuid.UUID
kojiDirectory := "osbuild-cg/osbuild-composer-koji-" + uuid.New().String()

Expand All @@ -256,7 +256,7 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas
arch := ir.imageType.Arch()
distribution := arch.Distro()

manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, manifestSeed)
manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, ir.manifestSeed)
if err != nil {
logrus.Errorf("ErrorEnqueueingJob, failed generating manifest: %v", err)
return id, HTTPErrorWithInternal(ErrorEnqueueingJob, err)
Expand Down Expand Up @@ -380,7 +380,7 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas
// copy the image request while passing it into the goroutine to prevent data races
s.goroutinesGroup.Add(1)
go func(ir imageRequest) {
serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, manifestSeed)
serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, ir.manifestSeed)
defer s.goroutinesGroup.Done()
}(ir)
}
Expand Down

0 comments on commit 28ef0bc

Please sign in to comment.