Skip to content

Commit c625126

Browse files
committed
cloudapi: enable librepo by default (and update tests)
This commit enables librepo by default in the cloudapi. This should help with on-prem out of sync mirror issues like: #4427 We have librepo in osbuild/images/ibcli/bib for a while now, c.f. osbuild/image-builder-cli#51 osbuild/bootc-image-builder#786 (enable) osbuild/bootc-image-builder#840 (make default) It is not configurable right now, I am not sure there is a reason to keep libcurl around for manifest generation as its more fragile but if it is desired I can look into that too. Having it configurable would allow us to revert to the previous org.osbuild.curl in case anything is wrong with the new downloader (and arguably it was only excercised by a relatively small number of people compared to how much the service is building).
1 parent f796a8d commit c625126

File tree

4 files changed

+50
-51
lines changed

4 files changed

+50
-51
lines changed

internal/cloudapi/v2/server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/osbuild/images/pkg/distro"
2828
"github.com/osbuild/images/pkg/distrofactory"
2929
"github.com/osbuild/images/pkg/manifest"
30+
"github.com/osbuild/images/pkg/osbuild"
3031
"github.com/osbuild/images/pkg/ostree"
3132
"github.com/osbuild/images/pkg/reporegistry"
3233
"github.com/osbuild/images/pkg/sbom"
@@ -647,7 +648,10 @@ func serializeManifest(ctx context.Context, manifestSource *manifest.Manifest, w
647648
r.Repos = res
648649
depsolveResultsInTheRightFormat[plName] = r
649650
}
650-
ms, err := manifestSource.Serialize(depsolveResultsInTheRightFormat, containerSpecs, ostreeCommitSpecs, nil)
651+
opts := &manifest.SerializeOptions{
652+
RpmDownloader: osbuild.RpmDownloaderLibrepo,
653+
}
654+
ms, err := manifestSource.Serialize(depsolveResultsInTheRightFormat, containerSpecs, ostreeCommitSpecs, opts)
651655
if err != nil {
652656
reason := "Error serializing manifest"
653657
jobResult.JobError = clienterrors.New(clienterrors.ErrorManifestGeneration, reason, err.Error())

internal/cloudapi/v2/v2_koji_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func TestKojiCompose(t *testing.T) {
400400
},
401401
}
402402

