rpmmd: pass in cache directory explicitly
rpmmd looked at the CACHE_DIRECTORY environment variable to set a path for the dnf repository cache. Aside from being a smelly thing to do from a library, this breaks osbuild-pipeline and osbuild-dnf-json-tests, which don't run as systemd services and thus don't have CACHE_DIRECTORY set. Explicitly pass the cache directory to rpmmd. Keep using a path based on CACHE_DIRECTORY for osbuild-composer. Use the user's `.cache` directory for osbuild-pipeline and a temporary directory for the tests.
This commit is contained in:
parent
5e6103f4a8
commit
60301df8f7
4 changed files with 26 additions and 19 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/rcm"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path"
|
||||
"os"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
|
|
@ -73,7 +74,12 @@ func main() {
|
|||
weldrListener := composerListeners[0]
|
||||
jobListener := composerListeners[1]
|
||||
|
||||
rpm := rpmmd.NewRPMMD()
|
||||
cacheDirectory, ok := os.LookupEnv("CACHE_DIRECTORY")
|
||||
if !ok {
|
||||
log.Fatal("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
|
||||
}
|
||||
|
||||
rpm := rpmmd.NewRPMMD(path.Join(cacheDirectory, "rpmmd"))
|
||||
distros := distro.NewRegistry([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"})
|
||||
|
||||
distribution, err := distros.FromHost()
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func TestFetchChecksum(quiet bool, dir string) {
|
|||
if !quiet {
|
||||
log.Println("Running TestFetchChecksum on:", dir)
|
||||
}
|
||||
rpmMetadata := rpmmd.NewRPMMD()
|
||||
rpmMetadata := rpmmd.NewRPMMD(path.Join(dir, "rpmmd"))
|
||||
_, c, err := rpmMetadata.FetchMetadata([]rpmmd.RepoConfig{repoCfg}, "platform:f31")
|
||||
if err != nil {
|
||||
log.Panic("Failed to fetch checksum:", err)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
|
||||
|
|
@ -87,7 +88,12 @@ func main() {
|
|||
}
|
||||
packages = append(pkgs, packages...)
|
||||
|
||||
rpmmd := rpmmd.NewRPMMD()
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic("os.UserHomeDir(): " + err.Error())
|
||||
}
|
||||
|
||||
rpmmd := rpmmd.NewRPMMD(path.Join(home, ".cache/osbuild-composer/rpmmd"))
|
||||
packageSpecs, checksums, err := rpmmd.Depsolve(packages, exclude_pkgs, d.Repositories(archArg), d.ModulePlatformID(), false)
|
||||
if err != nil {
|
||||
panic("Could not depsolve: " + err.Error())
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
|
|
@ -211,22 +210,22 @@ func runDNF(command string, arguments interface{}, result interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type rpmmdImpl struct{}
|
||||
|
||||
func NewRPMMD() RPMMD {
|
||||
return &rpmmdImpl{}
|
||||
type rpmmdImpl struct {
|
||||
CacheDir string
|
||||
}
|
||||
|
||||
func (*rpmmdImpl) FetchMetadata(repos []RepoConfig, modulePlatformID string) (PackageList, map[string]string, error) {
|
||||
cacheDirectory, ok := os.LookupEnv("CACHE_DIRECTORY")
|
||||
if !ok {
|
||||
panic("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
|
||||
func NewRPMMD(cacheDir string) RPMMD {
|
||||
return &rpmmdImpl{
|
||||
CacheDir: cacheDir,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *rpmmdImpl) FetchMetadata(repos []RepoConfig, modulePlatformID string) (PackageList, map[string]string, error) {
|
||||
var arguments = struct {
|
||||
Repos []RepoConfig `json:"repos"`
|
||||
CacheDir string `json:"cachedir"`
|
||||
ModulePlatformID string `json:"module_platform_id"`
|
||||
}{repos, path.Join(cacheDirectory, "rpmmd"), modulePlatformID}
|
||||
}{repos, r.CacheDir, modulePlatformID}
|
||||
var reply struct {
|
||||
Checksums map[string]string `json:"checksums"`
|
||||
Packages PackageList `json:"packages"`
|
||||
|
|
@ -238,11 +237,7 @@ func (*rpmmdImpl) FetchMetadata(repos []RepoConfig, modulePlatformID string) (Pa
|
|||
return reply.Packages, reply.Checksums, err
|
||||
}
|
||||
|
||||
func (*rpmmdImpl) Depsolve(specs, excludeSpecs []string, repos []RepoConfig, modulePlatformID string, clean bool) ([]PackageSpec, map[string]string, error) {
|
||||
cacheDirectory, ok := os.LookupEnv("CACHE_DIRECTORY")
|
||||
if !ok {
|
||||
panic("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
|
||||
}
|
||||
func (r *rpmmdImpl) Depsolve(specs, excludeSpecs []string, repos []RepoConfig, modulePlatformID string, clean bool) ([]PackageSpec, map[string]string, error) {
|
||||
var arguments = struct {
|
||||
PackageSpecs []string `json:"package-specs"`
|
||||
ExcludSpecs []string `json:"exclude-specs"`
|
||||
|
|
@ -250,7 +245,7 @@ func (*rpmmdImpl) Depsolve(specs, excludeSpecs []string, repos []RepoConfig, mod
|
|||
CacheDir string `json:"cachedir"`
|
||||
ModulePlatformID string `json:"module_platform_id"`
|
||||
Clean bool `json:"clean,omitempty"`
|
||||
}{specs, excludeSpecs, repos, path.Join(cacheDirectory, "rpmmd"), modulePlatformID, clean}
|
||||
}{specs, excludeSpecs, repos, r.CacheDir, modulePlatformID, clean}
|
||||
var reply struct {
|
||||
Checksums map[string]string `json:"checksums"`
|
||||
Dependencies []PackageSpec `json:"dependencies"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue