From 8ab80135353057b0d9076839888dd1599051ba43 Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Mon, 21 Mar 2022 12:26:18 +0100 Subject: [PATCH] cmd: add `osbuild-package-sets` for printing package sets of an image Add a new debugging / development tool `osbuild-package-sets` for printing JSON object with all package sets of a specific distro x arch x image type combination. This is useful, since due to the way package sets are implemented in composer, the actual package set of a vanilla image type is very difficult to determine just by looking at the code. Example usage: `go run cmd/osbuild-package-sets/main.go -distro rhel-90 -arch x86_64 -image qcow2` --- cmd/osbuild-package-sets/main.go | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cmd/osbuild-package-sets/main.go diff --git a/cmd/osbuild-package-sets/main.go b/cmd/osbuild-package-sets/main.go new file mode 100644 index 000000000..8a4b61032 --- /dev/null +++ b/cmd/osbuild-package-sets/main.go @@ -0,0 +1,46 @@ +// Simple tool to dump a JSON object containing all package sets for a specific +// distro x arch x image type. +package main + +import ( + "encoding/json" + "flag" + "fmt" + "os" + + "github.com/osbuild/osbuild-composer/internal/blueprint" + "github.com/osbuild/osbuild-composer/internal/distroregistry" +) + +func main() { + var distroName string + var archName string + var imageName string + + flag.StringVar(&distroName, "distro", "", "Distribution name") + flag.StringVar(&archName, "arch", "", "Architecture name") + flag.StringVar(&imageName, "image", "", "Image name") + flag.Parse() + + dr := distroregistry.NewDefault() + + distro := dr.GetDistro(distroName) + if distro == nil { + panic(fmt.Errorf("Distro %q does not exist", distro)) + } + + arch, err := distro.GetArch(archName) + if err != nil { + panic(err) + } + + image, err := arch.GetImageType(imageName) + if err != nil { + panic(err) + } + + encoder := json.NewEncoder(os.Stdout) + encoder.SetIndent("", " ") + pkgset := image.PackageSets(blueprint.Blueprint{}) + _ = encoder.Encode(pkgset) +}