From 0b0ea6c0a04b16ddb16478bdce1b80334377288b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 22 Feb 2024 10:23:14 +0100 Subject: [PATCH] image: switch BootcDiskImage to use RawBootcImage This means we move to use `bootc install to-filesystem` when creating a `BootcDiskImage`. --- pkg/image/bootc_disk.go | 30 ++++++++++++++++----------- pkg/image/bootc_disk_test.go | 39 ++++++++---------------------------- 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/pkg/image/bootc_disk.go b/pkg/image/bootc_disk.go index fd231dda2b..7696c40dc1 100644 --- a/pkg/image/bootc_disk.go +++ b/pkg/image/bootc_disk.go @@ -6,26 +6,29 @@ import ( "github.com/osbuild/images/pkg/artifact" "github.com/osbuild/images/pkg/container" + "github.com/osbuild/images/pkg/disk" "github.com/osbuild/images/pkg/manifest" "github.com/osbuild/images/pkg/platform" "github.com/osbuild/images/pkg/runner" ) type BootcDiskImage struct { - *OSTreeDiskImage + Base + + Platform platform.Platform + PartitionTable *disk.PartitionTable + + Filename string + + ContainerSource *container.SourceSpec + + Compression string } func NewBootcDiskImage(container container.SourceSpec) *BootcDiskImage { - // XXX: hardcoded for now - ref := "ostree/1/1/0" - return &BootcDiskImage{ - &OSTreeDiskImage{ - Base: NewBase("bootc-raw-image"), - ContainerSource: &container, - Ref: ref, - OSName: "default", - }, + Base: NewBase("bootc-raw-image"), + ContainerSource: &container, } } @@ -47,8 +50,11 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes panic(fmt.Sprintf("no compression is allowed with %q format for %q", imgFormat, img.name)) } - opts := &baseRawOstreeImageOpts{useBootupd: true} - baseImage := baseRawOstreeImage(img.OSTreeDiskImage, buildPipeline, opts) + // XXX: no support for customization right now, at least /etc/fstab + // and very basic user (root only?) should be supported + baseImage := manifest.NewRawBootcImage(buildPipeline, containers, img.Platform) + baseImage.PartitionTable = img.PartitionTable + switch imgFormat { case platform.FORMAT_QCOW2: // qcow2 runs without a build pipeline directly from "bib" diff --git a/pkg/image/bootc_disk_test.go b/pkg/image/bootc_disk_test.go index a9cbe170b7..a9a19fe321 100644 --- a/pkg/image/bootc_disk_test.go +++ b/pkg/image/bootc_disk_test.go @@ -25,7 +25,7 @@ func TestBootcDiskImageNew(t *testing.T) { img := image.NewBootcDiskImage(containerSource) require.NotNil(t, img) - assert.Equal(t, img.OSTreeDiskImage.Base.Name(), "bootc-raw-image") + assert.Equal(t, img.Base.Name(), "bootc-raw-image") } func makeFakeDigest(t *testing.T) string { @@ -70,8 +70,8 @@ func makeBootcDiskImageOsbuildManifest(t *testing.T, opts *bootcDiskImageTestOpt require.Nil(t, err) fakeSourceSpecs := map[string][]container.Spec{ - "build": []container.Spec{{Source: "some-src", Digest: makeFakeDigest(t), ImageID: makeFakeDigest(t)}}, - "ostree-deployment": []container.Spec{{Source: "other-src", Digest: makeFakeDigest(t), ImageID: makeFakeDigest(t)}}, + "build": []container.Spec{{Source: "some-src", Digest: makeFakeDigest(t), ImageID: makeFakeDigest(t)}}, + "image": []container.Spec{{Source: "other-src", Digest: makeFakeDigest(t), ImageID: makeFakeDigest(t)}}, } osbuildManifest, err := m.Serialize(nil, fakeSourceSpecs, nil) @@ -116,37 +116,14 @@ func TestBootcDiskImageInstantiateNoBuildpipelineForQcow2(t *testing.T) { assert.Equal(t, qcowPipeline["build"], nil) } -func TestBootcDiskImageUsesBootupd(t *testing.T) { +func TestBootcDiskImageUsesBootcInstallToFs(t *testing.T) { osbuildManifest := makeBootcDiskImageOsbuildManifest(t, nil) - // check that bootupd is part of the "image" pipeline + // check that bootc.install-to-filesystem is part of the "image" pipeline imagePipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "image") require.NotNil(t, imagePipeline) - bootupdStage := findStageFromOsbuildPipeline(t, imagePipeline, "org.osbuild.bootupd") - require.NotNil(t, bootupdStage) - - // ensure that "grub2" is not part of the ostree pipeline - ostreeDeployPipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "ostree-deployment") - require.NotNil(t, ostreeDeployPipeline) - grubStage := findStageFromOsbuildPipeline(t, ostreeDeployPipeline, "org.osbuild.grub2") - require.Nil(t, grubStage) -} + bootcStage := findStageFromOsbuildPipeline(t, imagePipeline, "org.osbuild.bootc.install-to-filesystem") + require.NotNil(t, bootcStage) -func TestBootcDiskImageBootupdBiosSupport(t *testing.T) { - for _, withBios := range []bool{false, true} { - osbuildManifest := makeBootcDiskImageOsbuildManifest(t, &bootcDiskImageTestOpts{BIOS: withBios}) - - imagePipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "image") - require.NotNil(t, imagePipeline) - bootupdStage := findStageFromOsbuildPipeline(t, imagePipeline, "org.osbuild.bootupd") - require.NotNil(t, bootupdStage) - - opts := bootupdStage["options"].(map[string]interface{}) - if withBios { - biosOpts := opts["bios"].(map[string]interface{}) - assert.Equal(t, biosOpts["device"], "disk") - } else { - require.Nil(t, opts["bios"]) - } - } + // XXX: check customizations here too }