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.
This commit is contained in:
Tom Gundersen 2022-07-10 15:40:38 +01:00 committed by Christian Kellner
parent 5a15608c89
commit 0f5846326c
8 changed files with 654 additions and 497 deletions

View file

@ -0,0 +1,47 @@
package image
import (
"math/rand"
"github.com/osbuild/osbuild-composer/internal/artifact"
"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 BaseContainer struct {
Base
Platform platform.Platform
OSCustomizations manifest.OSCustomizations
Environment environment.Environment
Workload workload.Workload
Filename string
}
func NewBaseContainer() *BaseContainer {
return &BaseContainer{
Base: NewBase("base-container"),
}
}
func (img *BaseContainer) 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.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
ociPipeline := manifest.NewOCIContainer(m, buildPipeline, osPipeline)
ociPipeline.Filename = img.Filename
artifact := ociPipeline.Export()
return artifact, nil
}

70
internal/image/live.go Normal file
View file

@ -0,0 +1,70 @@
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
}

View file

@ -0,0 +1,54 @@
package image
import (
"math/rand"
"github.com/osbuild/osbuild-composer/internal/artifact"
"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 OSTreeArchive struct {
Base
Platform platform.Platform
OSCustomizations manifest.OSCustomizations
Environment environment.Environment
Workload workload.Workload
OSTreeParent manifest.OSTree
OSTreeRef string
OSVersion string
Filename string
}
func NewOSTreeArchive() *OSTreeArchive {
return &OSTreeArchive{
Base: NewBase("ostree-archive"),
}
}
func (img *OSTreeArchive) 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.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
osPipeline.OSTree = &img.OSTreeParent
ostreeCommitPipeline := manifest.NewOSTreeCommit(m, buildPipeline, osPipeline, img.OSTreeRef)
ostreeCommitPipeline.OSVersion = img.OSVersion
tarPipeline := manifest.NewTar(m, buildPipeline, &ostreeCommitPipeline.Base, "commit-archive")
tarPipeline.Filename = img.Filename
artifact := tarPipeline.Export()
return artifact, nil
}

View file

@ -0,0 +1,70 @@
package image
import (
"math/rand"
"github.com/osbuild/osbuild-composer/internal/artifact"
"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 OSTreeContainer struct {
Base
Platform platform.Platform
OSCustomizations manifest.OSCustomizations
Environment environment.Environment
Workload workload.Workload
OSTreeParent manifest.OSTree
OSTreeRef string // TODO: merge into the above
OSVersion string
ExtraContainerPackages rpmmd.PackageSet
ContainerLanguage string
Filename string
}
func NewOSTreeContainer() *OSTreeContainer {
return &OSTreeContainer{
Base: NewBase("ostree-container"),
}
}
func (img *OSTreeContainer) 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.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
osPipeline.OSTree = &img.OSTreeParent
commitPipeline := manifest.NewOSTreeCommit(m, buildPipeline, osPipeline, img.OSTreeRef)
commitPipeline.OSVersion = img.OSVersion
nginxConfigPath := "/etc/nginx.conf"
listenPort := "8080"
serverPipeline := manifest.NewOSTreeCommitServer(m,
buildPipeline,
img.Platform,
repos,
commitPipeline,
nginxConfigPath,
listenPort)
serverPipeline.Language = img.ContainerLanguage
containerPipeline := manifest.NewOCIContainer(m, buildPipeline, serverPipeline)
containerPipeline.Cmd = []string{"nginx", "-c", nginxConfigPath}
containerPipeline.ExposedPorts = []string{listenPort}
containerPipeline.Filename = img.Filename
artifact := containerPipeline.Export()
return artifact, nil
}

View file

@ -0,0 +1,79 @@
package image
import (
"math/rand"
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"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"
)
type OSTreeInstaller struct {
Base
Platform platform.Platform
ExtraBasePackages rpmmd.PackageSet
Users []blueprint.UserCustomization
Groups []blueprint.GroupCustomization
ISOLabelTempl string
Product string
Variant string
OSName string
OSVersion string
Release string
OSTreeURL string
OSTreeRef string
OSTreeCommit string
Filename string
}
func NewOSTreeInstaller() *OSTreeInstaller {
return &OSTreeInstaller{
Base: NewBase("ostree-installer"),
}
}
func (img *OSTreeInstaller) InstantiateManifest(m *manifest.Manifest,
repos []rpmmd.RepoConfig,
runner runner.Runner,
rng *rand.Rand) (*artifact.Artifact, error) {
buildPipeline := manifest.NewBuild(m, runner, repos)
buildPipeline.Checkpoint()
anacondaPipeline := manifest.NewAnaconda(m,
buildPipeline,
img.Platform,
repos, "kernel",
img.Product,
img.OSVersion)
anacondaPipeline.ExtraPackages = img.ExtraBasePackages.Include
anacondaPipeline.ExtraRepos = img.ExtraBasePackages.Repositories
anacondaPipeline.Users = len(img.Users)+len(img.Groups) > 0
anacondaPipeline.Variant = img.Variant
anacondaPipeline.Biosdevname = (img.Platform.GetArch() == platform.ARCH_X86_64)
anacondaPipeline.Checkpoint()
isoTreePipeline := manifest.NewISOTree(m,
buildPipeline,
anacondaPipeline,
img.OSTreeCommit,
img.OSTreeURL,
img.OSTreeRef,
img.ISOLabelTempl)
isoTreePipeline.Release = img.Release
isoTreePipeline.OSName = img.OSName
isoTreePipeline.UEFIVendor = img.Platform.GetUEFIVendor()
isoTreePipeline.Users = img.Users
isoTreePipeline.Groups = img.Groups
isoPipeline := manifest.NewISO(m, buildPipeline, isoTreePipeline)
isoPipeline.Filename = img.Filename
artifact := isoPipeline.Export()
return artifact, nil
}