Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootc_disk: Add support for vmdk, ova #504

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package image
import (
"fmt"
"math/rand"
"path/filepath"
"strings"

"github.com/osbuild/images/pkg/artifact"
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/runner"
)
Expand Down Expand Up @@ -47,15 +50,38 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes
panic(fmt.Sprintf("no compression is allowed with %q format for %q", imgFormat, img.name))
}

// In the bootc flow, we reuse the host container context for tools;
// this is signified by passing nil to the below pipelines.
var hostPipeline manifest.Build

opts := &baseRawOstreeImageOpts{useBootupd: true}
baseImage := baseRawOstreeImage(img.OSTreeDiskImage, buildPipeline, opts)
switch imgFormat {
case platform.FORMAT_QCOW2:
// qcow2 runs without a build pipeline directly from "bib"
qcow2Pipeline := manifest.NewQCOW2(nil, baseImage)
qcow2Pipeline := manifest.NewQCOW2(hostPipeline, baseImage)
qcow2Pipeline.Compat = img.Platform.GetQCOW2Compat()
qcow2Pipeline.SetFilename(img.Filename)
return qcow2Pipeline.Export(), nil
// TODO: refactor to share this with disk.go; note here the build pipeline runs
mvo5 marked this conversation as resolved.
Show resolved Hide resolved
// on the host (that's the nil)
case platform.FORMAT_VMDK:
vmdkPipeline := manifest.NewVMDK(hostPipeline, baseImage)
vmdkPipeline.SetFilename(img.Filename)
return vmdkPipeline.Export(), nil
case platform.FORMAT_OVA:
vmdkPipeline := manifest.NewVMDK(hostPipeline, baseImage)
ovfPipeline := manifest.NewOVF(hostPipeline, vmdkPipeline)
tarPipeline := manifest.NewTar(hostPipeline, ovfPipeline, "archive")
tarPipeline.Format = osbuild.TarArchiveFormatUstar
tarPipeline.SetFilename(img.Filename)
extLess := strings.TrimSuffix(img.Filename, filepath.Ext(img.Filename))
// The .ovf descriptor needs to be the first file in the archive
tarPipeline.Paths = []string{
fmt.Sprintf("%s.ovf", extLess),
fmt.Sprintf("%s.mf", extLess),
fmt.Sprintf("%s.vmdk", extLess),
}
return tarPipeline.Export(), nil
}

switch img.Compression {
Expand Down
19 changes: 15 additions & 4 deletions pkg/image/bootc_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ func makeFakeDigest(t *testing.T) string {
}

type bootcDiskImageTestOpts struct {
BIOS bool
ImageFormat platform.ImageFormat
BIOS bool
}

func makeFakePlatform(opts *bootcDiskImageTestOpts) platform.Platform {
return &platform.X86{
BasePlatform: platform.BasePlatform{
ImageFormat: platform.FORMAT_QCOW2,
ImageFormat: opts.ImageFormat,
},
BIOS: opts.BIOS,
}
}

func makeBootcDiskImageOsbuildManifest(t *testing.T, opts *bootcDiskImageTestOpts) manifest.OSBuildManifest {
if opts == nil {
opts = &bootcDiskImageTestOpts{}
opts = &bootcDiskImageTestOpts{
ImageFormat: platform.FORMAT_QCOW2,
}
}

containerSource := container.SourceSpec{
Expand Down Expand Up @@ -116,6 +119,14 @@ func TestBootcDiskImageInstantiateNoBuildpipelineForQcow2(t *testing.T) {
assert.Equal(t, qcowPipeline["build"], nil)
}

func TestBootcDiskImageInstantiateVmdk(t *testing.T) {
opts := &bootcDiskImageTestOpts{ImageFormat: platform.FORMAT_VMDK}
osbuildManifest := makeBootcDiskImageOsbuildManifest(t, opts)

pipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "vmdk")
require.NotNil(t, pipeline)
}

func TestBootcDiskImageUsesBootupd(t *testing.T) {
osbuildManifest := makeBootcDiskImageOsbuildManifest(t, nil)

Expand All @@ -134,7 +145,7 @@ func TestBootcDiskImageUsesBootupd(t *testing.T) {

func TestBootcDiskImageBootupdBiosSupport(t *testing.T) {
for _, withBios := range []bool{false, true} {
osbuildManifest := makeBootcDiskImageOsbuildManifest(t, &bootcDiskImageTestOpts{BIOS: withBios})
osbuildManifest := makeBootcDiskImageOsbuildManifest(t, &bootcDiskImageTestOpts{BIOS: withBios, ImageFormat: platform.FORMAT_QCOW2})

imagePipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "image")
require.NotNil(t, imagePipeline)
Expand Down
11 changes: 8 additions & 3 deletions pkg/manifest/ovf.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ type OVF struct {
}

// NewOVF creates a new OVF pipeline. imgPipeline is the pipeline producing the vmdk image.
func NewOVF(buidPipeline Build, imgPipeline *VMDK) *OVF {
func NewOVF(buildPipeline Build, imgPipeline *VMDK) *OVF {
p := &OVF{
Base: NewBase("ovf", buidPipeline),
Base: NewBase("ovf", buildPipeline),
imgPipeline: imgPipeline,
}
buidPipeline.addDependent(p)
// See similar logic in qcow2 to run on the host
if buildPipeline != nil {
buildPipeline.addDependent(p)
} else {
imgPipeline.Manifest().addPipeline(p)
}
return p
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/manifest/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func NewTar(buildPipeline Build, inputPipeline Pipeline, pipelinename string) *T
inputPipeline: inputPipeline,
filename: "image.tar",
}
buildPipeline.addDependent(p)
// See similar logic in qcow2 to run on the host
if buildPipeline != nil {
buildPipeline.addDependent(p)
} else {
inputPipeline.Manifest().addPipeline(p)
}
return p
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/manifest/vmdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ func NewVMDK(buildPipeline Build, imgPipeline FilePipeline) *VMDK {
imgPipeline: imgPipeline,
filename: "image.vmdk",
}
buildPipeline.addDependent(p)
// See similar logic in qcow2 to run on the host
if buildPipeline != nil {
buildPipeline.addDependent(p)
} else {
imgPipeline.Manifest().addPipeline(p)
}
return p
}

Expand Down
Loading