Skip to content

Commit

Permalink
cmd/gen-manifests: use reporegistry instead of a custom code
Browse files Browse the repository at this point in the history
Rework the gen-manifests to use reporegistry for loading repo configs,
instead of own custom implementation.

Signed-off-by: Tomáš Hozza <[email protected]>
  • Loading branch information
thozza authored and achilleas-k committed Jan 2, 2024
1 parent 1f5d048 commit 845f8f5
Showing 1 changed file with 12 additions and 45 deletions.
57 changes: 12 additions & 45 deletions cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -563,7 +522,12 @@ func main() {
flag.Parse()

seedArg := int64(0)
darm := readRepos()

testedRepoRegistry, err := reporegistry.NewTestedDefault()
if err != nil {
panic(fmt.Sprintf("failed to create repo registry with tested distros: %v", err))
}

distroFac := distrofactory.NewDefault()
jobs := make([]manifestJob, 0)

Expand All @@ -587,7 +551,7 @@ func main() {

fmt.Println("Collecting jobs")

distros, invalidDistros := resolveArgValues(distros, darm.ListDistros())
distros, invalidDistros := resolveArgValues(distros, testedRepoRegistry.ListDistros())
if len(invalidDistros) > 0 {
fmt.Fprintf(os.Stderr, "WARNING: invalid distro names: [%s]\n", strings.Join(invalidDistros, ","))
}
Expand Down Expand Up @@ -621,7 +585,10 @@ func main() {
}

// get repositories
repos := darm[distroName][archName]
repos, err := testedRepoRegistry.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)
Expand Down

0 comments on commit 845f8f5

Please sign in to comment.