debian-forge-composer/internal/image/live.go
Tom Gundersen 0f5846326c image: introduce image kinds for Fedora
Implement all of Fedora in terms of this new abstraction. What used to be the
manifest functions (and before that the pipeline functions) are now the image
functions, whose purpose is to instantiate the right image kind structs from the
image type definitions we currently have in the distro definition.
2022-07-22 16:04:07 +02:00

70 lines
2.2 KiB
Go

package image
import (
"math/rand"
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/environment"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/runner"
"github.com/osbuild/osbuild-composer/internal/workload"
)
type LiveImage struct {
Base
Platform platform.Platform
PartitionTable *disk.PartitionTable
OSCustomizations manifest.OSCustomizations
Environment environment.Environment
Workload workload.Workload
Filename string
}
func NewLiveImage() *LiveImage {
return &LiveImage{
Base: NewBase("live-image"),
}
}
func (img *LiveImage) InstantiateManifest(m *manifest.Manifest,
repos []rpmmd.RepoConfig,
runner runner.Runner,
rng *rand.Rand) (*artifact.Artifact, error) {
buildPipeline := manifest.NewBuild(m, runner, repos)
buildPipeline.Checkpoint()
osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline.PartitionTable = img.PartitionTable
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
imagePipeline := manifest.NewRawImage(m, buildPipeline, osPipeline)
var artifact *artifact.Artifact
switch img.Platform.GetImageFormat() {
case platform.FORMAT_RAW:
imagePipeline.Filename = img.Filename
artifact = imagePipeline.Export()
case platform.FORMAT_QCOW2:
qcow2Pipeline := manifest.NewQCOW2(m, buildPipeline, imagePipeline)
qcow2Pipeline.Filename = img.Filename
qcow2Pipeline.Compat = img.Platform.GetQCOW2Compat()
artifact = qcow2Pipeline.Export()
case platform.FORMAT_VHD:
vpcPipeline := manifest.NewVPC(m, buildPipeline, imagePipeline)
vpcPipeline.Filename = img.Filename
artifact = vpcPipeline.Export()
case platform.FORMAT_VMDK:
vmdkPipeline := manifest.NewVMDK(m, buildPipeline, imagePipeline)
vmdkPipeline.Filename = img.Filename
artifact = vmdkPipeline.Export()
default:
panic("invalid image format for image kind")
}
return artifact, nil
}