internal/image: add ova support to live image

This commit is contained in:
Sanne Raymaekers 2023-03-30 11:44:37 +02:00
parent 53fa47f104
commit 1687937c51
3 changed files with 68 additions and 0 deletions

View file

@ -93,6 +93,14 @@ func (img *LiveImage) InstantiateManifest(m *manifest.Manifest,
}
artifactPipeline = vmdkPipeline
artifact = vmdkPipeline.Export()
case platform.FORMAT_OVA:
vmdkPipeline := manifest.NewVMDK(m, buildPipeline, imagePipeline)
ovfPipeline := manifest.NewOVF(m, buildPipeline, vmdkPipeline)
artifactPipeline := manifest.NewTar(m, buildPipeline, ovfPipeline, "archive")
artifactPipeline.Format = osbuild.TarArchiveFormatOldgnu
artifactPipeline.RootNode = osbuild.TarRootNodeOmit
artifactPipeline.Filename = img.Filename
artifact = artifactPipeline.Export()
case platform.FORMAT_GCE:
// NOTE(akoutsou): temporary workaround; filename required for GCP
// TODO: define internal raw filename on image type

57
internal/manifest/ovf.go Normal file
View file

@ -0,0 +1,57 @@
package manifest
import (
"fmt"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
// A OVF copies a vmdk image to it's own tree and generates an OVF descriptor
type OVF struct {
Base
imgPipeline *VMDK
}
// NewOVF creates a new OVF pipeline. imgPipeline is the pipeline producing the vmdk image.
func NewOVF(m *Manifest,
buildPipeline *Build,
imgPipeline *VMDK) *OVF {
p := &OVF{
Base: NewBase(m, "ovf", buildPipeline),
imgPipeline: imgPipeline,
}
if imgPipeline.Base.manifest != m {
panic("live image pipeline from different manifest")
}
buildPipeline.addDependent(p)
m.addPipeline(p)
return p
}
func (p *OVF) serialize() osbuild.Pipeline {
pipeline := p.Base.serialize()
inputName := "vmdk-tree"
pipeline.AddStage(osbuild.NewCopyStageSimple(
&osbuild.CopyStageOptions{
Paths: []osbuild.CopyStagePath{
osbuild.CopyStagePath{
From: fmt.Sprintf("input://%s/%s", inputName, p.imgPipeline.Export().Filename()),
To: "tree:///",
},
},
},
osbuild.NewPipelineTreeInputs(inputName, p.imgPipeline.Name()),
))
pipeline.AddStage(osbuild.NewOVFStage(&osbuild.OVFStageOptions{
Vmdk: p.imgPipeline.Filename,
}))
return pipeline
}
func (p *OVF) getBuildPackages() []string {
return []string{"qemu-img"}
}

View file

@ -18,6 +18,7 @@ const (
FORMAT_VMDK
FORMAT_VHD
FORMAT_GCE
FORMAT_OVA
)
func (a Arch) String() string {
@ -49,6 +50,8 @@ func (f ImageFormat) String() string {
return "vhd"
case FORMAT_GCE:
return "gce"
case FORMAT_OVA:
return "ova"
default:
panic("invalid image format")
}