From 1687937c51f12258f18a520a1fee9639290f6d6c Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Thu, 30 Mar 2023 11:44:37 +0200 Subject: [PATCH] internal/image: add ova support to live image --- internal/image/live.go | 8 +++++ internal/manifest/ovf.go | 57 +++++++++++++++++++++++++++++++++++ internal/platform/platform.go | 3 ++ 3 files changed, 68 insertions(+) create mode 100644 internal/manifest/ovf.go diff --git a/internal/image/live.go b/internal/image/live.go index cb6899b01..a4a8f794e 100644 --- a/internal/image/live.go +++ b/internal/image/live.go @@ -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 diff --git a/internal/manifest/ovf.go b/internal/manifest/ovf.go new file mode 100644 index 000000000..f8bbd1cf5 --- /dev/null +++ b/internal/manifest/ovf.go @@ -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"} +} diff --git a/internal/platform/platform.go b/internal/platform/platform.go index aa2f5b73c..1157137d7 100644 --- a/internal/platform/platform.go +++ b/internal/platform/platform.go @@ -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") }