Skip to content

Commit

Permalink
cmd/build: use reporegistry instead of a custom code
Browse files Browse the repository at this point in the history
Rework the cmd/build 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 845f8f5 commit 58a2e9d
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"strings"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
"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 @@ -111,32 +111,6 @@ func makeManifest(imgType distro.ImageType, config BuildConfig, distribution dis
return mf, nil
}

type DistroArchRepoMap map[string]map[string][]rpmmd.RepoConfig

func readRepos() DistroArchRepoMap {
reposDir := "./test/data/repositories/"
darm := make(DistroArchRepoMap)
filelist, err := os.ReadDir(reposDir)
check(err)
for _, file := range filelist {
filename := file.Name()
if !strings.HasSuffix(filename, ".json") {
continue
}
reposFilepath := filepath.Join(reposDir, filename)
fp, err := os.Open(reposFilepath)
check(err)
defer fp.Close()
data, err := io.ReadAll(fp)
check(err)
repos := make(map[string][]rpmmd.RepoConfig)
check(json.Unmarshal(data, &repos))
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 @@ -247,7 +221,10 @@ func main() {
}

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()

config := loadConfig(configFile)
Expand Down Expand Up @@ -279,7 +256,11 @@ func main() {
}

// get repositories
repos := filterRepos(darm[distroName][archName], imgTypeName)
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 {
fail(fmt.Sprintf("no repositories defined for %s/%s\n", distroName, archName))
}
Expand Down

0 comments on commit 58a2e9d

Please sign in to comment.