Skip to content

Commit 3f44230

Browse files
committed
main: embed manifestgen.options into manifestOptions
When we generate the osbuild manifest we need to take a bunch of commandline options into account. These are collected and passed via `manifestOptions` in the CLI. There is a (small) overlap with options that are then "converted" to options that need to be passed to `manifestgen` via `manifestgen.Options`. Previously there was manual code for this but its slightly nicer to just embedd the `manifestgen.Options` into the more general `manifestOptions` of the CLI. This avoid some boilerplate code and might serve as a useful pattern in other places. So this commit does that now (even though the wins are not that big).
1 parent b38aeb1 commit 3f44230

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

cmd/image-builder/main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/osbuild/images/pkg/customizations/subscription"
2222
"github.com/osbuild/images/pkg/distro/bootc"
2323
"github.com/osbuild/images/pkg/imagefilter"
24+
"github.com/osbuild/images/pkg/manifestgen"
2425
"github.com/osbuild/images/pkg/osbuild"
2526
"github.com/osbuild/images/pkg/ostree"
2627

@@ -138,6 +139,9 @@ type cmdManifestWrapperOptions struct {
138139
useBootstrapIfNeeded bool
139140
}
140141

142+
// used in tests
143+
var manifestgenDepsolver manifestgen.DepsolveFunc
144+
141145
func cmdManifestWrapper(pbar progress.ProgressBar, cmd *cobra.Command, args []string, w io.Writer, wd io.Writer, wrapperOpts *cmdManifestWrapperOptions) (*imagefilter.Result, error) {
142146
if wrapperOpts == nil {
143147
wrapperOpts = &cmdManifestWrapperOptions{}
@@ -304,27 +308,31 @@ func cmdManifestWrapper(pbar progress.ProgressBar, cmd *cobra.Command, args []st
304308
}
305309

306310
opts := &manifestOptions{
311+
ManifestgenOptions: manifestgen.Options{
312+
Cachedir: rpmmdCacheDir,
313+
CustomSeed: customSeed,
314+
RpmDownloader: rpmDownloader,
315+
DepsolveWarningsOutput: wd,
316+
Depsolve: manifestgenDepsolver,
317+
},
307318
OutputDir: outputDir,
308319
OutputFilename: outputFilename,
309320
BlueprintPath: blueprintPath,
310321
Ostree: ostreeImgOpts,
311322
BootcRef: bootcRef,
312323
BootcInstallerPayloadRef: bootcInstallerPayloadRef,
313-
RpmDownloader: rpmDownloader,
314324
WithSBOM: withSBOM,
315325
IgnoreWarnings: ignoreWarnings,
316-
CustomSeed: customSeed,
317326
Subscription: subscription,
318-
RpmmdCacheDir: rpmmdCacheDir,
319327

320328
ForceRepos: forceRepos,
321329
}
322-
opts.UseBootstrapContainer = wrapperOpts.useBootstrapIfNeeded && (img.ImgType.Arch().Name() != arch.Current().String())
323-
if opts.UseBootstrapContainer {
330+
opts.ManifestgenOptions.UseBootstrapContainer = wrapperOpts.useBootstrapIfNeeded && (img.ImgType.Arch().Name() != arch.Current().String())
331+
if opts.ManifestgenOptions.UseBootstrapContainer {
324332
fmt.Fprintf(os.Stderr, "WARNING: using experimental cross-architecture building to build %q\n", img.ImgType.Arch().Name())
325333
}
326334

327-
err = generateManifest(dataDir, extraRepos, img, w, wd, opts)
335+
err = generateManifest(dataDir, extraRepos, img, w, opts)
328336
return img, err
329337
}
330338

cmd/image-builder/manifest.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
)
2121

2222
type manifestOptions struct {
23+
ManifestgenOptions manifestgen.Options
24+
2325
OutputDir string
2426
OutputFilename string
2527
BlueprintPath string
@@ -30,11 +32,8 @@ type manifestOptions struct {
3032
RpmDownloader osbuild.RpmDownloader
3133
WithSBOM bool
3234
IgnoreWarnings bool
33-
CustomSeed *int64
34-
RpmmdCacheDir string
3535

36-
ForceRepos []string
37-
UseBootstrapContainer bool
36+
ForceRepos []string
3837
}
3938

4039
func sbomWriter(outputDir, filename string, content io.Reader) error {
@@ -55,23 +54,13 @@ func sbomWriter(outputDir, filename string, content io.Reader) error {
5554
return f.Sync()
5655
}
5756

58-
// used in tests
59-
var manifestgenDepsolver manifestgen.DepsolveFunc
60-
6157
// XXX: just return []byte instead of using output writer
62-
func generateManifest(dataDir string, extraRepos []string, img *imagefilter.Result, output io.Writer, depsolveWarningsOutput io.Writer, opts *manifestOptions) error {
58+
func generateManifest(dataDir string, extraRepos []string, img *imagefilter.Result, output io.Writer, opts *manifestOptions) error {
6359
repos, err := newRepoRegistry(dataDir, extraRepos)
6460
if err != nil {
6561
return err
6662
}
67-
manifestGenOpts := &manifestgen.Options{
68-
DepsolveWarningsOutput: depsolveWarningsOutput,
69-
RpmDownloader: opts.RpmDownloader,
70-
UseBootstrapContainer: opts.UseBootstrapContainer,
71-
CustomSeed: opts.CustomSeed,
72-
Depsolve: manifestgenDepsolver,
73-
Cachedir: opts.RpmmdCacheDir,
74-
}
63+
manifestGenOpts := &opts.ManifestgenOptions
7564
if opts.WithSBOM {
7665
outputDir := basenameFor(img, opts.OutputDir)
7766
manifestGenOpts.SBOMWriter = func(filename string, content io.Reader, docType sbom.StandardType) error {

0 commit comments

Comments
 (0)