Add the rhsm.facts stage.

We initially provide a Facts file that stores the `ApiType`. This is the
API that was used to request the compose.
This commit is contained in:
Simon de Vlieger 2022-08-25 12:09:21 +02:00 committed by Tomáš Hozza
parent dba76a1204
commit c5f335bceb
9 changed files with 111 additions and 16 deletions

View file

@ -2,7 +2,7 @@
"fedora-35": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
},
"repos": [
@ -79,7 +79,7 @@
"fedora-36": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
},
"repos": [
@ -156,21 +156,21 @@
"rhel-8.4": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
}
},
"rhel-8.6": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
}
},
"rhel-8.7": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
},
"repos": [
@ -216,14 +216,14 @@
"rhel-9.0": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
}
},
"rhel-9.1": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
},
"repos": [
@ -269,21 +269,21 @@
"centos-8": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
}
},
"centos-9": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
}
},
"centos-stream-9": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
},
"repos": [
@ -329,7 +329,7 @@
"centos-stream-8": {
"dependencies": {
"osbuild": {
"commit": "376cbffd136bc4ba86fc7c63697fa5b88fe3acef"
"commit": "ba218f781d4c7455cd995eea55be09e902370905"
}
},
"repos": [
@ -386,4 +386,4 @@
}
]
}
}
}

View file

@ -269,6 +269,10 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
}
imageOptions := distro.ImageOptions{Size: imageType.Size(0)}
imageOptions.Facts = &distro.FactsImageOptions{
ApiType: "cloudapi-v2",
}
if request.Customizations != nil && request.Customizations.Subscription != nil {
imageOptions.Subscription = &distro.SubscriptionImageOptions{
Organization: request.Customizations.Subscription.Organization,

View file

@ -129,6 +129,7 @@ type ImageOptions struct {
OSTree ostree.RequestParams
Size uint64
Subscription *SubscriptionImageOptions
Facts *FactsImageOptions
}
// The SubscriptionImageOptions specify subscription-specific image options
@ -142,6 +143,12 @@ type SubscriptionImageOptions struct {
Insights bool
}
// The FactsImageOptions specify things to be stored into the Insights facts
// storage. This mostly relates to how the build of the image was performed.
type FactsImageOptions struct {
ApiType string
}
type BasePartitionTableMap map[string]disk.PartitionTable
// A Manifest is an opaque JSON object, which is a valid input to osbuild

View file

@ -690,6 +690,14 @@ func osPipeline(t *imageType,
p.AddStage(osbuild.NewSELinuxStage(selinuxStageOptions(false)))
}
if options.Facts != nil {
p.AddStage(osbuild.NewRHSMFactsStage(&osbuild.RHSMFactsStageOptions{
Facts: osbuild.RHSMFacts{
ApiType: options.Facts.ApiType,
},
}))
}
if t.rpmOstree {
p.AddStage(osbuild.NewOSTreePrepTreeStage(&osbuild.OSTreePrepTreeStageOptions{
EtcGroupMembers: []string{

View file

@ -688,6 +688,14 @@ func osPipeline(t *imageType,
p.AddStage(osbuild.NewSELinuxStage(selinuxStageOptions(false)))
}
if options.Facts != nil {
p.AddStage(osbuild.NewRHSMFactsStage(&osbuild.RHSMFactsStageOptions{
Facts: osbuild.RHSMFacts{
ApiType: options.Facts.ApiType,
},
}))
}
if t.rpmOstree {
p.AddStage(osbuild.NewOSTreePrepTreeStage(&osbuild.OSTreePrepTreeStageOptions{
EtcGroupMembers: []string{

View file

@ -0,0 +1,19 @@
package osbuild
type RHSMFactsStageOptions struct {
Facts RHSMFacts `json:"facts"`
}
type RHSMFacts struct {
ApiType string `json:"image-builder.osbuild-composer.api-type"`
}
func (RHSMFactsStageOptions) isStageOptions() {}
// NewRHSMFactsStage creates a new RHSM stage
func NewRHSMFactsStage(options *RHSMFactsStageOptions) *Stage {
return &Stage{
Type: "org.osbuild.rhsm.facts",
Options: options,
}
}

View file

@ -0,0 +1,46 @@
package osbuild
import (
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewRHSMFactsStage(t *testing.T) {
expectedStage := &Stage{
Type: "org.osbuild.rhsm.facts",
Options: &RHSMFactsStageOptions{},
}
actualStage := NewRHSMFactsStage(&RHSMFactsStageOptions{})
assert.Equal(t, expectedStage, actualStage)
}
func TestRHSMFactsStageJson(t *testing.T) {
tests := []struct {
Options RHSMFactsStageOptions
JsonString string
}{
{
Options: RHSMFactsStageOptions{
Facts: RHSMFacts{
ApiType: "test-api",
},
},
JsonString: fmt.Sprintf(`{"facts":{"image-builder.osbuild-composer.api-type":"%s"}}`, "test-api"),
},
}
for _, test := range tests {
marshaledJson, err := json.Marshal(test.Options)
require.NoError(t, err, "failed to marshal JSON")
require.Equal(t, test.JsonString, string(marshaledJson))
var jsonOptions RHSMFactsStageOptions
err = json.Unmarshal([]byte(test.JsonString), &jsonOptions)
require.NoError(t, err, "failed to parse JSON")
require.True(t, reflect.DeepEqual(test.Options, jsonOptions))
}
}

View file

@ -2351,6 +2351,9 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
URL: cr.OSTree.URL,
},
}
options.Facts = &distro.FactsImageOptions{
ApiType: "weldr",
}
packageSets, err := api.depsolveBlueprintForImageType(*bp, options, imageType)
if err != nil {

View file

@ -309,10 +309,10 @@ The core osbuild-composer binary. This is suitable both for spawning in containe
Summary: The worker for osbuild-composer
Requires: systemd
Requires: qemu-img
Requires: osbuild >= 62
Requires: osbuild-ostree >= 62
Requires: osbuild-lvm2 >= 62
Requires: osbuild-luks2 >= 62
Requires: osbuild >= 63
Requires: osbuild-ostree >= 63
Requires: osbuild-lvm2 >= 63
Requires: osbuild-luks2 >= 63
Requires: %{name}-dnf-json = %{version}-%{release}
%description worker