Skip to content

Commit

Permalink
image: generate the all-manifest for bootc-disk
Browse files Browse the repository at this point in the history
The bootc-disk image manifest now always contains all pipelines needed
to generate all image types.  This way we can build any combination of
disk images depending on what we need to export without needing to
conditionally add or remove pipelines.

The Platform no longer needs to be read, since we're generating all of
the formats and the architecture depends on the source container.
However, the Platform is still required for specifying the boot mode
(enabling or disabling BIOS boot).

The first return value of the InstantiateManifestFromContainers()
function, the artifact, was not used and has been removed now.
  • Loading branch information
achilleas-k authored and mvo5 committed Mar 13, 2024
1 parent 88e71d7 commit f0de636
Showing 1 changed file with 25 additions and 44 deletions.
69 changes: 25 additions & 44 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ 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 All @@ -35,56 +31,41 @@ func NewBootcDiskImage(container container.SourceSpec) *BootcDiskImage {
func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifest,
containers []container.SourceSpec,
runner runner.Runner,
rng *rand.Rand) (*artifact.Artifact, error) {
rng *rand.Rand) error {

buildPipeline := manifest.NewBuildFromContainer(m, runner, containers, &manifest.BuildOptions{ContainerBuildable: true})
buildPipeline.Checkpoint()

// don't support compressing non-raw images
imgFormat := img.Platform.GetImageFormat()
if imgFormat == platform.FORMAT_UNSET {
// treat unset as raw for this check
imgFormat = platform.FORMAT_RAW
}

// 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}

fileBasename := img.Filename

// In BIB, we export multiple images from the same pipeline so we use the
// filename as the basename for each export and set the extensions based on
// each file format.
baseImage := baseRawOstreeImage(img.OSTreeDiskImage, buildPipeline, opts)
baseImage.SetFilename(fmt.Sprintf("%s.raw", fileBasename))

qcow2Pipeline := manifest.NewQCOW2(hostPipeline, baseImage)
qcow2Pipeline.Compat = img.Platform.GetQCOW2Compat()
qcow2Pipeline.SetFilename(fmt.Sprintf("%s.qcow2", fileBasename))

vmdkPipeline := manifest.NewVMDK(hostPipeline, baseImage)
vmdkPipeline.SetFilename(fmt.Sprintf("%s.vmdk", fileBasename))

// In BIB, we intend to export multiple images from the same pipeline and
// this is the expected filename for the raw images. Set it so that it's
// always disk.raw even when we're building a qcow2 or other image type.
baseImage.SetFilename("disk.raw")
switch imgFormat {
case platform.FORMAT_QCOW2:
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
// 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
ovfPipeline := manifest.NewOVF(hostPipeline, vmdkPipeline)
tarPipeline := manifest.NewTar(hostPipeline, ovfPipeline, "archive")
tarPipeline.Format = osbuild.TarArchiveFormatUstar
tarPipeline.SetFilename(fmt.Sprintf("%s.tar", fileBasename))
// The .ovf descriptor needs to be the first file in the archive
tarPipeline.Paths = []string{
fmt.Sprintf("%s.ovf", fileBasename),
fmt.Sprintf("%s.mf", fileBasename),
fmt.Sprintf("%s.vmdk", fileBasename),
}
baseImage.SetFilename(img.Filename)
return baseImage.Export(), nil
return nil
}

0 comments on commit f0de636

Please sign in to comment.