osbuild-composer: Move InitWeldr code into weldr.New
This will make it easier to support new features related to building for other distribution releases.
This commit is contained in:
parent
a330d84739
commit
9818b4b6b1
4 changed files with 62 additions and 35 deletions
|
|
@ -13,13 +13,10 @@ import (
|
|||
"path"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/cloudapi"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/jobqueue/fsjobqueue"
|
||||
"github.com/osbuild/osbuild-composer/internal/kojiapi"
|
||||
"github.com/osbuild/osbuild-composer/internal/reporegistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
"github.com/osbuild/osbuild-composer/internal/weldr"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
)
|
||||
|
|
@ -73,35 +70,11 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string, logger *
|
|||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *Composer) InitWeldr(repoPaths []string, weldrListener net.Listener) error {
|
||||
archName := common.CurrentArch()
|
||||
|
||||
hostDistro := c.distros.FromHost()
|
||||
if hostDistro == nil {
|
||||
return fmt.Errorf("host distro is not supported")
|
||||
}
|
||||
|
||||
arch, err := hostDistro.GetArch(archName)
|
||||
func (c *Composer) InitWeldr(repoPaths []string, weldrListener net.Listener) (err error) {
|
||||
c.weldr, err = weldr.New(repoPaths, c.stateDir, c.rpm, c.distros, c.logger, c.workers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Host distro does not support host architecture: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
rr, err := reporegistry.New(repoPaths)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading repository definitions: %v", err)
|
||||
}
|
||||
|
||||
// Check if repositories for the host distro and arch were loaded
|
||||
_, err = rr.ReposByArch(arch, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("loaded repository definitions don't contain any for the host distro/arch: %v", err)
|
||||
}
|
||||
|
||||
store := store.New(&c.stateDir, arch, c.logger)
|
||||
compatOutputDir := path.Join(c.stateDir, "outputs")
|
||||
|
||||
c.weldr = weldr.New(c.rpm, arch, hostDistro, rr, c.logger, store, c.workers, compatOutputDir)
|
||||
|
||||
c.weldrListener = weldrListener
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func executeTests(m *testing.M) int {
|
|||
})
|
||||
|
||||
logger := log.New(os.Stdout, "", 0)
|
||||
api := weldr.New(rpm, arch, distro, rr, logger, fixture.Store, fixture.Workers, "")
|
||||
api := weldr.NewTestAPI(rpm, arch, distro, rr, logger, fixture.Store, fixture.Workers, "")
|
||||
server := http.Server{Handler: api}
|
||||
defer server.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
|
|
@ -53,6 +54,9 @@ type API struct {
|
|||
router *httprouter.Router
|
||||
|
||||
compatOutputDir string
|
||||
|
||||
hostDistroName string // Name of the host distro
|
||||
distros *distroregistry.Registry // Supported distros
|
||||
}
|
||||
|
||||
type ComposeState int
|
||||
|
|
@ -94,18 +98,68 @@ func (api *API) systemRepoNames() (names []string) {
|
|||
|
||||
var ValidBlueprintName = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)
|
||||
|
||||
func New(rpmmd rpmmd.RPMMD, arch distro.Arch, distro distro.Distro, repoRegistry *reporegistry.RepoRegistry, logger *log.Logger, store *store.Store, workers *worker.Server, compatOutputDir string) *API {
|
||||
// NewTestAPI is used for the test framework, sets up a single distro
|
||||
func NewTestAPI(rpm rpmmd.RPMMD, arch distro.Arch, distro distro.Distro, rr *reporegistry.RepoRegistry, logger *log.Logger, store *store.Store, workers *worker.Server, compatOutputDir string) *API {
|
||||
distros, _ := distroregistry.New(distro)
|
||||
|
||||
api := &API{
|
||||
store: store,
|
||||
workers: workers,
|
||||
rpmmd: rpmmd,
|
||||
rpmmd: rpm,
|
||||
arch: arch,
|
||||
distro: distro,
|
||||
repoRegistry: repoRegistry,
|
||||
repoRegistry: rr,
|
||||
logger: logger,
|
||||
compatOutputDir: compatOutputDir,
|
||||
hostDistroName: distro.Name(),
|
||||
distros: distros,
|
||||
}
|
||||
return setupRouter(api)
|
||||
}
|
||||
|
||||
func New(repoPaths []string, stateDir string, rpm rpmmd.RPMMD, distros *distroregistry.Registry, logger *log.Logger, workers *worker.Server) (*API, error) {
|
||||
|
||||
hostDistro := distros.FromHost()
|
||||
if hostDistro == nil {
|
||||
return nil, fmt.Errorf("host distro is not supported")
|
||||
}
|
||||
archName := common.CurrentArch()
|
||||
|
||||
hostArch, err := hostDistro.GetArch(archName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Host distro does not support host architecture: %v", err)
|
||||
}
|
||||
|
||||
rr, err := reporegistry.New(repoPaths)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading repository definitions: %v", err)
|
||||
}
|
||||
|
||||
// Check if repositories for the host distro and arch were loaded
|
||||
_, err = rr.ReposByArch(hostArch, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("loaded repository definitions don't contain any for the host distro/arch: %v", err)
|
||||
}
|
||||
|
||||
store := store.New(&stateDir, hostArch, logger)
|
||||
compatOutputDir := path.Join(stateDir, "outputs")
|
||||
|
||||
api := &API{
|
||||
store: store,
|
||||
workers: workers,
|
||||
rpmmd: rpm,
|
||||
arch: hostArch,
|
||||
distro: hostDistro,
|
||||
repoRegistry: rr,
|
||||
logger: logger,
|
||||
compatOutputDir: compatOutputDir,
|
||||
hostDistroName: hostDistro.Name(),
|
||||
distros: distros,
|
||||
}
|
||||
return setupRouter(api), nil
|
||||
}
|
||||
|
||||
func setupRouter(api *API) *API {
|
||||
api.router = httprouter.New()
|
||||
api.router.RedirectTrailingSlash = false
|
||||
api.router.RedirectFixedPath = false
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func createWeldrAPI(tempdir string, fixtureGenerator rpmmd_mock.FixtureGenerator
|
|||
panic(err)
|
||||
}
|
||||
|
||||
return New(rpm, arch, d, rr, nil, fixture.Store, fixture.Workers, ""), fixture.Store
|
||||
return NewTestAPI(rpm, arch, d, rr, nil, fixture.Store, fixture.Workers, ""), fixture.Store
|
||||
}
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue