manifest: add RawOSTreeImage

The RawOSTreeImage pipeline is the OSTree-equivalent to the RawImage.
The serialization is very similar between the two (almost identical),
but the two Pipelines depend on different Tree implementations.

Co-Authored-By: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Achilleas Koutsou 2022-08-16 20:56:56 +02:00 committed by Tom Gundersen
parent a8a2191670
commit 2683474519

View file

@ -0,0 +1,67 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
// A RawOSTreeImage represents a raw ostree image file which can be booted in a
// hypervisor. It is created from an existing OSTreeDeployment.
type RawOSTreeImage struct {
Base
treePipeline *OSTreeDeployment
Filename string
}
func NewRawOStreeImage(m *Manifest,
buildPipeline *Build,
treePipeline *OSTreeDeployment) *RawOSTreeImage {
p := &RawOSTreeImage{
Base: NewBase(m, "image", buildPipeline),
treePipeline: treePipeline,
Filename: "disk.img",
}
buildPipeline.addDependent(p)
if treePipeline.Base.manifest != m {
panic("tree pipeline from different manifest")
}
m.addPipeline(p)
return p
}
func (p *RawOSTreeImage) getBuildPackages() []string {
return p.treePipeline.PartitionTable.GetBuildPackages()
}
func (p *RawOSTreeImage) serialize() osbuild.Pipeline {
pipeline := p.Base.serialize()
pt := p.treePipeline.PartitionTable
if pt == nil {
panic("no partition table in live image")
}
for _, stage := range osbuild.GenImagePrepareStages(pt, p.Filename, osbuild.PTSfdisk) {
pipeline.AddStage(stage)
}
inputName := "root-tree"
copyOptions, copyDevices, copyMounts := osbuild.GenCopyFSTreeOptions(inputName, p.treePipeline.Name(), p.Filename, pt)
copyInputs := osbuild.NewCopyStagePipelineTreeInputs(inputName, p.treePipeline.Name())
pipeline.AddStage(osbuild.NewCopyStage(copyOptions, copyInputs, copyDevices, copyMounts))
for _, stage := range osbuild.GenImageFinishStages(pt, p.Filename) {
pipeline.AddStage(stage)
}
if grubLegacy := p.treePipeline.platform.GetBIOSPlatform(); grubLegacy != "" {
pipeline.AddStage(osbuild.NewGrub2InstStage(osbuild.NewGrub2InstStageOption(p.Filename, pt, grubLegacy)))
}
return pipeline
}
func (p *RawOSTreeImage) Export() *artifact.Artifact {
p.Base.export = true
return artifact.New(p.Name(), p.Filename, nil)
}