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 committed Dec 20, 2023
1 parent f43a3f2 commit cfe6678
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()

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)

Expand All @@ -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, ","))
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cfe6678

Please sign in to comment.