Skip to content

Commit

Permalink
image: switch BootcDiskImage to use RawBootcImage
Browse files Browse the repository at this point in the history
This means we move to use `bootc install to-filesystem` when
creating a `BootcDiskImage`.
  • Loading branch information
mvo5 committed Feb 28, 2024
1 parent 5218876 commit e052adf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
30 changes: 18 additions & 12 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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"
Expand Down
39 changes: 8 additions & 31 deletions pkg/image/bootc_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit e052adf

Please sign in to comment.