Skip to content

Commit 348af7e

Browse files
committed
v1: require either bootc or distribution in common compose
`/compose`: the direct compose handler will now require one or the other, and never both. `/blueprints/{id}/compose`: composing images via the blueprint will result in the distribution being dropped from the compose request in case bootc is set. The ability to keep setting distribution in the blueprint itself is kept, to allow the frontend to easily present bootc images categorized by distribution.
1 parent ff1d2ec commit 348af7e

5 files changed

Lines changed: 96 additions & 15 deletions

File tree

HACKING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,23 @@ file to generate a package list.
169169

170170
If the repository requires a client tls key/cert you can supply them with
171171
`--key` and `--cert`.
172+
173+
## Bootc images and `distributions/`
174+
175+
Bootc images are listed under a specific distribution. For instance the RHEL 10 json will contain
176+
several bootc references, one or more per image type. Composer, however, does not need a
177+
distribution set when building bootc images, everything is derived from the bootc references. In the
178+
case of bootc images in image-builder-crc, the distribution field is relegated to a means of
179+
categorizing bootc references, rather than being an essential piece of information to build an
180+
image.
181+
182+
As a result:
183+
- when sending a compose request to composer, either the bootc information or the distribution is
184+
passed, but never both;
185+
- for the `/compose` endpoint in the image-builder-crc API (when building images without
186+
blueprints), either the bootc information or the distribution is passed, but never both;
187+
- to accomodate the need for the frontend to be able to categorize existing image mode blueprints
188+
under a distribution, the bootc information and the distribution can be set simultaneously.
189+
190+
By allowing the situation described in the third point, the frontend can easily present bootc images
191+
by distribution.

