Skip to content

Commit

Permalink
fixup! rework argument handling
Browse files Browse the repository at this point in the history
This commit tweaks the argument handling based on the suggestion
by @achilleas-k (thanks!). Now it takes
```console
$ image-builder manifest centos-9 qcow2 ./path/to/blueprint
...
$ image-builder manifest --arch s390x centos-9 qcow2
...
```

This means it is no longer copy/paste friendly from `--list-images`
but we can tweak the output of that so that by default we only
how `distro:foo type:bar` instead of the full arch string and
hint via something like `isatty(0)` for interactive users that
there are more arches available.
  • Loading branch information
mvo5 committed Dec 4, 2024
1 parent d46d430 commit d8b8d4e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
16 changes: 8 additions & 8 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ func cmdManifest(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
blueprintPath, err := cmd.Flags().GetString("blueprint")
archStr, err := cmd.Flags().GetString("arch")
if err != nil {
return err
}
if archStr == "" {
archStr = arch.Current().String()
}

var blueprintPath string
distroStr := args[0]
imgTypeStr := args[1]
var archStr string
if len(args) > 2 {
archStr = args[2]
} else {
archStr = arch.Current().String()
blueprintPath = args[2]
}
res, err := getOneImage(dataDir, distroStr, imgTypeStr, archStr)
if err != nil {
Expand Down Expand Up @@ -109,15 +110,14 @@ operating sytsems like centos and RHEL with easy customizations support.`,
rootCmd.AddCommand(listImagesCmd)

manifestCmd := &cobra.Command{
Use: "manifest <distro> <image-type> [<arch>]",
Use: "manifest <distro> <image-type> [blueprint]",
Short: "Build manifest for the given distro/image-type, e.g. centos-9 qcow2",
RunE: cmdManifest,
SilenceUsage: true,
Args: cobra.MinimumNArgs(2),
Hidden: true,
}
// XXX: share with build
manifestCmd.Flags().String("blueprint", "", `pass a blueprint file`)
manifestCmd.Flags().String("arch", "", `build manifest for a different architecture`)
rootCmd.AddCommand(manifestCmd)

return rootCmd.Execute()
Expand Down
39 changes: 36 additions & 3 deletions cmd/image-builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ func TestManifestIntegrationSmoke(t *testing.T) {

restore = main.MockOsArgs([]string{
"manifest",
"--blueprint", makeTestBlueprint(t, testBlueprint),
"centos-9", "qcow2"},
)
"centos-9", "qcow2",
makeTestBlueprint(t, testBlueprint),
})
defer restore()

var fakeStdout bytes.Buffer
Expand All @@ -190,3 +190,36 @@ func TestManifestIntegrationSmoke(t *testing.T) {
assert.Contains(t, fakeStdout.String(), `{"type":"org.osbuild.users","options":{"users":{"alice":{}}}}`)
assert.Contains(t, fakeStdout.String(), `"image":{"name":"registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/fedora-minimal"`)
}

func TestManifestIntegrationCrossArch(t *testing.T) {
if testing.Short() {
t.Skip("manifest generation takes a while")
}
if !hasDepsolveDnf() {
t.Skip("no osbuild-depsolve-dnf binary found")
}

restore := main.MockNewRepoRegistry(testrepos.New)
defer restore()

restore = main.MockOsArgs([]string{
"manifest",
"centos-9", "tar",
"--arch", "s390x",
})
defer restore()

var fakeStdout bytes.Buffer
restore = main.MockOsStdout(&fakeStdout)
defer restore()

err := main.Run()
assert.NoError(t, err)

pipelineNames, err := manifesttest.PipelineNamesFrom(fakeStdout.Bytes())
assert.NoError(t, err)
assert.Contains(t, pipelineNames, "archive")

// XXX: provide helpers in manifesttest to extract this in a nicer way
assert.Contains(t, fakeStdout.String(), `.el9.s390x.rpm`)
}

0 comments on commit d8b8d4e

Please sign in to comment.