We have three kinds of operating system trees, until we unify them to one, hide them behind one interface. Use this to read the architecture from the Tree rather than pass it in as a string to parent pipelines. Also, make the filename parameter optional in a few places, there should be no reason to set this rather than introspect it (except for backwards compatibility). Lastly, add another playground example sample to build a raw image.
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"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) error {
|
|
// Let's create a simple raw image!
|
|
|
|
// configure a build pipeline
|
|
build := manifest.NewBuild(m, runner, repos)
|
|
|
|
// create an x86_64 platform with bios boot
|
|
platform := &platform.X86{
|
|
BIOS: true,
|
|
}
|
|
|
|
// TODO: add helper
|
|
// math/rand is good enough in this case
|
|
/* #nosec G404 */
|
|
pt, err := disk.NewPartitionTable(&basePT, nil, 0, false, rand.New(rand.NewSource(0)))
|
|
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
|
|
manifest.NewRawImage(m, build, os)
|
|
|
|
return nil
|
|
}
|
|
|
|
// TODO: make internal
|
|
func (img *MyImage) GetExports() []string {
|
|
return []string{"image"}
|
|
}
|
|
|
|
func (img *MyImage) GetCheckpoints() []string {
|
|
return []string{"build"}
|
|
}
|