internal/v1/handler_blueprints.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,13 @@ func (h *Handlers) ComposeBlueprint(ctx echo.Context, id openapi_types.UUID) err
739739
ClientId: &clientId,
740740
Bootc: blueprint.Bootc,
741741
}
742+
743+
// handleCommonCompose requires either bootc or distribution, but not both. See
744+
// HACKING.md for more information on bootc and distribution.
745+
if composeRequest.Bootc != nil {
746+
composeRequest.Distribution = nil
747+
}
748+
742749
composesResponse, err := h.handleCommonCompose(ctx, composeRequest, composeOpts{
743750
BlueprintId: &blueprintEntry.Id,
744751
BlueprintVersionId: &blueprintEntry.VersionId,

internal/v1/handler_blueprints_test.go

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,27 +611,27 @@ func TestHandlers_ComposeBlueprint(t *testing.T) {
611611
{
612612
Baseurl: common.ToPtr("http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/"),
613613
CheckGpg: common.ToPtr(true),
614-
Gpgkey: common.ToPtr("-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v2.0.22 (GNU/Linux)\n\nmQINBFzMWxkBEADHrskpBgN9OphmhRkc7P/YrsAGSvvl7kfu+e9KAaU6f5MeAVyn\nrIoM43syyGkgFyWgjZM8/rur7EMPY2yt+2q/1ZfLVCRn9856JqTIq0XRpDUe4nKQ\n8BlA7wDVZoSDxUZkSuTIyExbDf0cpw89Tcf62Mxmi8jh74vRlPy1PgjWL5494b3X\n5fxDidH4bqPZyxTBqPrUFuo+EfUVEqiGF94Ppq6ZUvrBGOVo1V1+Ifm9CGEK597c\naevcGc1RFlgxIgN84UpuDjPR9/zSndwJ7XsXYvZ6HXcKGagRKsfYDWGPkA5cOL/e\nf+yObOnC43yPUvpggQ4KaNJ6+SMTZOKikM8yciyBwLqwrjo8FlJgkv8Vfag/2UR7\nJINbyqHHoLUhQ2m6HXSwK4YjtwidF9EUkaBZWrrskYR3IRZLXlWqeOi/+ezYOW0m\nvufrkcvsh+TKlVVnuwmEPjJ8mwUSpsLdfPJo1DHsd8FS03SCKPaXFdD7ePfEjiYk\nnHpQaKE01aWVSLUiygn7F7rYemGqV9Vt7tBw5pz0vqSC72a5E3zFzIIuHx6aANry\nGat3aqU3qtBXOrA/dPkX9cWE+UR5wo/A2UdKJZLlGhM2WRJ3ltmGT48V9CeS6N9Y\nm4CKdzvg7EWjlTlFrd/8WJ2KoqOE9leDPeXRPncubJfJ6LLIHyG09h9kKQARAQAB\ntDpDZW50T1MgKENlbnRPUyBPZmZpY2lhbCBTaWduaW5nIEtleSkgPHNlY3VyaXR5\nQGNlbnRvcy5vcmc+iQI3BBMBCAAhAhsDBgsJCAcDAgYVCAIJCgsDFgIBAh4BAheA\nBQJczFsaAAoJEAW1VbOEg8ZdvOgQAMFTGIQokADy5+CynFKjfO7R0VVpJxmYGVr1\nTjnKaHmjxnJaYqoha9ukGgmLu0r+lJ42Kk6nREk1vlxfRAfiWd00Zkm+K3IMq1/D\nE0heC2vX8qqjsLJs3jzq0hgNvo9X0uHDaA4J1BHsD8sE5in/f4SivjbngvFovRGU\n1XLNCgoqpFNcROP18LqKUw8WtqgWdnYBa5i6D5qx+WMRX0NHNwcCMy1lz+sTFxIU\n9mW6cLsMaacPGD8pUXIVli8P9Vlv3jBk1wFIqRgQPW01ph/3bM7pf9hyM9FAfU4X\nAFcyb1oYI4/82EkICUe6jeuZrz67dPeLVAlYrGW4hp/825g0fqJHxPDp25GS4rAa\n4RqyibLzNjSGdXYeLj2NcB/8OqaP+T1hv3JDaqe70QoYa/GIC4rh15NyXVbUP+LG\nV4vUiL7mb9ynzvF5zYHJbcg4R7dOsiZHrMFwy7FZesQaVrXeJlxRcEj65rpm1ZtZ\nmwAE1k2LsRkvLyr9hpZkXnMeOKYIPwpdmBjXNVNVbq7097OxZOYPPos+iZKMWfl4\nUQnMsCVxonZtamdI4qEc3jMkSZPJKgOplGOms5jdY+EdSvsFWEQ0Snd3dChfU7DV\no4Rbcy5klwHrvuZIOLaovhyxuRPhP6gV9+gzpTK/7vrvDlFbbZE6s212mDZ13RWB\nmTfAxz4h\n=agO/\n-----END PGP PUBLIC KEY BLOCK-----\n"),
614+
Gpgkey: common.ToPtr(mocks.CentosGPG),
615615
Rhsm: common.ToPtr(false),
616616
},
617617
{
618618
Baseurl: common.ToPtr("http://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/"),
619619
CheckGpg: common.ToPtr(true),
620-
Gpgkey: common.ToPtr("-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v2.0.22 (GNU/Linux)\n\nmQINBFzM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Uw8WtqgWdnYBa5i6D5qx+WMRX0NHNwcCMy1lz+sTFxIU\n9mW6cLsMaacPGD8pUXIVli8P9Vlv3jBk1wFIqRgQPW01ph/3bM7pf9hyM9FAfU4X\nAFcyb1oYI4/82EkICUe6jeuZrz67dPeLVAlYrGW4hp/825g0fqJHxPDp25GS4rAa\n4RqyibLzNjSGdXYeLj2NcB/8OqaP+T1hv3JDaqe70QoYa/GIC4rh15NyXVbUP+LG\nV4vUiL7mb9ynzvF5zYHJbcg4R7dOsiZHrMFwy7FZesQaVrXeJlxRcEj65rpm1ZtZ\nmwAE1k2LsRkvLyr9hpZkXnMeOKYIPwpdmBjXNVNVbq7097OxZOYPPos+iZKMWfl4\nUQnMsCVxonZtamdI4qEc3jMkSZPJKgOplGOms5jdY+EdSvsFWEQ0Snd3dChfU7DV\no4Rbcy5klwHrvuZIOLaovhyxuRPhP6gV9+gzpTK/7vrvDlFbbZE6s212mDZ13RWB\nmTfAxz4h\n=agO/\n-----END PGP PUBLIC KEY BLOCK-----\n"),
620+
Gpgkey: common.ToPtr(mocks.CentosGPG),
621621
Rhsm: common.ToPtr(false),
622622
},
623623
}
624624
reposAarch := []composer.Repository{
625625
{
626626
Baseurl: common.ToPtr("http://mirror.stream.centos.org/9-stream/BaseOS/aarch64/os/"),
627627
CheckGpg: common.ToPtr(true),
628-
Gpgkey: common.ToPtr("-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v2.0.22 (GNU/Linux)\n\nmQINBFzMWxkBEADHrskpBgN9OphmhRkc7P/YrsAGSvvl7kfu+e9KAaU6f5MeAVyn\nrIoM43syyGkgFyWgjZM8/rur7EMPY2yt+2q/1ZfLVCRn9856JqTIq0XRpDUe4nKQ\n8BlA7wDVZoSDxUZkSuTIyExbDf0cpw89Tcf62Mxmi8jh74vRlPy1PgjWL5494b3X\n5fxDidH4bqPZyxTBqPrUFuo+EfUVEqiGF94Ppq6ZUvrBGOVo1V1+Ifm9CGEK597c\naevcGc1RFlgxIg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R7dOsiZHrMFwy7FZesQaVrXeJlxRcEj65rpm1ZtZ\nmwAE1k2LsRkvLyr9hpZkXnMeOKYIPwpdmBjXNVNVbq7097OxZOYPPos+iZKMWfl4\nUQnMsCVxonZtamdI4qEc3jMkSZPJKgOplGOms5jdY+EdSvsFWEQ0Snd3dChfU7DV\no4Rbcy5klwHrvuZIOLaovhyxuRPhP6gV9+gzpTK/7vrvDlFbbZE6s212mDZ13RWB\nmTfAxz4h\n=agO/\n-----END PGP PUBLIC KEY BLOCK-----\n"),
628+
Gpgkey: common.ToPtr(mocks.CentosGPG),
629629
Rhsm: common.ToPtr(false),
630630
},
631631
{
632632
Baseurl: common.ToPtr("http://mirror.stream.centos.org/9-stream/AppStream/aarch64/os/"),
633633
CheckGpg: common.ToPtr(true),
634-
Gpgkey: common.ToPtr("-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v2.0.22 (GNU/Linux)\n\nmQINBFzMWxkBEADHrskpBgN9OphmhRkc7P/YrsAGSvvl7kfu+e9KAaU6f5MeAVyn\nrIoM43syyGkgFyWgjZM8/rur7EMPY2yt+2q/1ZfLVCRn9856JqTIq0XRpDUe4nKQ\n8BlA7wDVZoSDxUZkSuTIyExbDf0cpw89Tcf62Mxmi8jh74vRlPy1PgjWL5494b3X\n5fxDidH4bqPZyxTBqPrUFuo+EfUVEqiGF94Ppq6ZUvrBGOVo1V1+Ifm9CGEK597c\naevcGc1RFlgxIgN84UpuDjPR9/zSndwJ7XsXYvZ6HXcKGagRKsfYDWGPkA5cOL/e\nf+yObOnC43yPUvpggQ4KaNJ6+SMTZOKikM8yciyBwLqwrjo8FlJgkv8Vfag/2UR7\nJINbyqHHoLUhQ2m6HXSwK4YjtwidF9EUkaBZWrrskYR3IRZLXlWqeOi/+ezYOW0m\nvufrkcvsh+TKlVVnuwmEPjJ8mwUSpsLdfPJo1DHsd8FS03SCKPaXFdD7ePfEjiYk\nnHpQaKE01aWVSLUiygn7F7rYemGqV9Vt7tBw5pz0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: common.ToPtr(mocks.CentosGPG),
635635
Rhsm: common.ToPtr(false),
636636
},
637637
}
@@ -710,34 +710,81 @@ func TestHandlers_ComposeBlueprint(t *testing.T) {
710710
},
711711
}
712712

713+
bootcId := uuid.New()
714+
bootcBlueprint := v1.BlueprintBody{
715+
Distribution: common.ToPtr(v1.Distributions("rhel-10.1")),
716+
Bootc: &v1.BootcBody{
717+
Reference: "quay.io/redhat-services-prod/insights-management-tenant/image-builder-bootc-foundry/rhel-10-ec2:latest",
718+
},
719+
ImageRequests: []v1.ImageRequest{
720+
{
721+
Architecture: v1.ImageRequestArchitectureX8664,
722+
ImageType: v1.ImageTypesAws,
723+
UploadRequest: v1.UploadRequest{
724+
Type: v1.UploadTypesAws,
725+
Options: uploadOptions,
726+
},
727+
},
728+
},
729+
}
730+
message, err = json.Marshal(bootcBlueprint)
731+
require.NoError(t, err)
732+
err = srv.DB.InsertBlueprint(ctx, bootcId, uuid.New(), "000000", "000000", "bootc bp", "descr", message, nil, nil)
733+
require.NoError(t, err)
734+
creq4 := composer.ComposeRequest{
735+
BlueprintId: &bootcId,
736+
Bootc: &composer.Bootc{
737+
Reference: "quay.io/redhat-services-prod/insights-management-tenant/image-builder-bootc-foundry/rhel-10-ec2:latest",
738+
},
739+
ImageRequest: &composer.ImageRequest{
740+
Architecture: "x86_64",
741+
ImageType: composer.ImageTypesAws,
742+
Repositories: []composer.Repository{},
743+
UploadOptions: makeUploadOptions(t, composer.AWSEC2UploadOptions{
744+
ShareWithAccounts: []string{"test-account"},
745+
}),
746+
},
747+
Customizations: &composer.Customizations{},
748+
}
749+
713750
tests := map[string]struct {
751+
blueprintId uuid.UUID
714752
payload any
715753
composeRequests []composer.ComposeRequest
716754
expectedImages int
717755
}{
718756
"empty targets": {
757+
blueprintId: id,
719758
payload: strings.NewReader(""),
720759
composeRequests: []composer.ComposeRequest{creq1, creq2, creq3},
721760
expectedImages: 3,
722761
},
723762
"multiple targets": {
763+
blueprintId: id,
724764
payload: v1.ComposeBlueprintJSONBody{ImageTypes: &[]v1.ImageTypes{"aws", "guest-image", "gcp"}},
725765
composeRequests: []composer.ComposeRequest{creq1, creq2, creq3},
726766
expectedImages: 3,
727767
},
728768
"one target": {
769+
blueprintId: id,
729770
payload: v1.ComposeBlueprintJSONBody{ImageTypes: &[]v1.ImageTypes{"guest-image"}},
730771
composeRequests: []composer.ComposeRequest{creq3},
731772
expectedImages: 1,
732773
},
774+
"bootc": {
775+
blueprintId: bootcId,
776+
payload: strings.NewReader(""),
777+
composeRequests: []composer.ComposeRequest{creq4},
778+
expectedImages: 1,
779+
},
733780
}
734781

735782
for name, tc := range tests {
736783
t.Run(name, func(t *testing.T) {
737784
composeRequests = []composer.ComposeRequest{}
738785

739-
respStatusCode, body := tutils.PostResponseBody(t, srv.URL+fmt.Sprintf("/api/image-builder/v1/blueprints/%s/compose", id.String()), tc.payload)
740-
require.Equal(t, http.StatusCreated, respStatusCode)
786+
respStatusCode, body := tutils.PostResponseBody(t, srv.URL+fmt.Sprintf("/api/image-builder/v1/blueprints/%s/compose", tc.blueprintId.String()), tc.payload)
787+
require.Equal(t, http.StatusCreated, respStatusCode, body)
741788

742789
var result []v1.ComposeResponse
743790
err = json.Unmarshal([]byte(body), &result)

internal/v1/handler_compose_image.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ func (h *Handlers) handleCommonCompose(ctx echo.Context, composeRequest ComposeR
6767
return ComposeResponse{}, echo.NewHTTPError(http.StatusForbidden, msg)
6868
}
6969

70+
// See HACKING.md for more information on bootc and distribution.
71+
if composeRequest.Bootc == nil && composeRequest.Distribution == nil {
72+
return ComposeResponse{}, echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("either distribution or bootc needs to be set"))
73+
} else if composeRequest.Bootc != nil && composeRequest.Distribution != nil {
74+
return ComposeResponse{}, echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("either distribution or bootc needs to be set, but not both"))
75+
}
76+
7077
if string(composeRequest.ImageRequests[0].UploadRequest.Type) == "" {
7178
return ComposeResponse{}, echo.NewHTTPError(http.StatusBadRequest, "Exactly one upload request should be included")
7279
}
@@ -75,10 +82,6 @@ func (h *Handlers) handleCommonCompose(ctx echo.Context, composeRequest ComposeR
7582
return ComposeResponse{}, echo.NewHTTPError(http.StatusBadRequest, "Either a snapshot date or content template can be specified, but not both")
7683
}
7784

78-
if composeRequest.Bootc == nil && composeRequest.ImageRequests[0].ImageType == ImageTypesBootableContainerIso {
79-
return ComposeResponse{}, echo.NewHTTPError(http.StatusBadRequest, "bootc is required for bootable-container-iso image type")
80-
}
81-
8285
repositories := []composer.Repository{}
8386
var customizations *composer.Customizations
8487
var distro *string
@@ -151,9 +154,6 @@ func (h *Handlers) handleCommonCompose(ctx echo.Context, composeRequest ComposeR
151154
distro = &v
152155
}
153156
}
154-
} else {
155-
// 500 error as any validation should have happened before handing it off to the common compose function
156-
return ComposeResponse{}, echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("either distribution or bootc needs to be set"))
157157
}
158158

