diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 2158772..b2ba2ce 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -9,8 +9,8 @@ import ( "github.com/spf13/cobra" "github.com/osbuild/images/pkg/arch" - "github.com/osbuild/images/pkg/blueprint" + "github.com/osbuild/image-builder-cli/internal/blueprintload" "github.com/osbuild/image-builder-cli/internal/manifestgen" ) @@ -41,6 +41,10 @@ func cmdManifest(cmd *cobra.Command, args []string) error { if err != nil { return err } + blueprintPath, err := cmd.Flags().GetString("blueprint") + if err != nil { + return err + } distroStr := args[0] imgTypeStr := args[1] @@ -65,8 +69,12 @@ func cmdManifest(cmd *cobra.Command, args []string) error { if err != nil { return err } - var bp blueprint.Blueprint - return mg.Generate(&bp, res.Distro, res.ImgType, res.Arch, nil) + bp, err := blueprintload.Load(blueprintPath) + if err != nil { + return err + } + + return mg.Generate(bp, res.Distro, res.ImgType, res.Arch, nil) } func run() error { @@ -107,7 +115,8 @@ operating sytsems like centos and RHEL with easy customizations support.`, Args: cobra.MinimumNArgs(2), Hidden: true, } - // XXX: add blueprint switch + // XXX: share with build + manifestCmd.Flags().String("blueprint", "", `pass a blueprint file`) rootCmd.AddCommand(manifestCmd) return rootCmd.Execute() diff --git a/cmd/image-builder/main_test.go b/cmd/image-builder/main_test.go index 757557c..e4d9245 100644 --- a/cmd/image-builder/main_test.go +++ b/cmd/image-builder/main_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "os" + "path/filepath" "testing" "github.com/sirupsen/logrus" @@ -132,6 +133,24 @@ func hasDepsolveDnf() bool { return err == nil } +var testBlueprint = `{ + "customizations": { + "user": [ + { + "name": "alice" + } + ] + } +}` + +func makeTestBlueprint(t *testing.T, testBlueprint string) string { + tmpdir := t.TempDir() + blueprintPath := filepath.Join(tmpdir, "blueprint.json") + err := os.WriteFile(blueprintPath, []byte(testBlueprint), 0644) + assert.NoError(t, err) + return blueprintPath +} + // XXX: move to pytest like bib maybe? func TestManifestIntegrationSmoke(t *testing.T) { if testing.Short() { @@ -145,7 +164,9 @@ func TestManifestIntegrationSmoke(t *testing.T) { defer restore() restore = main.MockOsArgs([]string{ - "manifest", "centos-9", "qcow2"}, + "manifest", + "--blueprint", makeTestBlueprint(t, testBlueprint), + "centos-9", "qcow2"}, ) defer restore() @@ -159,4 +180,7 @@ func TestManifestIntegrationSmoke(t *testing.T) { pipelineNames, err := manifesttest.PipelineNamesFrom(fakeStdout.Bytes()) assert.NoError(t, err) assert.Contains(t, pipelineNames, "qcow2") + + // XXX: provide helpers in manifesttest to extract this in a nicer way + assert.Contains(t, fakeStdout.String(), `{"type":"org.osbuild.users","options":{"users":{"alice":{}}}}`) }