Skip to content

Commit

Permalink
manifest,sources: add repos to GenSources and support librepo
Browse files Browse the repository at this point in the history
This commit enables librepo sources generation. Currently guarded
behind a hacky OSBUILD_USE_LIBREPO environment.
  • Loading branch information
mvo5 committed Jan 14, 2025
1 parent 5cad773 commit d865c84
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (m Manifest) Serialize(packageSets map[string][]rpmmd.PackageSpec, containe
pipeline.serializeEnd()
}

sources, err := osbuild.GenSources(packages, commits, inline, containers)
sources, err := osbuild.GenSources(packages, commits, inline, containers, rpmRepos)
if err != nil {
return nil, err
}
Expand Down
44 changes: 36 additions & 8 deletions pkg/osbuild/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package osbuild
import (
"encoding/json"
"errors"
"os"

"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/ostree"
Expand Down Expand Up @@ -54,19 +55,46 @@ func (sources *Sources) UnmarshalJSON(data []byte) error {
return nil
}

func GenSources(packages []rpmmd.PackageSpec, ostreeCommits []ostree.CommitSpec, inlineData []string, containers []container.Spec) (Sources, error) {
func addPackagesCurl(sources Sources, packages []rpmmd.PackageSpec) error {
curl := NewCurlSource()
for _, pkg := range packages {
err := curl.AddPackage(pkg)
if err != nil {
return err
}
}
sources["org.osbuild.curl"] = curl
return nil
}

func addPackagesLibrepo(sources Sources, packages []rpmmd.PackageSpec, rpmRepos map[string][]rpmmd.RepoConfig) error {
librepo := NewLibrepoSource()
for _, pkg := range packages {
err := librepo.AddPackage(pkg, rpmRepos)
if err != nil {
return err
}
}
sources["org.osbuild.librepo"] = librepo
return nil
}

func GenSources(packages []rpmmd.PackageSpec, ostreeCommits []ostree.CommitSpec, inlineData []string, containers []container.Spec, rpmRepos map[string][]rpmmd.RepoConfig) (Sources, error) {
sources := Sources{}

// collect rpm package sources
if len(packages) > 0 {
curl := NewCurlSource()
for _, pkg := range packages {
err := curl.AddPackage(pkg)
if err != nil {
return nil, err
}
// XXX: hack, we have no good way to pass options to GenSource
// right now
var err error
if s := os.Getenv("OSBUILD_USE_LIBREPO"); s == "1" {
err = addPackagesLibrepo(sources, packages, rpmRepos)
} else {
err = addPackagesCurl(sources, packages)
}
if err != nil {
return nil, err
}
sources["org.osbuild.curl"] = curl
}

// collect ostree commit sources
Expand Down
8 changes: 4 additions & 4 deletions pkg/osbuild/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestSource_UnmarshalJSON(t *testing.T) {
}

func TestGenSourcesTrivial(t *testing.T) {
sources, err := GenSources(nil, nil, nil, nil)
sources, err := GenSources(nil, nil, nil, nil, nil)
assert.NoError(t, err)

jsonOutput, err := json.MarshalIndent(sources, "", " ")
Expand All @@ -135,7 +135,7 @@ func TestGenSourcesContainerStorage(t *testing.T) {
LocalStorage: true,
},
}
sources, err := GenSources(nil, nil, nil, containers)
sources, err := GenSources(nil, nil, nil, containers, nil)
assert.NoError(t, err)

jsonOutput, err := json.MarshalIndent(sources, "", " ")
Expand All @@ -159,7 +159,7 @@ func TestGenSourcesSkopeo(t *testing.T) {
ImageID: imageID,
},
}
sources, err := GenSources(nil, nil, nil, containers)
sources, err := GenSources(nil, nil, nil, containers, nil)
assert.NoError(t, err)

jsonOutput, err := json.MarshalIndent(sources, "", " ")
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestGenSourcesWithSkopeoIndex(t *testing.T) {
ImageID: imageID,
},
}
sources, err := GenSources(nil, nil, nil, containers)
sources, err := GenSources(nil, nil, nil, containers, nil)
assert.NoError(t, err)

jsonOutput, err := json.MarshalIndent(sources, "", " ")
Expand Down

0 comments on commit d865c84

Please sign in to comment.