Skip to content

Commit 493d0cc

Browse files
committed
image-builder: add ib build --filename foo.img support
1 parent 4eaa65a commit 493d0cc

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

Diff for: cmd/image-builder/build.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/osbuild/images/pkg/osbuild"
1212
)
1313

14-
func buildImage(out io.Writer, distroName, imgTypeStr string) error {
14+
func buildImage(out io.Writer, distroName, imgTypeStr, outputFilename string) error {
1515
// cross arch building is not possible, we would have to download
1616
// a pre-populated buildroot (tar,container) with rpm for that
1717
archStr := arch.Current().String()
@@ -22,7 +22,10 @@ func buildImage(out io.Writer, distroName, imgTypeStr string) error {
2222
imgType := filterResult.ImgType
2323

2424
var mf bytes.Buffer
25-
if err := outputManifest(&mf, distroName, imgTypeStr, archStr); err != nil {
25+
opts := &genManifestOptions{
26+
OutputFilename: outputFilename,
27+
}
28+
if err := outputManifest(&mf, distroName, imgTypeStr, archStr, opts); err != nil {
2629
return err
2730
}
2831

Diff for: cmd/image-builder/main.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ func cmdManifest(cmd *cobra.Command, args []string) error {
3838
archStr = arch.Current().String()
3939
}
4040

41-
return outputManifest(osStdout, distroName, imgType, archStr)
41+
return outputManifest(osStdout, distroName, imgType, archStr, nil)
4242
}
4343

4444
func cmdBuild(cmd *cobra.Command, args []string) error {
4545
// support prefixes to make it easy to copy/paste from list-images
4646
distroName := strings.TrimPrefix(args[0], "distro:")
4747
imgType := strings.TrimPrefix(args[1], "type:")
48+
outputFilename, err := cmd.Flags().GetString("filename")
49+
if err != nil {
50+
return err
51+
}
4852

49-
return buildImage(osStdout, distroName, imgType)
53+
return buildImage(osStdout, distroName, imgType, outputFilename)
5054
}
5155

5256
func run() error {
@@ -95,8 +99,10 @@ operating sytsems like centos and RHEL with easy customizations support.`,
9599
// XXX: show error with available types if only one arg given
96100
Args: cobra.ExactArgs(2),
97101
}
98-
rootCmd.AddCommand(buildCmd)
102+
// XXX: add this for "manifest" too in a nice way
103+
buildCmd.Flags().String("filename", "", "Output as a specific filename")
99104
// XXX: add --output=text,json and streaming
105+
rootCmd.AddCommand(buildCmd)
100106

101107
return rootCmd.Execute()
102108
}

Diff for: cmd/image-builder/manifest.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ func depsolve(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d dist
2929
return depsolvedSets, repoSets, nil
3030
}
3131

32-
func outputManifest(out io.Writer, distroName, imgTypeStr, archStr string) error {
33-
// XXX: what/how much do we expose here?
34-
var options distro.ImageOptions
32+
type genManifestOptions struct {
33+
OutputFilename string
34+
}
35+
36+
func outputManifest(out io.Writer, distroName, imgTypeStr, archStr string, opts *genManifestOptions) error {
37+
if opts == nil {
38+
opts = &genManifestOptions{}
39+
}
3540

3641
filterResult, err := getOneImage(distroName, imgTypeStr, archStr)
3742
if err != nil {
3843
return err
3944
}
40-
distro := filterResult.Distro
45+
dist := filterResult.Distro
4146
imgType := filterResult.ImgType
4247

4348
reporeg, err := newRepoRegistry()
@@ -50,7 +55,10 @@ func outputManifest(out io.Writer, distroName, imgTypeStr, archStr string) error
5055
}
5156

5257
var bp blueprint.Blueprint
53-
preManifest, warnings, err := imgType.Manifest(&bp, options, repos, 0)
58+
imgOpts := distro.ImageOptions{
59+
OutputFilename: opts.OutputFilename,
60+
}
61+
preManifest, warnings, err := imgType.Manifest(&bp, imgOpts, repos, 0)
5462
if err != nil {
5563
return err
5664
}
@@ -64,7 +72,7 @@ func outputManifest(out io.Writer, distroName, imgTypeStr, archStr string) error
6472
if err != nil {
6573
return err
6674
}
67-
packageSpecs, _, err := depsolve(cacheDir, preManifest.GetPackageSetChains(), distro, archStr)
75+
packageSpecs, _, err := depsolve(cacheDir, preManifest.GetPackageSetChains(), dist, archStr)
6876
if err != nil {
6977
return err
7078
}

0 commit comments

Comments
 (0)