Skip to content

Commit

Permalink
image: add vhd/vpc support to BootcDiskImage
Browse files Browse the repository at this point in the history
This will help konflux to build azure/vhd images directly.

Closes: osbuild/bootc-image-builder#132
  • Loading branch information
mvo5 authored and achilleas-k committed Sep 6, 2024
1 parent a857cec commit 7bfd9da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
13 changes: 13 additions & 0 deletions pkg/image/bootc_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions pkg/manifest/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 7bfd9da

Please sign in to comment.