Delete cmd/osbuild-playground

This command is part of the osbuild/images repo, where all image
definitions live. Having it in the osbuild-composer repository does not
add any value.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2024-01-03 14:41:26 +01:00 committed by Achilleas Koutsou
parent 34f4196677
commit c1affa6188
5 changed files with 0 additions and 348 deletions

View file

@ -1,107 +0,0 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"os"
"path"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/distroregistry"
"github.com/osbuild/images/pkg/image"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/osbuild-composer/internal/common"
)
var ImageTypes = make(map[string]image.ImageKind)
func AddImageType(img image.ImageKind) {
ImageTypes[img.Name()] = img
}
// osbuild-playground is a utility command and is often run from within the
// source tree. Find the dnf-json binary in case the osbuild-composer package
// isn't installed. This prioritises the local source version over the system
// version if run from within the source tree.
func findDnfJsonBin() string {
locations := []string{"./dnf-json", "/usr/libexec/osbuild-composer/dnf-json", "/usr/lib/osbuild-composer/dnf-json"}
for _, djPath := range locations {
_, err := os.Stat(djPath)
if !os.IsNotExist(err) {
return djPath
}
}
// can't run: panic
panic(fmt.Sprintf("could not find 'dnf-json' in any of the known paths: %+v", locations))
}
func main() {
var distroArg string
flag.StringVar(&distroArg, "distro", "host", "distro to build from")
var archArg string
flag.StringVar(&archArg, "arch", common.CurrentArch(), "architecture to build for")
var imageTypeArg string
flag.StringVar(&imageTypeArg, "type", "my-container", "image type to build")
flag.Parse()
// Path to options or '-' for stdin
optionsArg := flag.Arg(0)
img := ImageTypes[imageTypeArg]
if optionsArg != "" {
var reader io.Reader
if optionsArg == "-" {
reader = os.Stdin
} else {
var err error
reader, err = os.Open(optionsArg)
if err != nil {
panic("Could not open path to image options: " + err.Error())
}
}
file, err := io.ReadAll(reader)
if err != nil {
panic("Could not read image options: " + err.Error())
}
err = json.Unmarshal(file, img)
if err != nil {
panic("Could not parse image options: " + err.Error())
}
}
distros := distroregistry.NewDefault()
var d distro.Distro
if distroArg == "host" {
d = distros.FromHost()
if d == nil {
panic("host distro not supported")
}
} else {
d = distros.GetDistro(distroArg)
if d == nil {
panic(fmt.Sprintf("distro '%s' not supported\n", distroArg))
}
}
arch, err := d.GetArch(archArg)
if err != nil {
panic(fmt.Sprintf("arch '%s' not supported\n", archArg))
}
repos, err := rpmmd.LoadRepositories([]string{"./"}, d.Name())
if err != nil {
panic("could not load repositories for distro " + d.Name())
}
home, err := os.UserHomeDir()
if err != nil {
panic("os.UserHomeDir(): " + err.Error())
}
state_dir := path.Join(home, ".local/share/osbuild-playground/")
RunPlayground(img, d, arch, repos, state_dir)
}

View file

@ -1,64 +0,0 @@
package main
import (
"math/rand"
"github.com/osbuild/images/pkg/artifact"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/runner"
)
// MyContainer contains the arguments passed in as a JSON blob.
// You can replace them with whatever you want to use to
// configure your image. In the current example they are
// unused.
type MyContainer struct {
MyOption string `json:"my_option"`
}
// Name returns the name of the image type, used to select what kind
// of image to build.
func (img *MyContainer) Name() string {
return "my-container"
}
// init registeres this image type
func init() {
AddImageType(&MyContainer{})
}
// Build your manifest by attaching pipelines to it
//
// @m is the manifest you are constructing
// @options are what was passed in on the commandline
// @repos are the default repositories for the host OS/arch
// @runner is needed by any build pipelines
//
// Return nil when you are done, or an error if something
// went wrong. Your manifest will be streamed to osbuild
// for building.
func (img *MyContainer) InstantiateManifest(m *manifest.Manifest,
repos []rpmmd.RepoConfig,
runner runner.Runner,
rng *rand.Rand) (*artifact.Artifact, error) {
// Let's create a simple OCI container!
// configure a build pipeline
build := manifest.NewBuild(m, runner, repos, nil)
build.Checkpoint()
// create a minimal non-bootable OS tree
os := manifest.NewOS(m, build, &platform.X86{}, repos)
os.ExtraBasePackages = []string{"@core"}
os.OSCustomizations.Language = "en_US.UTF-8"
os.OSCustomizations.Hostname = "my-host"
os.OSCustomizations.Timezone = "UTC"
// create an OCI container containing the OS tree created above
container := manifest.NewOCIContainer(build, os)
artifact := container.Export()
return artifact, nil
}

