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`
This commit is contained in:
Tomas Hozza 2022-03-21 12:26:18 +01:00 committed by Ondřej Budai
parent d117b84dc3
commit 8ab8013535

View file

@ -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)
}