ostree: move OSTreeImageOptions to the ostree package

Move the ostree image options to the ostree package and rename the type
to ImageOptions (ostree.ImageOptions).
This commit is contained in:
Achilleas Koutsou 2023-05-05 15:11:39 +02:00 committed by Simon de Vlieger
parent ffa1e1df17
commit db431a565d
14 changed files with 114 additions and 69 deletions

View file

@ -22,6 +22,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
@ -122,12 +123,17 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
options := distro.ImageOptions{Size: 0}
if cr.OSTree != nil {
options.OSTree = distro.OSTreeImageOptions{
options.OSTree = &ostree.ImageOptions{
URL: cr.OSTree.URL,
ImageRef: cr.OSTree.Ref,
FetchChecksum: cr.OSTree.Parent,
RHSM: cr.OSTree.RHSM,
}
} else {
// use default OSTreeRef for image type
options.OSTree = &ostree.ImageOptions{
ImageRef: imgType.OSTreeRef(),
}
}
// add RHSM fact to detect changes
@ -155,11 +161,6 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
return fmt.Errorf("[%s] container resolution failed: %s", filename, err.Error())
}
if options.OSTree.ImageRef == "" {
// use default OSTreeRef for image type
options.OSTree.ImageRef = imgType.OSTreeRef()
}
packageSpecs, err := depsolve(cacheDir, imgType, bp, options, repos, distribution, archName)
if err != nil {
err = fmt.Errorf("[%s] depsolve failed: %s", filename, err.Error())

View file

@ -14,6 +14,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
rhel "github.com/osbuild/osbuild-composer/internal/distro/rhel8"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
@ -47,7 +48,7 @@ func TestCrossArchDepsolve(t *testing.T) {
packages := imgType.PackageSets(blueprint.Blueprint{},
distro.ImageOptions{
OSTree: distro.OSTreeImageOptions{
OSTree: &ostree.ImageOptions{
URL: "foo",
ImageRef: "bar",
FetchChecksum: "baz",

View file

@ -11,6 +11,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/ostree"
)
func main() {
@ -48,7 +49,7 @@ func main() {
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
pkgset := image.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
OSTree: distro.OSTreeImageOptions{
OSTree: &ostree.ImageOptions{
URL: "foo",
ImageRef: "bar",
FetchChecksum: "baz",

View file

@ -13,6 +13,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -179,7 +180,7 @@ func main() {
options := distro.ImageOptions{
Size: imageType.Size(0),
OSTree: distro.OSTreeImageOptions{
OSTree: &ostree.ImageOptions{
ImageRef: composeRequest.OSTree.Ref,
FetchChecksum: composeRequest.OSTree.Parent,
URL: composeRequest.OSTree.URL,

View file

@ -462,6 +462,8 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
var ostreeOptions *ostree.SourceSpec
// assume it's an ostree image if the type has a default ostree ref
if imageType.OSTreeRef() != "" {
imageOptions.OSTree = &ostree.ImageOptions{}
ostreeOptions = &ostree.SourceSpec{}
if ir.Ostree != nil {
if ir.Ostree.Ref != nil {

View file

@ -23,6 +23,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/container"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/prometheus"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/target"
@ -454,9 +455,11 @@ func generateManifest(ctx context.Context, workers *worker.Server, depsolveJobID
return
}
options.OSTree.ImageRef = result.Specs[0].Ref
options.OSTree.FetchChecksum = result.Specs[0].Checksum
options.OSTree.URL = result.Specs[0].URL
options.OSTree = &ostree.ImageOptions{
ImageRef: result.Specs[0].Ref,
FetchChecksum: result.Specs[0].Checksum,
URL: result.Specs[0].URL,
}
}
manifest, _, err := imageType.Manifest(b, options, repos, depsolveResults.PackageSpecs, containerSpecs, seed)

View file

@ -7,6 +7,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/container"
"github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/subscription"
@ -138,37 +139,11 @@ type ImageType interface {
// The ImageOptions specify options for a specific image build
type ImageOptions struct {
Size uint64
OSTree OSTreeImageOptions
OSTree *ostree.ImageOptions
Subscription *subscription.ImageOptions
Facts *facts.ImageOptions
}
// The OSTreeImageOptions specify an ostree ref, checksum, URL, ContentURL, and RHSM. The meaning of
// each parameter depends on the image type being built.
type OSTreeImageOptions struct {
// For ostree commit and container types: The ref of the new commit to be
// built.
// For ostree installers and raw images: The ref of the commit being
// embedded in the installer or deployed in the image.
ImageRef string
// For ostree commit and container types: The FetchChecksum specifies the parent
// ostree commit that the new commit will be based on.
// For ostree installers and raw images: The FetchChecksum specifies the commit
// ID that will be embedded in the installer or deployed in the image.
FetchChecksum string
// The URL from which to fetch the commit specified by the checksum.
URL string
// If specified, the URL will be used only for metadata.
ContentURL string
// Indicate if the 'org.osbuild.rhsm.consumer' secret should be added when pulling from the
// remote.
RHSM bool
}
type BasePartitionTableMap map[string]disk.PartitionTable
// Fallbacks: When a new method is added to an interface to provide to provide

View file

@ -12,6 +12,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distro/distro_test_common"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -44,7 +45,7 @@ func TestImageType_PackageSetsChains(t *testing.T) {
require.Nil(t, err)
imagePkgSets := imageType.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
OSTree: distro.OSTreeImageOptions{
OSTree: &ostree.ImageOptions{
URL: "foo",
ImageRef: "bar",
FetchChecksum: "baz",
@ -133,7 +134,7 @@ func TestImageTypePipelineNames(t *testing.T) {
seed := int64(0)
// Add ostree options for image types that require them
options.OSTree = distro.OSTreeImageOptions{
options.OSTree = &ostree.ImageOptions{
ImageRef: imageType.OSTreeRef(),
URL: "https://example.com/repo",
FetchChecksum: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
@ -412,7 +413,7 @@ func TestPipelineRepositories(t *testing.T) {
options := distro.ImageOptions{}
// Add ostree options for image types that require them
options.OSTree = distro.OSTreeImageOptions{
options.OSTree = &ostree.ImageOptions{
ImageRef: imageType.OSTreeRef(),
URL: "https://example.com/repo",
FetchChecksum: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",

View file

@ -101,10 +101,10 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis
return
}
var ostreeOptions distro.OSTreeImageOptions
var ostreeOptions *ostree.ImageOptions
if ref := imageType.OSTreeRef(); ref != "" {
if tt.ComposeRequest.OSTree != nil {
ostreeOptions = distro.OSTreeImageOptions{
ostreeOptions = &ostree.ImageOptions{
ImageRef: tt.ComposeRequest.OSTree.Ref,
FetchChecksum: tt.ComposeRequest.OSTree.Parent,
URL: tt.ComposeRequest.OSTree.URL,
@ -112,8 +112,10 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis
}
}
}
if ostreeOptions.ImageRef == "" { // set image type default if not specified in request
ostreeOptions.ImageRef = imageType.OSTreeRef()
if ostreeOptions == nil { // set image type default if not specified in request
ostreeOptions = &ostree.ImageOptions{
ImageRef: imageType.OSTreeRef(),
}
}
options := distro.ImageOptions{
@ -344,14 +346,14 @@ func GetTestingPackageSpecSets(packageName, arch string, pkgSetNames []string) m
func GetTestingImagePackageSpecSets(packageName string, i distro.ImageType) map[string][]rpmmd.PackageSpec {
arch := i.Arch().Name()
imagePackageSets := make([]string, 0, len(i.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
OSTree: distro.OSTreeImageOptions{
OSTree: &ostree.ImageOptions{
URL: "foo",
ImageRef: "bar",
FetchChecksum: "baz",
},
}, nil)))
for pkgSetName := range i.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
OSTree: distro.OSTreeImageOptions{
OSTree: &ostree.ImageOptions{
URL: "foo",
ImageRef: "bar",
FetchChecksum: "baz",

View file

@ -14,6 +14,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/image"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/oscap"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -110,6 +111,15 @@ func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOpti
}
}
// For iot-commit and iot-container, we need to set an ImageRef if one
// isn't defined already in order to properly initialize the manifest and
// package selection.
if options.OSTree == nil {
options.OSTree = &ostree.ImageOptions{
ImageRef: t.OSTreeRef(),
}
}
// In case of Cloud API, this method is called before the ostree commit
// is resolved. Unfortunately, initializeManifest when called for
// an ostree installer returns an error.
@ -128,11 +138,6 @@ func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOpti
logrus.Warn("FIXME: Requesting package sets for iot-installer without a resolved ostree ref. Faking one.")
}
// Similar to above, for edge-commit and edge-container, we need to set an
// ImageRef in order to properly initialize the manifest and package
// selection.
options.OSTree.ImageRef = t.OSTreeRef()
// create a temporary container spec array with the info from the blueprint
// to initialize the manifest
containers := make([]container.Spec, len(bp.Containers))
@ -337,9 +342,14 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp
return nil, fmt.Errorf("embedding containers is not supported for %s on %s", t.name, t.arch.distro.name)
}
ostreeChecksum := ""
if options.OSTree != nil {
ostreeChecksum = options.OSTree.FetchChecksum
}
if t.bootISO && t.rpmOstree {
// check the checksum instead of the URL, because the URL should have been used to resolve the checksum and we need both
if options.OSTree.FetchChecksum == "" {
if ostreeChecksum == "" {
return nil, fmt.Errorf("boot ISO image type %q requires specifying a URL from which to retrieve the OSTree commit", t.name)
}
}

View file

@ -18,6 +18,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/image"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/oscap"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -282,6 +283,15 @@ func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOpti
}
}
// For edge-commit and edge-container, we need to set an ImageRef if one
// isn't defined already in order to properly initialize the manifest and
// package selection.
if options.OSTree == nil {
options.OSTree = &ostree.ImageOptions{
ImageRef: t.OSTreeRef(),
}
}
// In case of Cloud API, this method is called before the ostree commit
// is resolved. Unfortunately, initializeManifest when called for
// an ostree installer returns an error.
@ -300,11 +310,6 @@ func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOpti
logrus.Warn("FIXME: Requesting package sets for iot-installer without a resolved ostree ref. Faking one.")
}
// Similar to above, for edge-commit and edge-container, we need to set an
// ImageRef in order to properly initialize the manifest and package
// selection.
options.OSTree.ImageRef = t.OSTreeRef()
// create a temporary container spec array with the info from the blueprint
// to initialize the manifest
containers := make([]container.Spec, len(bp.Containers))
@ -410,9 +415,14 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp
return warnings, fmt.Errorf("embedding containers is not supported for %s on %s", t.name, t.arch.distro.name)
}
ostreeChecksum := ""
if options.OSTree != nil {
ostreeChecksum = options.OSTree.FetchChecksum
}
if t.bootISO && t.rpmOstree {
// check the checksum instead of the URL, because the URL should have been used to resolve the checksum and we need both
if options.OSTree.FetchChecksum == "" {
if ostreeChecksum == "" {
return warnings, fmt.Errorf("boot ISO image type %q requires specifying a URL from which to retrieve the OSTree commit", t.name)
}
@ -453,7 +463,7 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp
if t.name == "edge-raw-image" {
// check the checksum instead of the URL, because the URL should have been used to resolve the checksum and we need both
if options.OSTree.FetchChecksum == "" {
if ostreeChecksum == "" {
return warnings, fmt.Errorf("edge raw images require specifying a URL from which to retrieve the OSTree commit")
}

View file

@ -18,6 +18,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/image"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/oscap"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -282,6 +283,15 @@ func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOpti
}
}
// For edge-commit and edge-container, we need to set an ImageRef if one
// isn't defined already in order to properly initialize the manifest and
// package selection.
if options.OSTree == nil {
options.OSTree = &ostree.ImageOptions{
ImageRef: t.OSTreeRef(),
}
}
// In case of Cloud API, this method is called before the ostree commit
// is resolved. Unfortunately, initializeManifest when called for
// an ostree installer returns an error.
@ -300,11 +310,6 @@ func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOpti
logrus.Warn("FIXME: Requesting package sets for iot-installer without a resolved ostree ref. Faking one.")
}
// Similar to above, for edge-commit and edge-container, we need to set an
// ImageRef in order to properly initialize the manifest and package
// selection.
options.OSTree.ImageRef = t.OSTreeRef()
// create a temporary container spec array with the info from the blueprint
// to initialize the manifest
containers := make([]container.Spec, len(bp.Containers))
@ -380,9 +385,14 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp
return warnings, fmt.Errorf("embedding containers is not supported for %s on %s", t.name, t.arch.distro.name)
}
ostreeChecksum := ""
if options.OSTree != nil {
ostreeChecksum = options.OSTree.FetchChecksum
}
if t.bootISO && t.rpmOstree {
// check the checksum instead of the URL, because the URL should have been used to resolve the checksum and we need both
if options.OSTree.FetchChecksum == "" {
if ostreeChecksum == "" {
return warnings, fmt.Errorf("boot ISO image type %q requires specifying a URL from which to retrieve the OSTree commit", t.name)
}
@ -434,7 +444,7 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp
if t.name == "edge-raw-image" {
// check the checksum instead of the URL, because the URL should have been used to resolve the checksum and we need both
if options.OSTree.FetchChecksum == "" {
if ostreeChecksum == "" {
return warnings, fmt.Errorf("edge raw images require specifying a URL from which to retrieve the OSTree commit")
}

View file

@ -45,6 +45,34 @@ type CommitSpec struct {
Checksum string
}
// ImageOptions specify an ostree ref, checksum, URL, ContentURL, and RHSM. The
// meaning of each parameter depends on the image type being built. The type
// is used to specify ostree-related image options when initializing a
// Manifest.
type ImageOptions struct {
// For ostree commit and container types: The ref of the new commit to be
// built.
// For ostree installers and raw images: The ref of the commit being
// embedded in the installer or deployed in the image.
ImageRef string
// For ostree commit and container types: The FetchChecksum specifies the parent
// ostree commit that the new commit will be based on.
// For ostree installers and raw images: The FetchChecksum specifies the commit
// ID that will be embedded in the installer or deployed in the image.
FetchChecksum string
// The URL from which to fetch the commit specified by the checksum.
URL string
// If specified, the URL will be used only for metadata.
ContentURL string
// Indicate if the 'org.osbuild.rhsm.consumer' secret should be added when pulling from the
// remote.
RHSM bool
}
// Remote defines the options that can be set for an OSTree Remote configuration.
type Remote struct {
Name string

View file

@ -2452,7 +2452,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
}
testMode := q.Get("test")
ostreeOptions := distro.OSTreeImageOptions{
ostreeOptions := &ostree.ImageOptions{
URL: cr.OSTree.URL,
}
if testMode == "1" || testMode == "2" {