From 7bfd9dadf01a30713c1c71671ad2838753ebc0cd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 5 Sep 2024 18:56:10 +0200 Subject: [PATCH] image: add `vhd`/`vpc` support to `BootcDiskImage` This will help konflux to build azure/vhd images directly. Closes: https://github.com/osbuild/bootc-image-builder/issues/132 --- pkg/image/bootc_disk.go | 4 ++++ pkg/image/bootc_disk_test.go | 13 +++++++++++++ pkg/manifest/vpc.go | 13 +++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pkg/image/bootc_disk.go b/pkg/image/bootc_disk.go index d016af4255..a1037e6cc5 100644 --- a/pkg/image/bootc_disk.go +++ b/pkg/image/bootc_disk.go @@ -75,6 +75,9 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes vmdkPipeline := manifest.NewVMDK(hostPipeline, rawImage) vmdkPipeline.SetFilename(fmt.Sprintf("%s.vmdk", fileBasename)) + vhdPipeline := manifest.NewVPC(hostPipeline, rawImage) + vhdPipeline.SetFilename(fmt.Sprintf("%s.vhd", fileBasename)) + ovfPipeline := manifest.NewOVF(hostPipeline, vmdkPipeline) tarPipeline := manifest.NewTar(hostPipeline, ovfPipeline, "archive") tarPipeline.Format = osbuild.TarArchiveFormatUstar @@ -84,6 +87,7 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes fmt.Sprintf("%s.ovf", fileBasename), fmt.Sprintf("%s.mf", fileBasename), fmt.Sprintf("%s.vmdk", fileBasename), + fmt.Sprintf("%s.vhd", fileBasename), } return nil } diff --git a/pkg/image/bootc_disk_test.go b/pkg/image/bootc_disk_test.go index 095a60745d..f0937625eb 100644 --- a/pkg/image/bootc_disk_test.go +++ b/pkg/image/bootc_disk_test.go @@ -130,6 +130,15 @@ func TestBootcDiskImageInstantiateNoBuildpipelineForQcow2(t *testing.T) { assert.Equal(t, qcowPipeline["build"], nil) } +func TestBootcDiskImageInstantiateNoBuildpipelineForVpc(t *testing.T) { + osbuildManifest := makeBootcDiskImageOsbuildManifest(t, nil) + + vpcPipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "vpc") + require.NotNil(t, vpcPipeline) + // no build pipeline for vpc + assert.Equal(t, vpcPipeline["build"], nil) +} + func TestBootcDiskImageInstantiateVmdk(t *testing.T) { opts := &bootcDiskImageTestOpts{ImageFormat: platform.FORMAT_VMDK} osbuildManifest := makeBootcDiskImageOsbuildManifest(t, opts) @@ -185,6 +194,10 @@ func TestBootcDiskImageExportPipelines(t *testing.T) { vmdkPipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "vmdk") require.NotNil(vmdkPipeline) + // vpc pipeline for the vhd + vpcPipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "vpc") + require.NotNil(vpcPipeline) + // tar pipeline for ova tarPipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "archive") require.NotNil(tarPipeline) diff --git a/pkg/manifest/vpc.go b/pkg/manifest/vpc.go index bcb6ae94c1..7fea150712 100644 --- a/pkg/manifest/vpc.go +++ b/pkg/manifest/vpc.go @@ -5,14 +5,14 @@ import ( "github.com/osbuild/images/pkg/osbuild" ) -// A VPC turns a raw image file into qemu-based image format, such as qcow2. +// A VPC turns a raw image file into qemu-based image format, such as vhd. type VPC struct { Base filename string ForceSize *bool - imgPipeline *RawImage + imgPipeline FilePipeline } func (p VPC) Filename() string { @@ -26,13 +26,18 @@ func (p *VPC) SetFilename(filename string) { // NewVPC createsa new Qemu pipeline. imgPipeline is the pipeline producing the // raw image. The pipeline name is the name of the new pipeline. Filename is the name // of the produced image. -func NewVPC(buildPipeline Build, imgPipeline *RawImage) *VPC { +func NewVPC(buildPipeline Build, imgPipeline FilePipeline) *VPC { p := &VPC{ Base: NewBase("vpc", buildPipeline), imgPipeline: imgPipeline, filename: "image.vhd", } - buildPipeline.addDependent(p) + // vpc can run outside the build pipeline for e.g. "bib" + if buildPipeline != nil { + buildPipeline.addDependent(p) + } else { + imgPipeline.Manifest().addPipeline(p) + } return p }