debian-forge-composer/cmd/osbuild-playground/my-image.go
Tom Gundersen 5a15608c89 image: add image kind abstraction
This abstracts away the manifest instantiation. The idea is that we define one
of these image kind types to represent a group of image types that are
sufficiently similar. Each image kind will have a struct with with all the
properties that can be customised for the image and a function to turn that into
an actual manifest. This is similar to how distro/fedora/manifest.go and
cmd/osbuild-playground works today, and aspires to move these closer together
and to eventually make the distro definitions simpler.

For now cmd/osbuild-playground is moved over to using the new abstraction.
2022-07-22 16:04:07 +02:00

57 lines
1.4 KiB
Go

package main
import (
"math/rand"
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/disk"
"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 MyImage struct {
MyOption string `json:"my_option"`
}
func (img *MyImage) Name() string {
return "my-image"
}
func init() {
AddImageType(&MyImage{})
}
func (img *MyImage) InstantiateManifest(m *manifest.Manifest,
repos []rpmmd.RepoConfig,
runner runner.Runner,
rng *rand.Rand) (*artifact.Artifact, error) {
// Let's create a simple raw image!
// configure a build pipeline
build := manifest.NewBuild(m, runner, repos)
build.Checkpoint()
// create an x86_64 platform with bios boot
platform := &platform.X86{
BIOS: true,
}
// TODO: add helper
pt, err := disk.NewPartitionTable(&basePT, nil, 0, false, rng)
if err != nil {
panic(err)
}
// create a minimal bootable OS tree
os := manifest.NewOS(m, build, platform, repos)
os.PartitionTable = pt // we need a partition table
os.KernelName = "kernel" // use the default fedora kernel
// create a raw image containing the OS tree created above
raw := manifest.NewRawImage(m, build, os)
artifact := raw.Export()
return artifact, nil
}