cmd: add blueprint support to manifest
This commit adds support to pass a blueprint to the manifest generation.
This commit is contained in:
parent
f242005672
commit
05ef9502e4
2 changed files with 38 additions and 5 deletions
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/osbuild/images/pkg/arch"
|
"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"
|
"github.com/osbuild/image-builder-cli/internal/manifestgen"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -41,6 +41,10 @@ func cmdManifest(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
blueprintPath, err := cmd.Flags().GetString("blueprint")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
distroStr := args[0]
|
distroStr := args[0]
|
||||||
imgTypeStr := args[1]
|
imgTypeStr := args[1]
|
||||||
|
|
@ -65,8 +69,12 @@ func cmdManifest(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var bp blueprint.Blueprint
|
bp, err := blueprintload.Load(blueprintPath)
|
||||||
return mg.Generate(&bp, res.Distro, res.ImgType, res.Arch, nil)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return mg.Generate(bp, res.Distro, res.ImgType, res.Arch, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
|
|
@ -107,7 +115,8 @@ operating sytsems like centos and RHEL with easy customizations support.`,
|
||||||
Args: cobra.MinimumNArgs(2),
|
Args: cobra.MinimumNArgs(2),
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
}
|
}
|
||||||
// XXX: add blueprint switch
|
// XXX: share with build
|
||||||
|
manifestCmd.Flags().String("blueprint", "", `pass a blueprint file`)
|
||||||
rootCmd.AddCommand(manifestCmd)
|
rootCmd.AddCommand(manifestCmd)
|
||||||
|
|
||||||
return rootCmd.Execute()
|
return rootCmd.Execute()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
@ -132,6 +133,24 @@ func hasDepsolveDnf() bool {
|
||||||
return err == nil
|
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?
|
// XXX: move to pytest like bib maybe?
|
||||||
func TestManifestIntegrationSmoke(t *testing.T) {
|
func TestManifestIntegrationSmoke(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
|
|
@ -145,7 +164,9 @@ func TestManifestIntegrationSmoke(t *testing.T) {
|
||||||
defer restore()
|
defer restore()
|
||||||
|
|
||||||
restore = main.MockOsArgs([]string{
|
restore = main.MockOsArgs([]string{
|
||||||
"manifest", "centos-9", "qcow2"},
|
"manifest",
|
||||||
|
"--blueprint", makeTestBlueprint(t, testBlueprint),
|
||||||
|
"centos-9", "qcow2"},
|
||||||
)
|
)
|
||||||
defer restore()
|
defer restore()
|
||||||
|
|
||||||
|
|
@ -159,4 +180,7 @@ func TestManifestIntegrationSmoke(t *testing.T) {
|
||||||
pipelineNames, err := manifesttest.PipelineNamesFrom(fakeStdout.Bytes())
|
pipelineNames, err := manifesttest.PipelineNamesFrom(fakeStdout.Bytes())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Contains(t, pipelineNames, "qcow2")
|
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":{}}}}`)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue