Skip to content

Commit

Permalink
manifest: add SerializeOptions to manifest.Serialize()
Browse files Browse the repository at this point in the history
This commit makes `Serialize()` more extensible by switching the
rpmDownloader option to a more general `SerializeOptions` struct
that can be nil if no options are required. It contains the
`RpmDownloader` as the only option right now. We could YAGNI it
and do it once we have the second option but arguably it is cleaner
already doing it now.
  • Loading branch information
mvo5 committed Jan 16, 2025
1 parent 991d5d8 commit 75632a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func makeManifest(
return nil, fmt.Errorf("[ERROR] ostree commit resolution failed: %w", err)
}

mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, 0)
mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, nil)
if err != nil {
return nil, fmt.Errorf("[ERROR] manifest serialization failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func makeManifestJob(
commitSpecs = mockResolveCommits(manifest.GetOSTreeSourceSpecs())
}

mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, 0)
mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, nil)
if err != nil {
return fmt.Errorf("[%s] manifest serialization failed: %s", filename, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/osbuild-playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func RunPlayground(img image.ImageKind, d distro.Distro, arch distro.Arch, repos
fmt.Fprintf(os.Stderr, "could not clean dnf cache: %s", err.Error())
}

bytes, err := manifest.Serialize(depsolvedSets, nil, nil, 0)
bytes, err := manifest.Serialize(depsolvedSets, nil, nil, nil)
if err != nil {
panic("failed to serialize manifest: " + err.Error())
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ func (m Manifest) GetOSTreeSourceSpecs() map[string][]ostree.SourceSpec {
return ostreeSpecs
}

func (m Manifest) Serialize(depsolvedSets map[string]dnfjson.Result, containerSpecs map[string][]container.Spec, ostreeCommits map[string][]ostree.CommitSpec, rpmDownloader osbuild.RpmDownloader) (OSBuildManifest, error) {
type SerializeOptions struct {
RpmDownloader osbuild.RpmDownloader
}

func (m Manifest) Serialize(depsolvedSets map[string]dnfjson.Result, containerSpecs map[string][]container.Spec, ostreeCommits map[string][]ostree.CommitSpec, opts *SerializeOptions) (OSBuildManifest, error) {
if opts == nil {
opts = &SerializeOptions{}
}

for _, pipeline := range m.pipelines {
pipeline.serializeStart(Inputs{
Depsolved: depsolvedSets[pipeline.Name()],
Expand All @@ -165,7 +173,7 @@ func (m Manifest) Serialize(depsolvedSets map[string]dnfjson.Result, containerSp
pipeline.serializeEnd()
}

sources, err := osbuild.GenSources(mergedInputs, rpmDownloader)
sources, err := osbuild.GenSources(mergedInputs, opts.RpmDownloader)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 75632a9

Please sign in to comment.