pipelines: add fedora liveimg and qemu pipelines

This commit is contained in:
Tom Gundersen 2022-06-25 21:15:25 +01:00
parent 562a5b1127
commit 1243f84cb0
3 changed files with 124 additions and 60 deletions

View file

@ -35,11 +35,11 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti
diskfile := "disk.img"
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(packageSetSpecs[osPkgsKey], customizations.GetKernel().Name)
imagePipeline := liveImagePipeline(treePipeline.Name(), diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
imagePipeline := liveImagePipeline(&buildPipeline, &treePipeline, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, imagePipeline.Serialize())
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatQCOW2, osbuild.QCOW2Options{Compat: "1.1"})
pipelines = append(pipelines, *qemuPipeline)
qemuPipeline := qemuPipeline(&buildPipeline, &imagePipeline, diskfile, t.filename, osbuild.QEMUFormatQCOW2, osbuild.QCOW2Options{Compat: "1.1"})
pipelines = append(pipelines, qemuPipeline.Serialize())
return pipelines, nil
}
@ -76,11 +76,11 @@ func vhdPipelines(t *imageType, customizations *blueprint.Customizations, option
diskfile := "disk.img"
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(packageSetSpecs[osPkgsKey], customizations.GetKernel().Name)
imagePipeline := liveImagePipeline(treePipeline.Name(), diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
imagePipeline := liveImagePipeline(&buildPipeline, &treePipeline, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, imagePipeline.Serialize())
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatVPC, nil)
pipelines = append(pipelines, *qemuPipeline)
qemuPipeline := qemuPipeline(&buildPipeline, &imagePipeline, diskfile, t.filename, osbuild.QEMUFormatVPC, nil)
pipelines = append(pipelines, qemuPipeline.Serialize())
return pipelines, nil
}
@ -105,11 +105,11 @@ func vmdkPipelines(t *imageType, customizations *blueprint.Customizations, optio
diskfile := "disk.img"
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(packageSetSpecs[osPkgsKey], customizations.GetKernel().Name)
imagePipeline := liveImagePipeline(treePipeline.Name(), diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
imagePipeline := liveImagePipeline(&buildPipeline, &treePipeline, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, imagePipeline.Serialize())
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatVMDK, osbuild.VMDKOptions{Subformat: osbuild.VMDKSubformatStreamOptimized})
pipelines = append(pipelines, *qemuPipeline)
qemuPipeline := qemuPipeline(&buildPipeline, &imagePipeline, diskfile, t.filename, osbuild.QEMUFormatVMDK, osbuild.VMDKOptions{Subformat: osbuild.VMDKSubformatStreamOptimized})
pipelines = append(pipelines, qemuPipeline.Serialize())
return pipelines, nil
}
@ -134,11 +134,11 @@ func openstackPipelines(t *imageType, customizations *blueprint.Customizations,
diskfile := "disk.img"
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(packageSetSpecs[osPkgsKey], customizations.GetKernel().Name)
imagePipeline := liveImagePipeline(treePipeline.Name(), diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
imagePipeline := liveImagePipeline(&buildPipeline, &treePipeline, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, imagePipeline.Serialize())
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatQCOW2, nil)
pipelines = append(pipelines, *qemuPipeline)
qemuPipeline := qemuPipeline(&buildPipeline, &imagePipeline, diskfile, t.filename, osbuild.QEMUFormatQCOW2, nil)
pipelines = append(pipelines, qemuPipeline.Serialize())
return pipelines, nil
}
@ -164,8 +164,8 @@ func ec2CommonPipelines(t *imageType, customizations *blueprint.Customizations,
pipelines = append(pipelines, treePipeline.Serialize())
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(packageSetSpecs[osPkgsKey], customizations.GetKernel().Name)
imagePipeline := liveImagePipeline(treePipeline.Name(), diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
imagePipeline := liveImagePipeline(&buildPipeline, &treePipeline, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, imagePipeline.Serialize())
return pipelines, nil
}
@ -541,51 +541,30 @@ func bootISOPipeline(filename, isolabel, arch string, isolinux bool) *osbuild.Pi
return p
}
func liveImagePipeline(inputPipelineName string, outputFilename string, pt *disk.PartitionTable, arch *architecture, kernelVer string) *osbuild.Pipeline {
p := new(osbuild.Pipeline)
p.Name = "image"
p.Build = "name:build"
func liveImagePipeline(buildPipeline *pipeline.BuildPipeline, treePipeline *pipeline.OSPipeline, outputFilename string, pt *disk.PartitionTable, arch *architecture, kernelVer string) pipeline.LiveImgPipeline {
p := pipeline.NewLiveImgPipeline(buildPipeline, treePipeline)
for _, stage := range osbuild.GenImagePrepareStages(pt, outputFilename, osbuild.PTSfdisk) {
p.AddStage(stage)
}
inputName := "root-tree"
copyOptions, copyDevices, copyMounts := osbuild.GenCopyFSTreeOptions(inputName, inputPipelineName, outputFilename, pt)
copyInputs := osbuild.NewCopyStagePipelineTreeInputs(inputName, inputPipelineName)
p.AddStage(osbuild.NewCopyStage(copyOptions, copyInputs, copyDevices, copyMounts))
for _, stage := range osbuild.GenImageFinishStages(pt, outputFilename) {
p.AddStage(stage)
}
loopback := osbuild.NewLoopbackDevice(&osbuild.LoopbackDeviceOptions{Filename: outputFilename})
p.AddStage(bootloaderInstStage(outputFilename, pt, arch, kernelVer, copyDevices, copyMounts, loopback))
return p
}
func qemuPipeline(inputPipelineName, inputFilename, outputFilename string, format osbuild.QEMUFormat, formatOptions osbuild.QEMUFormatOptions) *osbuild.Pipeline {
p := new(osbuild.Pipeline)
p.Name = string(format)
p.Build = "name:build"
qemuStage := osbuild.NewQEMUStage(
osbuild.NewQEMUStageOptions(outputFilename, format, formatOptions),
osbuild.NewQemuStagePipelineFilesInputs(inputPipelineName, inputFilename),
)
p.AddStage(qemuStage)
return p
}
func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *architecture, kernelVer string, devices *osbuild.Devices, mounts *osbuild.Mounts, disk *osbuild.Device) *osbuild.Stage {
platform := arch.legacy
if platform != "" {
return osbuild.NewGrub2InstStage(osbuild.NewGrub2InstStageOption(filename, pt, platform))
}
p.Filename = outputFilename
if arch.name == distro.S390xArchName {
return osbuild.NewZiplInstStage(osbuild.NewZiplInstStageOptions(kernelVer, pt), disk, devices, mounts)
p.BootLoader = pipeline.BOOTLOADER_ZIPL
} else {
p.BootLoader = pipeline.BOOTLOADER_GRUB
p.GRUBLegacy = arch.legacy
}
return nil
p.KernelVer = kernelVer
p.PartitionTable = *pt
return p
}
func qemuPipeline(buildPipeline *pipeline.BuildPipeline, imagePipeline *pipeline.LiveImgPipeline, inputFilename, outputFilename string, format osbuild.QEMUFormat, formatOptions osbuild.QEMUFormatOptions) pipeline.QemuPipeline {
p := pipeline.NewQemuPipeline(buildPipeline, imagePipeline, string(format))
p.InputFilename = inputFilename
p.OutputFilename = outputFilename
p.Format = format
p.FormatOptions = formatOptions
return p
}