159159
uploadOptions, imageType, err := h.buildUploadOptions(ctx, composeRequest.ImageRequests[0].UploadRequest, composeRequest.ImageRequests[0].ImageType)

internal/v1/handler_post_compose_bootc_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestComposeBootcReferenceWithQuery(t *testing.T) {
6666
},
6767
},
6868
{
69-
name: "distribution is ignored in favour of bootc",
69+
name: "distribution is not allowed with bootc",
7070
distro: "rhel-10.1",
7171
queryExtra: "distro=rhel-10.1&arch=x86_64&type=aws",
7272
wantReference: "quay.io/redhat-services-prod/insights-management-tenant/image-builder-bootc-foundry/rhel-10-ec2:latest",
@@ -133,6 +133,13 @@ func TestComposeBootcReferenceWithQuery(t *testing.T) {
133133
}
134134

135135
status, body = tutils.PostResponseBody(t, srv.URL+"/api/image-builder/v1/compose", payload)
136+
137+
if tt.distro != "" {
138+
// distro is not allowed when bootc is set
139+
require.Equal(t, http.StatusBadRequest, status, body)
140+
return
141+
}
142+
136143
require.Equal(t, http.StatusCreated, status, body)
137144
var composeResp v1.ComposeResponse
138145
require.NoError(t, json.Unmarshal([]byte(body), &composeResp))
@@ -364,7 +371,7 @@ func TestComposeBootableContainerIso(t *testing.T) {
364371
return uo
365372
},
366373
wantStatus: http.StatusBadRequest,
367-
wantErrSubstring: "bootc is required for bootable-container-iso image type",
374+
wantErrSubstring: "either distribution or bootc needs to be set",
368375
},
369376
}
370377

0 commit comments

Comments
 (0)