Skip to content

Commit

Permalink
image-builder: add ib build --filename foo.img support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 14, 2024
1 parent 20b3493 commit cf92ebf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
7 changes: 5 additions & 2 deletions cmd/image-builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/osbuild/images/pkg/osbuild"
)

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

var mf bytes.Buffer
if err := outputManifest(&mf, distroName, imgTypeStr, archStr); err != nil {
opts := &genManifestOptions{
OutputFilename: outputFilename,
}
if err := outputManifest(&mf, distroName, imgTypeStr, archStr, opts); err != nil {
return err
}

Expand Down
12 changes: 9 additions & 3 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ func cmdManifest(cmd *cobra.Command, args []string) error {
archStr = arch.Current().String()
}

return outputManifest(osStdout, distroName, imgType, archStr)
return outputManifest(osStdout, distroName, imgType, archStr, nil)
}

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

return buildImage(osStdout, distroName, imgType)
return buildImage(osStdout, distroName, imgType, outputFilename)
}

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

return rootCmd.Execute()
}
Expand Down
20 changes: 14 additions & 6 deletions cmd/image-builder/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ func depsolve(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d dist
return depsolvedSets, repoSets, nil
}

func outputManifest(out io.Writer, distroName, imgTypeStr, archStr string) error {
// XXX: what/how much do we expose here?
var options distro.ImageOptions
type genManifestOptions struct {
OutputFilename string
}

func outputManifest(out io.Writer, distroName, imgTypeStr, archStr string, opts *genManifestOptions) error {
if opts == nil {
opts = &genManifestOptions{}
}

filterResult, err := getOneImage(distroName, imgTypeStr, archStr)
if err != nil {
return err
}
distro := filterResult.Distro
dist := filterResult.Distro
imgType := filterResult.ImgType

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

var bp blueprint.Blueprint
preManifest, warnings, err := imgType.Manifest(&bp, options, repos, 0)
imgOpts := distro.ImageOptions{
OutputFilename: opts.OutputFilename,
}
preManifest, warnings, err := imgType.Manifest(&bp, imgOpts, repos, 0)
if err != nil {
return err
}
Expand All @@ -64,7 +72,7 @@ func outputManifest(out io.Writer, distroName, imgTypeStr, archStr string) error
if err != nil {
return err
}
packageSpecs, _, err := depsolve(cacheDir, preManifest.GetPackageSetChains(), distro, archStr)
packageSpecs, _, err := depsolve(cacheDir, preManifest.GetPackageSetChains(), dist, archStr)
if err != nil {
return err
}
Expand Down

0 comments on commit cf92ebf

Please sign in to comment.