View file

@ -0,0 +1,52 @@
package pipeline
import (
"github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/osbuild2"
)
type LiveImgPipeline struct {
Pipeline
PartitionTable disk.PartitionTable
BootLoader BootLoader
GRUBLegacy string
KernelVer string
treePipeline *Pipeline
Filename string
}
func NewLiveImgPipeline(buildPipeline *BuildPipeline, treePipeline *OSPipeline) LiveImgPipeline {
return LiveImgPipeline{
Pipeline: New("image", &buildPipeline.Pipeline),
treePipeline: &treePipeline.Pipeline,
}
}
func (p LiveImgPipeline) Serialize() osbuild2.Pipeline {
pipeline := p.Pipeline.Serialize()
for _, stage := range osbuild2.GenImagePrepareStages(&p.PartitionTable, p.Filename, osbuild2.PTSfdisk) {
pipeline.AddStage(stage)
}
inputName := "root-tree"
copyOptions, copyDevices, copyMounts := osbuild2.GenCopyFSTreeOptions(inputName, p.treePipeline.Name(), p.Filename, &p.PartitionTable)
copyInputs := osbuild2.NewCopyStagePipelineTreeInputs(inputName, p.treePipeline.Name())
pipeline.AddStage(osbuild2.NewCopyStage(copyOptions, copyInputs, copyDevices, copyMounts))
for _, stage := range osbuild2.GenImageFinishStages(&p.PartitionTable, p.Filename) {
pipeline.AddStage(stage)
}
switch p.BootLoader {
case BOOTLOADER_GRUB:
if p.GRUBLegacy != "" {
pipeline.AddStage(osbuild2.NewGrub2InstStage(osbuild2.NewGrub2InstStageOption(p.Filename, &p.PartitionTable, p.GRUBLegacy)))
}
case BOOTLOADER_ZIPL:
loopback := osbuild2.NewLoopbackDevice(&osbuild2.LoopbackDeviceOptions{Filename: p.Filename})
pipeline.AddStage(osbuild2.NewZiplInstStage(osbuild2.NewZiplInstStageOptions(p.KernelVer, &p.PartitionTable), loopback, copyDevices, copyMounts))
}
return pipeline
}

View file

@ -0,0 +1,33 @@
package pipeline
import (
"github.com/osbuild/osbuild-composer/internal/osbuild2"
)
type QemuPipeline struct {
Pipeline
imgPipeline *Pipeline
InputFilename string
OutputFilename string
// TODO: don't expose the osbuild2 types in the API
Format osbuild2.QEMUFormat
FormatOptions osbuild2.QEMUFormatOptions
}
func NewQemuPipeline(buildPipeline *BuildPipeline, imgPipeline *LiveImgPipeline, name string) QemuPipeline {
return QemuPipeline{
Pipeline: New(name, &buildPipeline.Pipeline),
imgPipeline: &imgPipeline.Pipeline,
}
}
func (p QemuPipeline) Serialize() osbuild2.Pipeline {
pipeline := p.Pipeline.Serialize()
pipeline.AddStage(osbuild2.NewQEMUStage(
osbuild2.NewQEMUStageOptions(p.OutputFilename, p.Format, p.FormatOptions),
osbuild2.NewQemuStagePipelineFilesInputs(p.imgPipeline.Name(), p.InputFilename),
))
return pipeline
}