Skip to content

Commit 943321e

Browse files
mvo5thozza
authored andcommitted
manifest,sources: add repos to GenSources and support librepo
This commit enables librepo sources generation. Currently guarded behind a hacky OSBUILD_USE_LIBREPO environment.
1 parent 3fde7be commit 943321e

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

pkg/manifest/manifest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (m Manifest) Serialize(packageSets map[string][]rpmmd.PackageSpec, containe
158158
pipeline.serializeEnd()
159159
}
160160

161-
sources, err := osbuild.GenSources(packages, commits, inline, containers)
161+
sources, err := osbuild.GenSources(packages, commits, inline, containers, rpmRepos)
162162
if err != nil {
163163
return nil, err
164164
}

pkg/osbuild/source.go

+36-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package osbuild
33
import (
44
"encoding/json"
55
"errors"
6+
"os"
67

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

57-
func GenSources(packages []rpmmd.PackageSpec, ostreeCommits []ostree.CommitSpec, inlineData []string, containers []container.Spec) (Sources, error) {
58+
func addPackagesCurl(sources Sources, packages []rpmmd.PackageSpec) error {
59+
curl := NewCurlSource()
60+
for _, pkg := range packages {
61+
err := curl.AddPackage(pkg)
62+
if err != nil {
63+
return err
64+
}
65+
}
66+
sources["org.osbuild.curl"] = curl
67+
return nil
68+
}
69+
70+
func addPackagesLibrepo(sources Sources, packages []rpmmd.PackageSpec, rpmRepos map[string][]rpmmd.RepoConfig) error {
71+
librepo := NewLibrepoSource()
72+
for _, pkg := range packages {
73+
err := librepo.AddPackage(pkg, rpmRepos)
74+
if err != nil {
75+
return err
76+
}
77+
}
78+
sources["org.osbuild.librepo"] = librepo
79+
return nil
80+
}
81+
82+
func GenSources(packages []rpmmd.PackageSpec, ostreeCommits []ostree.CommitSpec, inlineData []string, containers []container.Spec, rpmRepos map[string][]rpmmd.RepoConfig) (Sources, error) {
5883
sources := Sources{}
5984

6085
// collect rpm package sources
6186
if len(packages) > 0 {
62-
curl := NewCurlSource()
63-
for _, pkg := range packages {
64-
err := curl.AddPackage(pkg)
65-
if err != nil {
66-
return nil, err
67-
}
87+
// XXX: hack, we have no good way to pass options to GenSource
88+
// right now
89+
var err error
90+
if s := os.Getenv("OSBUILD_USE_LIBREPO"); s == "1" {
91+
err = addPackagesLibrepo(sources, packages, rpmRepos)
92+
} else {
93+
err = addPackagesCurl(sources, packages)
94+
}
95+
if err != nil {
96+
return nil, err
6897
}
69-
sources["org.osbuild.curl"] = curl
7098
}
7199

72100
// collect ostree commit sources

pkg/osbuild/source_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestSource_UnmarshalJSON(t *testing.T) {
119119
}
120120

121121
func TestGenSourcesTrivial(t *testing.T) {
122-
sources, err := GenSources(nil, nil, nil, nil)
122+
sources, err := GenSources(nil, nil, nil, nil, nil)
123123
assert.NoError(t, err)
124124

125125
jsonOutput, err := json.MarshalIndent(sources, "", " ")
@@ -135,7 +135,7 @@ func TestGenSourcesContainerStorage(t *testing.T) {
135135
LocalStorage: true,
136136
},
137137
}
138-
sources, err := GenSources(nil, nil, nil, containers)
138+
sources, err := GenSources(nil, nil, nil, containers, nil)
139139
assert.NoError(t, err)
140140

141141
jsonOutput, err := json.MarshalIndent(sources, "", " ")
@@ -159,7 +159,7 @@ func TestGenSourcesSkopeo(t *testing.T) {
159159
ImageID: imageID,
160160
},
161161
}
162-
sources, err := GenSources(nil, nil, nil, containers)
162+
sources, err := GenSources(nil, nil, nil, containers, nil)
163163
assert.NoError(t, err)
164164

165165
jsonOutput, err := json.MarshalIndent(sources, "", " ")
@@ -190,7 +190,7 @@ func TestGenSourcesWithSkopeoIndex(t *testing.T) {
190190
ImageID: imageID,
191191
},
192192
}
193-
sources, err := GenSources(nil, nil, nil, containers)
193+
sources, err := GenSources(nil, nil, nil, containers, nil)
194194
assert.NoError(t, err)
195195

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

0 commit comments

Comments
 (0)