From e5139054246abed214637221b6b18f5567789391 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 9 Feb 2021 16:11:20 +0000 Subject: [PATCH] cloudapi: add support for additional packages Optionally allow a pacakge set to be included in the compose request. The specified packages are added to the base packages before depsolving. As the base packages differ between the image types the package customizations may have different results on the different images part of the compose request. Signed-off-by: Tom Gundersen --- internal/cloudapi/openapi.gen.go | 1 + internal/cloudapi/openapi.yml | 5 +++++ internal/cloudapi/server.go | 21 ++++++++++++++------- test/cases/api.sh | 5 +++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/internal/cloudapi/openapi.gen.go b/internal/cloudapi/openapi.gen.go index 806dd23ac..297e0d3fe 100644 --- a/internal/cloudapi/openapi.gen.go +++ b/internal/cloudapi/openapi.gen.go @@ -58,6 +58,7 @@ type ComposeStatus struct { // Customizations defines model for Customizations. type Customizations struct { + Packages *[]string `json:"packages,omitempty"` Subscription *Subscription `json:"subscription,omitempty"` } diff --git a/internal/cloudapi/openapi.yml b/internal/cloudapi/openapi.yml index 78d3466de..753839ce5 100644 --- a/internal/cloudapi/openapi.yml +++ b/internal/cloudapi/openapi.yml @@ -221,6 +221,11 @@ components: properties: subscription: $ref: '#/components/schemas/Subscription' + packages: + type: array + example: ['postgres'] + items: + type: string Subscription: type: object required: diff --git a/internal/cloudapi/server.go b/internal/cloudapi/server.go index 12b658a36..349cfb312 100644 --- a/internal/cloudapi/server.go +++ b/internal/cloudapi/server.go @@ -77,6 +77,20 @@ func (server *Server) Compose(w http.ResponseWriter, r *http.Request) { return } + var bp = blueprint.Blueprint{} + err = bp.Initialize() + if err != nil { + http.Error(w, "Unable to initialize blueprint", http.StatusInternalServerError) + return + } + if request.Customizations != nil && request.Customizations.Packages != nil { + for _, p := range *request.Customizations.Packages { + bp.Packages = append(bp.Packages, blueprint.Package{ + Name: p, + }) + } + } + type imageRequest struct { manifest distro.Manifest arch string @@ -118,13 +132,6 @@ func (server *Server) Compose(w http.ResponseWriter, r *http.Request) { } } - var bp = blueprint.Blueprint{} - err = bp.Initialize() - if err != nil { - http.Error(w, "Unable to initialize blueprint", http.StatusInternalServerError) - return - } - packageSpecs, excludePackageSpecs := imageType.Packages(bp) packages, _, err := server.rpmMetadata.Depsolve(packageSpecs, excludePackageSpecs, repositories, distribution.ModulePlatformID(), arch.Name()) if err != nil { diff --git a/test/cases/api.sh b/test/cases/api.sh index 967dca8ff..ea3d66b6f 100644 --- a/test/cases/api.sh +++ b/test/cases/api.sh @@ -90,6 +90,11 @@ cat > "$REQUEST_FILE" << EOF "architecture": "$ARCH", "image_type": "ami", "repositories": $(jq ".\"$ARCH\"" /usr/share/tests/osbuild-composer/repositories/"$DISTRO".json), + "customizations": { + "packages": [ + "postgres" + ] + }, "upload_requests": [ { "type": "aws",