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 ff89da5 commit 576511a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 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
2 changes: 1 addition & 1 deletion pkg/distro/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestImageTypePipelineNames(t *testing.T) {
}
commits[name] = commitSpecs
}
mf, err := m.Serialize(depsolvedSets, containers, commits, 0)
mf, err := m.Serialize(depsolvedSets, containers, commits, nil)
assert.NoError(err)
pm := new(manifest)
err = json.Unmarshal(mf, pm)
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/bootc_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func makeBootcDiskImageOsbuildManifest(t *testing.T, opts *bootcDiskImageTestOpt
"image": []container.Spec{{Source: "other-src", Digest: makeFakeDigest(t), ImageID: makeFakeDigest(t)}},
}

osbuildManifest, err := m.Serialize(nil, fakeSourceSpecs, nil, 0)
osbuildManifest, err := m.Serialize(nil, fakeSourceSpecs, nil, nil)
require.Nil(t, err)

return osbuildManifest
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/installer_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func instantiateAndSerialize(t *testing.T, img image.ImageKind, depsolved map[st
_, err := img.InstantiateManifest(&mf, nil, &runner.CentOS{Version: 9}, rng)
assert.NoError(t, err)

mfs, err := mf.Serialize(depsolved, containers, commits, 0)
mfs, err := mf.Serialize(depsolved, containers, commits, nil)
assert.NoError(t, err)

return string(mfs)
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.DepsolveResult, 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.DepsolveResult, 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.DepsolveResult, con
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 576511a

Please sign in to comment.