403-
emptyManifest := `{"version":"2","pipelines":[{"name":"build"},{"name":"os"}],"sources":{"org.osbuild.curl":{"items":{"sha256:e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe":{"url":"https://pkg1.example.com/1.33-2.fc30.x86_64.rpm"}}}}}`
403+
emptyManifest := `{"version":"2","pipelines":[{"name":"build"},{"name":"os"}],"sources":{"org.osbuild.librepo":{"items":{"sha256:e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe":{"path":"","mirror":"pkg1-repoid"}},"options":{"mirrors":{"pkg1-repoid":{"url":"https://pkg1.example.com/","type":"baseurl"}}}}}}`
404404
expectedManifests := `{"manifests":[` + emptyManifest + `,` + emptyManifest + `],"kind":"ComposeManifests"}`
405405
for idx, c := range cases {
406406
name, version, release := "foo", "1", "2"

internal/cloudapi/v2/v2_multi_tenancy_test.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,7 @@ func runNextJob(t *testing.T, jobs []uuid.UUID, workerServer *worker.Server, org
179179
// the manifest generation job would fail on empty depsolved package list.
180180
// This would make the ComposeManifests endpoint return an error.
181181
case worker.JobTypeDepsolve:
182-
dummyPackage := worker.DepsolvedPackage{
183-
Name: "pkg1",
184-
Version: "1.33",
185-
Release: "2.fc30",
186-
Arch: "x86_64",
187-
Checksum: &worker.DepsolvedPackageChecksum{
188-
Type: "sha256",
189-
Value: "e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe",
190-
},
191-
RemoteLocations: []string{"https://pkg1.example.com/1.33-2.fc30.x86_64.rpm"},
192-
}
193-
depsolveJobResult := &worker.DepsolveJobResult{
194-
PackageSpecs: map[string]worker.DepsolvedPackageList{
195-
// Used when depsolving a manifest
196-
"build": {dummyPackage},
197-
"os": {dummyPackage},
198-
},
199-
}
182+
depsolveJobResult := makeFakeWorkerDepsolveResult()
200183
rawDepsolveJobResult, err := json.Marshal(depsolveJobResult)
201184
require.NoError(t, err)
202185
result := api.UpdateJobResult{

internal/cloudapi/v2/v2_test.go

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,46 @@ var sbomDoc = json.RawMessage(`{
7474
]
7575
}`)
7676

77+
func makeFakeWorkerDepsolveResult() *worker.DepsolveJobResult {
78+
dummyPackage := worker.DepsolvedPackage{
79+
Name: "pkg1",
80+
Version: "1.33",
81+
Release: "2.fc30",
82+
Arch: "x86_64",
83+
Checksum: &worker.DepsolvedPackageChecksum{
84+
Type: "sha256",
85+
Value: "e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe",
86+
},
87+
RemoteLocations: []string{"https://pkg1.example.com/1.33-2.fc30.x86_64.rpm"},
88+
RepoID: "pkg1-repoid",
89+
}
90+
dummyRepo := rpmmd.RepoConfig{
91+
Id: "pkg1-repoid",
92+
BaseURLs: []string{"https://pkg1.example.com/"},
93+
}
94+
return &worker.DepsolveJobResult{
95+
PackageSpecs: map[string]worker.DepsolvedPackageList{
96+
// Used when depsolving a manifest
97+
"build": {dummyPackage},
98+
"os": {dummyPackage},
99+
},
100+
RepoConfigs: map[string][]rpmmd.RepoConfig{
101+
"build": {dummyRepo},
102+
"os": {dummyRepo},
103+
},
104+
SbomDocs: map[string]worker.SbomDoc{
105+
"build": {
106+
DocType: sbom.StandardTypeSpdx,
107+
Document: sbomDoc,
108+
},
109+
"os": {
110+
DocType: sbom.StandardTypeSpdx,
111+
Document: sbomDoc,
112+
},
113+
},
114+
}
115+
}
116+
77117
// mockDepsolve starts a routine which just completes depsolve jobs
78118
// It requires some of the test framework to operate
79119
// And the optional fail parameter will cause it to return an error as if the depsolve failed
@@ -92,35 +132,7 @@ func mockDepsolve(t *testing.T, workerServer *worker.Server, wg *sync.WaitGroup,
92132
if err != nil {
93133
continue
94134
}
95-
dummyPackage := worker.DepsolvedPackage{
96-
Name: "pkg1",
97-
Version: "1.33",
98-
Release: "2.fc30",
99-
Arch: "x86_64",
100-
Checksum: &worker.DepsolvedPackageChecksum{
101-
Type: "sha256",
102-
Value: "e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe",
103-
},
104-
RemoteLocations: []string{"https://pkg1.example.com/1.33-2.fc30.x86_64.rpm"},
105-
}
106-
dJR := &worker.DepsolveJobResult{
107-
PackageSpecs: map[string]worker.DepsolvedPackageList{
108-
// Used when depsolving a manifest
109-
"build": {dummyPackage},
110-
"os": {dummyPackage},
111-
},
112-
SbomDocs: map[string]worker.SbomDoc{
113-
"build": {
114-
DocType: sbom.StandardTypeSpdx,
115-
Document: sbomDoc,
116-
},
117-
"os": {
118-
DocType: sbom.StandardTypeSpdx,
119-
Document: sbomDoc,
120-
},
121-
},
122-
}
123-
135+
dJR := makeFakeWorkerDepsolveResult()
124136
if fail {
125137
dJR.JobResult.JobError = clienterrors.New(clienterrors.ErrorDNFOtherError, "DNF Error", nil)
126138
}
@@ -837,7 +849,7 @@ func TestComposeStatusSuccess(t *testing.T) {
837849
]
838850
}`, jobId, jobId))
839851

840-
emptyManifest := `{"version":"2","pipelines":[{"name":"build"},{"name":"os"}],"sources":{"org.osbuild.curl":{"items":{"sha256:e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe":{"url":"https://pkg1.example.com/1.33-2.fc30.x86_64.rpm"}}}}}`
852+
emptyManifest := `{"version":"2","pipelines":[{"name":"build"},{"name":"os"}],"sources":{"org.osbuild.librepo":{"items":{"sha256:e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe":{"path":"","mirror":"pkg1-repoid"}},"options":{"mirrors":{"pkg1-repoid":{"url":"https://pkg1.example.com/","type":"baseurl"}}}}}}`
841853
test.TestRoute(t, srv.Handler("/api/image-builder-composer/v2"), false, "GET", fmt.Sprintf("/api/image-builder-composer/v2/composes/%v/manifests", jobId), ``, http.StatusOK, fmt.Sprintf(`
842854
{
843855
"href": "/api/image-builder-composer/v2/composes/%v/manifests",
@@ -881,7 +893,7 @@ func TestComposeManifests(t *testing.T) {
881893
{
882894
name: "success",
883895
jobResult: worker.ManifestJobByIDResult{
884-
Manifest: manifest.OSBuildManifest([]byte(`{"version":"2","pipelines":[{"name":"build"},{"name":"os"}],"sources":{"org.osbuild.curl":{"items":{"sha256:e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe":{"url":"https://pkg1.example.com/1.33-2.fc30.x86_64.rpm"}}}}}`)),
896+
Manifest: manifest.OSBuildManifest([]byte(`{"version":"2","pipelines":[{"name":"build"},{"name":"os"}],"sources":{"org.osbuild.librepo":{"items":{"sha256:e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe":{"path":"","mirror":"pkg1-repoid"}},"options":{"mirrors":{"pkg1-repoid":{"url":"https://pkg1.example.com/","type":"baseurl"}}}}}}`)),
885897
}},
886898
{
887899
name: "failure",

0 commit comments

Comments
 (0)