View file

@ -1,57 +0,0 @@
package main
import (
"math/rand"
"github.com/osbuild/images/pkg/artifact"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/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, nil)
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, disk.RawPartitioningMode, nil, 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(build, os)
artifact := raw.Export()
return artifact, nil
}

View file

@ -1,56 +0,0 @@
package main
import "github.com/osbuild/images/pkg/disk"
var basePT = disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Partitions: []disk.Partition{
{
Size: 1048576, // 1MB
Bootable: true,
Type: disk.BIOSBootPartitionGUID,
UUID: disk.BIOSBootPartitionUUID,
},
{
Size: 209715200, // 200 MB
Type: disk.EFISystemPartitionGUID,
UUID: disk.EFISystemPartitionUUID,
Payload: &disk.Filesystem{
Type: "vfat",
UUID: disk.EFIFilesystemUUID,
Mountpoint: "/boot/efi",
Label: "EFI-SYSTEM",
FSTabOptions: "defaults,uid=0,gid=0,umask=077,shortname=winnt",
FSTabFreq: 0,
FSTabPassNo: 2,
},
},
{
Size: 524288000, // 500 MB
Type: disk.FilesystemDataGUID,
UUID: disk.FilesystemDataUUID,
Payload: &disk.Filesystem{
Type: "ext4",
Mountpoint: "/boot",
Label: "boot",
FSTabOptions: "defaults",
FSTabFreq: 0,
FSTabPassNo: 0,
},
},
{
Size: 2147483648, // 2GiB
Type: disk.FilesystemDataGUID,
UUID: disk.RootPartitionUUID,
Payload: &disk.Filesystem{
Type: "ext4",
Label: "root",
Mountpoint: "/",
FSTabOptions: "defaults",
FSTabFreq: 0,
FSTabPassNo: 0,
},
},
},
}

View file

@ -1,64 +0,0 @@
package main
import (
"fmt"
"math/rand"
"os"
"path"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/image"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/runner"
)
func RunPlayground(img image.ImageKind, d distro.Distro, arch distro.Arch, repos map[string][]rpmmd.RepoConfig, state_dir string) {
solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch.Name(), d.Name(), path.Join(state_dir, "rpmmd"))
solver.SetDNFJSONPath(findDnfJsonBin())
// Set cache size to 3 GiB
solver.SetMaxCacheSize(1 * 1024 * 1024 * 1024)
manifest := manifest.New()
/* #nosec G404 */
rnd := rand.New(rand.NewSource(0))
// TODO: query distro for runner
artifact, err := img.InstantiateManifest(&manifest, repos[arch.Name()], &runner.Fedora{Version: 36}, rnd)
if err != nil {
panic("InstantiateManifest() failed: " + err.Error())
}
packageSpecs := make(map[string][]rpmmd.PackageSpec)
for name, chain := range manifest.GetPackageSetChains() {
packages, err := solver.Depsolve(chain)
if err != nil {
panic(fmt.Sprintf("failed to depsolve for pipeline %s: %s\n", name, err.Error()))
}
packageSpecs[name] = packages
}
if err := solver.CleanCache(); err != nil {
// print to stderr but don't exit with error
fmt.Fprintf(os.Stderr, "could not clean dnf cache: %s", err.Error())
}
bytes, err := manifest.Serialize(packageSpecs, nil, nil)
if err != nil {
panic("failed to serialize manifest: " + err.Error())
}
store := path.Join(state_dir, "osbuild-store")
_, err = osbuild.RunOSBuild(bytes, store, "./", manifest.GetExports(), manifest.GetCheckpoints(), nil, false, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "could not run osbuild: %s", err.Error())
}
fmt.Fprintf(os.Stderr, "built ./%s/%s (%s)\n", artifact.Export(), artifact.Filename(), artifact.MIMEType())
}