Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dnf-json #313

Merged
merged 8 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dnfjson: osbuild-depsolve-dnf finder function
Add findDepsolveDnf() to the dnfjson package and call it when
initialising the solver.  This used to be a helper function in some of
the cmds and would look for dnf-json in the current directory for
running it from sources then fall back to the installed locations.  Now
that it's no longer part of the repository, it only searches for the
installed locations, `/usr/libexec` for the official Fedora, CentOS, and
RHEL paths, and `/usr/lib/osbuild` for other distros that might not user
`/usr/libexec`.
  • Loading branch information
achilleas-k committed Dec 12, 2023
commit bbc35f4b2260db466abcc7ee6ddc49e2898716a3
1 change: 0 additions & 1 deletion cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func resolvePipelineCommits(commitSources map[string][]ostree.SourceSpec) (map[s

func depsolve(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d distro.Distro, arch string) (map[string][]rpmmd.PackageSpec, error) {
solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch, d.Name(), cacheDir)
solver.SetDNFJSONPath("./dnf-json")
depsolvedSets := make(map[string][]rpmmd.PackageSpec)
for name, pkgSet := range packageSets {
res, err := solver.Depsolve(pkgSet)
Expand Down
1 change: 0 additions & 1 deletion cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ func mockResolveCommits(commitSources map[string][]ostree.SourceSpec) map[string

func depsolve(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d distro.Distro, arch string) (map[string][]rpmmd.PackageSpec, error) {
solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch, d.Name(), cacheDir)
solver.SetDNFJSONPath("./dnf-json")
depsolvedSets := make(map[string][]rpmmd.PackageSpec)
for name, pkgSet := range packageSets {
res, err := solver.Depsolve(pkgSet)
Expand Down
17 changes: 0 additions & 17 deletions cmd/osbuild-playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@ func AddImageType(img image.ImageKind) {
ImageTypes[img.Name()] = img
}

// osbuild-playground is a utility command and is often run from within the
// source tree. Find the dnf-json binary in case the osbuild-composer package
// isn't installed. This prioritises the local source version over the system
// version if run from within the source tree.
func findDnfJsonBin() string {
locations := []string{"./dnf-json", "/usr/libexec/osbuild-composer/dnf-json", "/usr/lib/osbuild-composer/dnf-json"}
for _, djPath := range locations {
_, err := os.Stat(djPath)
if !os.IsNotExist(err) {
return djPath
}
}

// can't run: panic
panic(fmt.Sprintf("could not find 'dnf-json' in any of the known paths: %+v", locations))
}

func main() {
var distroArg string
flag.StringVar(&distroArg, "distro", "host", "distro to build from")
Expand Down
1 change: 0 additions & 1 deletion cmd/osbuild-playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
func RunPlayground(img image.ImageKind, d distro.Distro, arch distro.Arch, repos map[string][]rpmmd.RepoConfig, state_dir string) {

solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch.Name(), d.Name(), path.Join(state_dir, "rpmmd"))
solver.SetDNFJSONPath(findDnfJsonBin())

// Set cache size to 1 GiB
solver.SetMaxCacheSize(1 * common.GiB)
Expand Down
23 changes: 20 additions & 3 deletions pkg/dnfjson/dnfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,36 @@ type BaseSolver struct {
// Cache information
cache *rpmCache

// Path to the dnf-json binary and optional args (default: "/usr/libexec/osbuild-composer/dnf-json")
// Path to the dnf-json binary and optional args (default: "/usr/libexec/osbuild-depsolve-dnf")
dnfJsonCmd []string

resultCache *dnfCache
}

// Find the osbuild-depsolve-dnf script. This checks the default location in
// /usr/libexec but also /usr/lib in case it's used on a distribution that
// doesn't use libexec.
func findDepsolveDnf() string {
locations := []string{"/usr/libexec/osbuild-depsolve-dnf", "/usr/lib/osbuild/osbuild-depsolve-dnf"}
for _, djPath := range locations {
_, err := os.Stat(djPath)
if !os.IsNotExist(err) {
return djPath
}
}

// if it's not found, return empty string; the run() function will fail if
// it's used before setting.
return locations[0]
}

// Create a new unconfigured BaseSolver (without platform information). It can
// be used to create configured Solver instances with the NewWithConfig()
// method.
func NewBaseSolver(cacheDir string) *BaseSolver {
return &BaseSolver{
cache: newRPMCache(cacheDir, 1024*1024*1024), // 1 GiB
dnfJsonCmd: []string{"/usr/libexec/osbuild-composer/dnf-json"},
dnfJsonCmd: []string{findDepsolveDnf()},
resultCache: NewDNFCache(60 * time.Second),
}
}
Expand Down Expand Up @@ -620,7 +637,7 @@ func ParseError(data []byte) Error {

func run(dnfJsonCmd []string, req *Request) ([]byte, error) {
if len(dnfJsonCmd) == 0 {
return nil, fmt.Errorf("dnf-json command undefined")
return nil, fmt.Errorf("osbuild-depsolve-dnf command undefined")
}
ex := dnfJsonCmd[0]
args := make([]string, len(dnfJsonCmd)-1)
Expand Down
3 changes: 0 additions & 3 deletions pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestDepsolver(t *testing.T) {

tmpdir := t.TempDir()
solver := NewSolver("platform:el9", "9", "x86_64", "rhel9.0", tmpdir)
solver.SetDNFJSONPath("../../dnf-json")

{ // single depsolve
pkgsets := []rpmmd.PackageSet{{Include: []string{"kernel", "vim-minimal", "tmux", "zsh"}, Repositories: []rpmmd.RepoConfig{s.RepoConfig}, InstallWeakDeps: true}} // everything you'll ever need
Expand Down Expand Up @@ -602,7 +601,6 @@ func TestErrorRepoInfo(t *testing.T) {
}

solver := NewSolver("f38", "38", "x86_64", "fedora-38", "/tmp/cache")
solver.SetDNFJSONPath("../../dnf-json")
for idx, tc := range testCases {
t.Run(fmt.Sprintf("%d", idx), func(t *testing.T) {
_, err := solver.Depsolve([]rpmmd.PackageSet{
Expand Down Expand Up @@ -632,7 +630,6 @@ func TestRepoConfigHash(t *testing.T) {
}

solver := NewSolver("f38", "38", "x86_64", "fedora-38", "/tmp/cache")
solver.SetDNFJSONPath("../../dnf-json")

rcs, err := solver.reposFromRPMMD(repos)
assert.Nil(t, err)
Expand Down