weldr: get repositories from distro
Make distros export repository information and use those in the weldr API. This means that repos are only specified once and that the API returns the right packages when we allow different distros.
This commit is contained in:
parent
1dac0a03d2
commit
b911d0b928
6 changed files with 94 additions and 29 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
|
|
@ -32,13 +33,8 @@ func main() {
|
|||
weldrListener := listeners[0]
|
||||
jobListener := listeners[1]
|
||||
|
||||
repo := rpmmd.RepoConfig{
|
||||
Id: "fedora",
|
||||
Name: "Fedora 30",
|
||||
Metalink: "https://mirrors.fedoraproject.org/metalink?repo=fedora-30&arch=x86_64",
|
||||
}
|
||||
|
||||
rpm := rpmmd.NewRPMMD()
|
||||
distribution := distro.New("")
|
||||
|
||||
var logger *log.Logger
|
||||
if verbose {
|
||||
|
|
@ -53,7 +49,7 @@ func main() {
|
|||
store := store.New(&stateFile)
|
||||
|
||||
jobAPI := jobqueue.New(logger, store)
|
||||
weldrAPI := weldr.New(rpm, repo, logger, store)
|
||||
weldrAPI := weldr.New(rpm, distribution, logger, store)
|
||||
|
||||
go jobAPI.Serve(jobListener)
|
||||
weldrAPI.Serve(weldrListener)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,14 @@ import (
|
|||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/pipeline"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
type Distro interface {
|
||||
// Returns a list of repositories from which this distribution gets its
|
||||
// content.
|
||||
Repositories() []rpmmd.RepoConfig
|
||||
|
||||
// Returns a sorted list of the output formats this distro supports.
|
||||
ListOutputFormats() []string
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/pipeline"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
type Fedora30 struct {
|
||||
|
|
@ -34,6 +35,16 @@ func init() {
|
|||
})
|
||||
}
|
||||
|
||||
func (f *Fedora30) Repositories() []rpmmd.RepoConfig {
|
||||
return []rpmmd.RepoConfig{
|
||||
{
|
||||
Id: "fedora",
|
||||
Name: "Fedora 30",
|
||||
Metalink: "https://mirrors.fedoraproject.org/metalink?repo=fedora-30&arch=x86_64",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ListOutputFormats returns a sorted list of the supported output formats
|
||||
func (f *Fedora30) ListOutputFormats() []string {
|
||||
formats := make([]string, 0, len(f.outputs))
|
||||
|
|
|
|||
36
internal/distro/test/distro.go
Normal file
36
internal/distro/test/distro.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/pipeline"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
type TestDistro struct{}
|
||||
|
||||
func init() {
|
||||
distro.Register("test", &TestDistro{})
|
||||
}
|
||||
|
||||
func (d *TestDistro) Repositories() []rpmmd.RepoConfig {
|
||||
return []rpmmd.RepoConfig{
|
||||
{
|
||||
Id: "test",
|
||||
Name: "Test",
|
||||
BaseURL: "http://example.com/test/os",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *TestDistro) ListOutputFormats() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (d *TestDistro) FilenameFromType(outputFormat string) (string, string, error) {
|
||||
return "", "", &distro.InvalidOutputFormatError{outputFormat}
|
||||
}
|
||||
|
||||
func (d *TestDistro) Pipeline(b *blueprint.Blueprint, outputFormat string) (*pipeline.Pipeline, error) {
|
||||
return nil, &distro.InvalidOutputFormatError{outputFormat}
|
||||
}
|
||||
|
|
@ -25,19 +25,19 @@ type API struct {
|
|||
store *store.Store
|
||||
|
||||
rpmmd rpmmd.RPMMD
|
||||
repo rpmmd.RepoConfig
|
||||
distro distro.Distro
|
||||
|
||||
logger *log.Logger
|
||||
router *httprouter.Router
|
||||
}
|
||||
|
||||
func New(rpmmd rpmmd.RPMMD, repo rpmmd.RepoConfig, logger *log.Logger, store *store.Store) *API {
|
||||
func New(rpmmd rpmmd.RPMMD, distro distro.Distro, logger *log.Logger, store *store.Store) *API {
|
||||
// This needs to be shared with the worker API so that they can communicate with each other
|
||||
// builds := make(chan queue.Build, 200)
|
||||
api := &API{
|
||||
store: store,
|
||||
rpmmd: rpmmd,
|
||||
repo: repo,
|
||||
distro: distro,
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,10 @@ func (api *API) sourceListHandler(writer http.ResponseWriter, request *http.Requ
|
|||
}
|
||||
|
||||
names := api.store.ListSources()
|
||||
names = append(names, api.repo.Id)
|
||||
|
||||
for _, repo := range api.distro.Repositories() {
|
||||
names = append(names, repo.Id)
|
||||
}
|
||||
|
||||
json.NewEncoder(writer).Encode(reply{
|
||||
Sources: names,
|
||||
|
|
@ -203,14 +206,25 @@ func (api *API) sourceInfoHandler(writer http.ResponseWriter, request *http.Requ
|
|||
// if names is "*" we want all sources
|
||||
if names == "*" {
|
||||
sources = api.store.GetAllSources()
|
||||
sources[api.repo.Id] = store.NewSourceConfig(api.repo, true)
|
||||
for _, repo := range api.distro.Repositories() {
|
||||
sources[repo.Id] = store.NewSourceConfig(repo, true)
|
||||
}
|
||||
} else {
|
||||
for _, name := range strings.Split(names, ",") {
|
||||
// check if the source is in the base repo
|
||||
if name == api.repo.Id {
|
||||
sources[api.repo.Id] = store.NewSourceConfig(api.repo, true)
|
||||
// check if the source is one of the base repos
|
||||
found := false
|
||||
for _, repo := range api.distro.Repositories() {
|
||||
if name == repo.Id {
|
||||
sources[repo.Id] = store.NewSourceConfig(repo, true)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
// check if the source is in the store
|
||||
} else if source := api.store.GetSource(name); source != nil {
|
||||
if source := api.store.GetSource(name); source != nil {
|
||||
sources[source.Name] = *source
|
||||
} else {
|
||||
error := responseError{
|
||||
|
|
@ -483,7 +497,7 @@ func (api *API) modulesInfoHandler(writer http.ResponseWriter, request *http.Req
|
|||
|
||||
if modulesRequested {
|
||||
for i, _ := range packageInfos {
|
||||
err := packageInfos[i].FillDependencies(api.rpmmd, []rpmmd.RepoConfig{api.repo})
|
||||
err := packageInfos[i].FillDependencies(api.rpmmd, api.distro.Repositories())
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
ID: errorId,
|
||||
|
|
@ -509,7 +523,7 @@ func (api *API) projectsDepsolveHandler(writer http.ResponseWriter, request *htt
|
|||
|
||||
names := strings.Split(params.ByName("projects"), ",")
|
||||
|
||||
packages, err := api.rpmmd.Depsolve(names, []rpmmd.RepoConfig{api.repo})
|
||||
packages, err := api.rpmmd.Depsolve(names, api.distro.Repositories())
|
||||
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
|
|
@ -657,7 +671,9 @@ func (api *API) blueprintsDepsolveHandler(writer http.ResponseWriter, request *h
|
|||
}
|
||||
|
||||
var repos []rpmmd.RepoConfig
|
||||
repos = append(repos, api.repo)
|
||||
for _, repo := range api.distro.Repositories() {
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
for _, source := range api.store.GetAllSources() {
|
||||
repos = append(repos, source.RepoConfig())
|
||||
}
|
||||
|
|
@ -725,7 +741,9 @@ func (api *API) blueprintsFreezeHandler(writer http.ResponseWriter, request *htt
|
|||
}
|
||||
|
||||
var repos []rpmmd.RepoConfig
|
||||
repos = append(repos, api.repo)
|
||||
for _, repo := range api.distro.Repositories() {
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
for _, source := range api.store.GetAllSources() {
|
||||
repos = append(repos, source.RepoConfig())
|
||||
}
|
||||
|
|
@ -1163,7 +1181,9 @@ func (api *API) composeFailedHandler(writer http.ResponseWriter, request *http.R
|
|||
|
||||
func (api *API) fetchPackageList() (rpmmd.PackageList, error) {
|
||||
var repos []rpmmd.RepoConfig
|
||||
repos = append(repos, api.repo)
|
||||
for _, repo := range api.distro.Repositories() {
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
for _, source := range api.store.GetAllSources() {
|
||||
repos = append(repos, source.RepoConfig())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,16 +17,12 @@ import (
|
|||
"time"
|
||||
|
||||
rpmmd_mock "github.com/osbuild/osbuild-composer/internal/mocks/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
"github.com/osbuild/osbuild-composer/internal/weldr"
|
||||
)
|
||||
|
||||
var repo = rpmmd.RepoConfig{
|
||||
Id: "test",
|
||||
Name: "Test",
|
||||
BaseURL: "http://example.com/test/os",
|
||||
}
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
_ "github.com/osbuild/osbuild-composer/internal/distro/test"
|
||||
)
|
||||
|
||||
func externalRequest(method, path, body string) *http.Response {
|
||||
client := http.Client{
|
||||
|
|
@ -159,8 +155,9 @@ func testRoute(t *testing.T, api *weldr.API, external bool, method, path, body s
|
|||
func createWeldrAPI(fixture rpmmd_mock.Fixture) (*weldr.API, *store.Store) {
|
||||
s := store.New(nil)
|
||||
rpm := rpmmd_mock.NewRPMMDMock(fixture)
|
||||
d := distro.New("test")
|
||||
|
||||
return weldr.New(rpm, repo, nil, s), s
|
||||
return weldr.New(rpm, d, nil, s), s
|
||||
}
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue