diff --git a/cmd/gen-manifests/main.go b/cmd/gen-manifests/main.go index 01aaa09ee3..f3c8109071 100644 --- a/cmd/gen-manifests/main.go +++ b/cmd/gen-manifests/main.go @@ -24,6 +24,7 @@ import ( "github.com/osbuild/images/pkg/dnfjson" "github.com/osbuild/images/pkg/manifest" "github.com/osbuild/images/pkg/ostree" + "github.com/osbuild/images/pkg/reporegistry" "github.com/osbuild/images/pkg/rhsm/facts" "github.com/osbuild/images/pkg/rpmmd" ) @@ -290,48 +291,6 @@ func makeManifestJob( return job } -type DistroArchRepoMap map[string]map[string][]rpmmd.RepoConfig - -func (d DistroArchRepoMap) ListDistros() []string { - distros := make([]string, 0, len(d)) - for distro := range d { - distros = append(distros, distro) - } - return distros -} - -func readRepos() DistroArchRepoMap { - reposDir := "./test/data/repositories/" - darm := make(DistroArchRepoMap) - filelist, err := os.ReadDir(reposDir) - if err != nil { - panic(err) - } - for _, file := range filelist { - filename := file.Name() - if !strings.HasSuffix(filename, ".json") { - continue - } - reposFilepath := filepath.Join(reposDir, filename) - fp, err := os.Open(reposFilepath) - if err != nil { - panic(err) - } - defer fp.Close() - data, err := io.ReadAll(fp) - if err != nil { - panic(err) - } - repos := make(map[string][]rpmmd.RepoConfig) - if err := json.Unmarshal(data, &repos); err != nil { - panic(err) - } - distro := strings.TrimSuffix(filename, filepath.Ext(filename)) - darm[distro] = repos - } - return darm -} - func resolveContainers(containers []container.SourceSpec, archName string) ([]container.Spec, error) { resolver := container.NewResolver(archName) @@ -563,7 +522,12 @@ func main() { flag.Parse() seedArg := int64(0) - darm := readRepos() + + repoRegistry, err := reporegistry.New([]string{"./test/data"}) + if err != nil { + panic(fmt.Sprintf("failed to load repositories: %v", err)) + } + distroFac := distrofactory.NewDefault() jobs := make([]manifestJob, 0) @@ -587,7 +551,7 @@ func main() { fmt.Println("Collecting jobs") - distros, invalidDistros := resolveArgValues(distros, darm.ListDistros()) + distros, invalidDistros := resolveArgValues(distros, repoRegistry.ListDistros()) if len(invalidDistros) > 0 { fmt.Fprintf(os.Stderr, "WARNING: invalid distro names: [%s]\n", strings.Join(invalidDistros, ",")) } @@ -621,7 +585,10 @@ func main() { } // get repositories - repos := darm[distroName][archName] + repos, err := repoRegistry.ReposByArchName(distroName, archName, true) + if err != nil { + panic(fmt.Sprintf("failed to get repositories for %s/%s: %v", distroName, archName, err)) + } repos = filterRepos(repos, imgTypeName) if len(repos) == 0 { fmt.Printf("no repositories defined for %s/%s/%s\n", distroName, archName, imgTypeName)