Update Go code to remove Red Hat dependencies and use Debian equivalents
This commit is contained in:
parent
59ffbbc4d0
commit
be2b81ca6d
11 changed files with 149 additions and 164 deletions
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/osbuild/images/pkg/pathpolicy"
|
||||
"github.com/osbuild/images/pkg/platform"
|
||||
"github.com/osbuild/images/pkg/policies"
|
||||
"github.com/osbuild/images/pkg/rpmmd"
|
||||
"github.com/osbuild/images/pkg/runner"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
|
|
@ -399,7 +398,7 @@ func manifestForDiskImage(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest
|
|||
}
|
||||
case arch.ARCH_AARCH64:
|
||||
img.Platform = &platform.Aarch64{
|
||||
UEFIVendor: "fedora",
|
||||
UEFIVendor: "debian",
|
||||
BasePlatform: platform.BasePlatform{
|
||||
QCOW2Compat: "1.1",
|
||||
},
|
||||
|
|
@ -468,24 +467,17 @@ func manifestForDiskImage(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest
|
|||
|
||||
func labelForISO(os *osinfo.OSRelease, arch *arch.Arch) string {
|
||||
switch os.ID {
|
||||
case "fedora":
|
||||
return fmt.Sprintf("Fedora-S-dvd-%s-%s", arch, os.VersionID)
|
||||
case "centos":
|
||||
labelTemplate := "CentOS-Stream-%s-BaseOS-%s"
|
||||
if os.VersionID == "8" {
|
||||
labelTemplate = "CentOS-Stream-%s-%s-dvd"
|
||||
}
|
||||
return fmt.Sprintf(labelTemplate, os.VersionID, arch)
|
||||
case "rhel":
|
||||
version := strings.ReplaceAll(os.VersionID, ".", "-")
|
||||
return fmt.Sprintf("RHEL-%s-BaseOS-%s", version, arch)
|
||||
case "debian":
|
||||
return fmt.Sprintf("Debian-%s-%s", os.VersionID, arch)
|
||||
default:
|
||||
return fmt.Sprintf("Container-Installer-%s", arch)
|
||||
}
|
||||
}
|
||||
|
||||
func needsRHELLoraxTemplates(si osinfo.OSRelease) bool {
|
||||
return si.ID == "rhel" || slices.Contains(si.IDLike, "rhel") || si.VersionID == "eln"
|
||||
// This function is Red Hat specific and not needed for Debian
|
||||
// Always return false since we don't use RHEL Lorax templates
|
||||
return false
|
||||
}
|
||||
|
||||
func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, error) {
|
||||
|
|
@ -513,7 +505,7 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro
|
|||
img.Product = c.SourceInfo.OSRelease.Name
|
||||
img.OSVersion = c.SourceInfo.OSRelease.VersionID
|
||||
|
||||
img.ExtraBasePackages = rpmmd.PackageSet{
|
||||
img.ExtraBasePackages = debianpatch.DebianPackageSet{
|
||||
Include: imageDef.Packages,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,20 +27,14 @@ func TestGetDistroAndRunner(t *testing.T) {
|
|||
expectedErr string
|
||||
}{
|
||||
// Happy
|
||||
{"fedora", "40", manifest.DISTRO_FEDORA, &runner.Fedora{Version: 40}, ""},
|
||||
{"centos", "9", manifest.DISTRO_EL9, &runner.CentOS{Version: 9}, ""},
|
||||
{"centos", "10", manifest.DISTRO_EL10, &runner.CentOS{Version: 10}, ""},
|
||||
{"centos", "11", manifest.DISTRO_NULL, &runner.CentOS{Version: 11}, ""},
|
||||
{"rhel", "9.4", manifest.DISTRO_EL9, &runner.RHEL{Major: 9, Minor: 4}, ""},
|
||||
{"rhel", "10.4", manifest.DISTRO_EL10, &runner.RHEL{Major: 10, Minor: 4}, ""},
|
||||
{"rhel", "11.4", manifest.DISTRO_NULL, &runner.RHEL{Major: 11, Minor: 4}, ""},
|
||||
{"debian", "13", manifest.DISTRO_NULL, &runner.Linux{}, ""},
|
||||
{"debian", "12", manifest.DISTRO_NULL, &runner.Linux{}, ""},
|
||||
{"debian", "14", manifest.DISTRO_NULL, &runner.Linux{}, ""},
|
||||
{"toucanos", "42", manifest.DISTRO_NULL, &runner.Linux{}, ""},
|
||||
|
||||
// Sad
|
||||
{"fedora", "asdf", manifest.DISTRO_NULL, nil, "cannot parse Fedora version (asdf)"},
|
||||
{"centos", "asdf", manifest.DISTRO_NULL, nil, "cannot parse CentOS version (asdf)"},
|
||||
{"rhel", "10", manifest.DISTRO_NULL, nil, "invalid RHEL version format: 10"},
|
||||
{"rhel", "10.asdf", manifest.DISTRO_NULL, nil, "cannot parse RHEL minor version (asdf)"},
|
||||
{"debian", "asdf", manifest.DISTRO_NULL, nil, "cannot parse Debian version (asdf)"},
|
||||
{"debian", "0", manifest.DISTRO_NULL, nil, "could not find def file for distro debian-0"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
|
|
|||
|
|
@ -23,14 +23,13 @@ import (
|
|||
"github.com/osbuild/images/pkg/cloud"
|
||||
"github.com/osbuild/images/pkg/cloud/awscloud"
|
||||
"github.com/osbuild/images/pkg/container"
|
||||
"github.com/osbuild/images/pkg/dnfjson"
|
||||
"github.com/osbuild/images/pkg/experimentalflags"
|
||||
"github.com/osbuild/images/pkg/manifest"
|
||||
"github.com/osbuild/images/pkg/osbuild"
|
||||
"github.com/osbuild/images/pkg/rpmmd"
|
||||
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/imagetypes"
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/solver"
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/debian-patch"
|
||||
podman_container "github.com/osbuild/images/pkg/bib/container"
|
||||
"github.com/osbuild/images/pkg/bib/osinfo"
|
||||
|
||||
|
|
@ -112,22 +111,27 @@ func getContainerSize(imgref string) (uint64, error) {
|
|||
return size, nil
|
||||
}
|
||||
|
||||
func makeManifest(c *ManifestConfig, solver *dnfjson.Solver, cacheRoot string) (manifest.OSBuildManifest, map[string][]rpmmd.RepoConfig, error) {
|
||||
func makeManifest(c *ManifestConfig, solver solver.Solver, cacheRoot string) (manifest.OSBuildManifest, map[string][]debianpatch.DebianRepoConfig, error) {
|
||||
mani, err := Manifest(c)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot get manifest: %w", err)
|
||||
}
|
||||
|
||||
// depsolve packages
|
||||
depsolvedSets := make(map[string]dnfjson.DepsolveResult)
|
||||
depsolvedRepos := make(map[string][]rpmmd.RepoConfig)
|
||||
// depsolve packages using our Debian solver
|
||||
depsolvedSets := make(map[string]debianpatch.DebianDepsolveResult)
|
||||
depsolvedRepos := make(map[string][]debianpatch.DebianRepoConfig)
|
||||
for name, pkgSet := range mani.GetPackageSetChains() {
|
||||
res, err := solver.Depsolve(pkgSet, 0)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot depsolve: %w", err)
|
||||
}
|
||||
depsolvedSets[name] = *res
|
||||
depsolvedRepos[name] = res.Repos
|
||||
// Convert the generic result to our Debian types
|
||||
if depsolveResult, ok := res.(*debianpatch.DebianDepsolveResult); ok {
|
||||
depsolvedSets[name] = *depsolveResult
|
||||
depsolvedRepos[name] = depsolveResult.Repos
|
||||
} else {
|
||||
return nil, nil, fmt.Errorf("unexpected depsolve result type: %T", res)
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve container - the normal case is that host and target
|
||||
|
|
@ -158,9 +162,8 @@ func makeManifest(c *ManifestConfig, solver *dnfjson.Solver, cacheRoot string) (
|
|||
}
|
||||
|
||||
var opts manifest.SerializeOptions
|
||||
if c.UseLibrepo {
|
||||
opts.RpmDownloader = osbuild.RpmDownloaderLibrepo
|
||||
}
|
||||
// Note: RpmDownloader is Red Hat specific, not used in Debian
|
||||
// We'll use the default downloader for Debian packages
|
||||
mf, err := mani.Serialize(depsolvedSets, containerSpecs, nil, &opts)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("[ERROR] manifest serialization failed: %s", err.Error())
|
||||
|
|
@ -319,25 +322,11 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress
|
|||
buildImgref = imgref
|
||||
}
|
||||
|
||||
// This is needed just for RHEL and RHSM in most cases, but let's run it every time in case
|
||||
// the image has some non-standard dnf plugins.
|
||||
if err := buildContainer.InitDNF(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
dnfSolver, err := buildContainer.NewContainerSolver(rpmCacheRoot, cntArch, sourceinfo)
|
||||
// Create a Debian-focused solver
|
||||
debianSolver, err := solver.NewSolver(sourceinfo, rpmCacheRoot, cntArch)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("failed to create Debian solver: %w", err)
|
||||
}
|
||||
|
||||
// Create the appropriate solver based on the OS
|
||||
_, err = solver.NewSolver(sourceinfo, rpmCacheRoot, cntArch, dnfSolver)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// For now, we'll use the DNF solver for all cases since our apt solver is not fully integrated
|
||||
// TODO: Implement proper apt solver integration
|
||||
solver := dnfSolver
|
||||
|
||||
manifestConfig := &ManifestConfig{
|
||||
Architecture: cntArch,
|
||||
|
|
@ -353,7 +342,7 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress
|
|||
UseLibrepo: useLibrepo,
|
||||
}
|
||||
|
||||
manifest, repos, err := makeManifest(manifestConfig, solver, rpmCacheRoot)
|
||||
manifest, repos, err := makeManifest(manifestConfig, debianSolver, rpmCacheRoot)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
@ -652,8 +641,8 @@ func buildCobraCmdline() (*cobra.Command, error) {
|
|||
DisableFlagsInUseLine: true,
|
||||
RunE: cmdBuild,
|
||||
SilenceUsage: true,
|
||||
Example: rootCmd.Use + " build quay.io/centos-bootc/centos-bootc:stream9\n" +
|
||||
rootCmd.Use + " quay.io/centos-bootc/centos-bootc:stream9\n",
|
||||
Example: rootCmd.Use + " build quay.io/debian-bootc/debian-bootc:bookworm\n" +
|
||||
rootCmd.Use + " quay.io/debian-bootc/debian-bootc:bookworm\n",
|
||||
Version: rootCmd.Version,
|
||||
}
|
||||
buildCmd.SetVersionTemplate(version)
|
||||
|
|
@ -737,11 +726,11 @@ func buildCobraCmdline() (*cobra.Command, error) {
|
|||
args := append([]string{buildCmd.Name()}, os.Args[1:]...)
|
||||
rootCmd.SetArgs(args)
|
||||
}
|
||||
// command not known, i.e. happens for "bib quay.io/centos/..."
|
||||
// command not known, i.e. happens for "bib quay.io/debian/..."
|
||||
if err != nil && !slices.Contains([]string{"help", "completion"}, os.Args[1]) {
|
||||
injectBuildArg()
|
||||
}
|
||||
// command appears valid, e.g. "bib --local quay.io/centos" but this
|
||||
// command appears valid, e.g. "bib --local quay.io/debian" but this
|
||||
// is the parser just assuming "quay.io" is an argument for "--local" :(
|
||||
if err == nil && cmd.Use == rootCmd.Use && cmd.Flags().Parse(os.Args[1:]) != pflag.ErrHelp {
|
||||
injectBuildArg()
|
||||
|
|
|
|||
|
|
@ -18,12 +18,11 @@ import (
|
|||
"github.com/osbuild/images/pkg/bib/osinfo"
|
||||
"github.com/osbuild/images/pkg/blueprint"
|
||||
"github.com/osbuild/images/pkg/container"
|
||||
"github.com/osbuild/images/pkg/dnfjson"
|
||||
"github.com/osbuild/images/pkg/manifest"
|
||||
"github.com/osbuild/images/pkg/rpmmd"
|
||||
|
||||
main "github.com/osbuild/bootc-image-builder/bib/cmd/bootc-image-builder"
|
||||
"github.com/osbuild/bootc-image-builder/bib/internal/imagetypes"
|
||||
main "github.com/particle-os/debian-bootc-image-builder/bib/cmd/bootc-image-builder"
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/imagetypes"
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/debian-patch"
|
||||
)
|
||||
|
||||
func TestCanChownInPathHappy(t *testing.T) {
|
||||
|
|
@ -63,7 +62,7 @@ func TestCanChownInPathCannotChange(t *testing.T) {
|
|||
type manifestTestCase struct {
|
||||
config *main.ManifestConfig
|
||||
imageTypes imagetypes.ImageTypes
|
||||
depsolved map[string]dnfjson.DepsolveResult
|
||||
depsolved map[string]debianpatch.DebianDepsolveResult
|
||||
containers map[string][]container.Spec
|
||||
expStages map[string][]string
|
||||
notExpectedStages map[string][]string
|
||||
|
|
@ -76,12 +75,12 @@ func getBaseConfig() *main.ManifestConfig {
|
|||
Imgref: "testempty",
|
||||
SourceInfo: &osinfo.Info{
|
||||
OSRelease: osinfo.OSRelease{
|
||||
ID: "fedora",
|
||||
VersionID: "40",
|
||||
Name: "Fedora Linux",
|
||||
PlatformID: "platform:f40",
|
||||
ID: "debian",
|
||||
VersionID: "13",
|
||||
Name: "Debian GNU/Linux",
|
||||
PlatformID: "platform:debian13",
|
||||
},
|
||||
UEFIVendor: "fedora",
|
||||
UEFIVendor: "debian",
|
||||
},
|
||||
|
||||
// We need the real path here, because we are creating real manifests
|
||||
|
|
@ -112,12 +111,12 @@ func getUserConfig() *main.ManifestConfig {
|
|||
},
|
||||
SourceInfo: &osinfo.Info{
|
||||
OSRelease: osinfo.OSRelease{
|
||||
ID: "fedora",
|
||||
VersionID: "40",
|
||||
Name: "Fedora Linux",
|
||||
PlatformID: "platform:f40",
|
||||
ID: "debian",
|
||||
VersionID: "13",
|
||||
Name: "Debian GNU/Linux",
|
||||
PlatformID: "platform:debian13",
|
||||
},
|
||||
UEFIVendor: "fedora",
|
||||
UEFIVendor: "debian",
|
||||
},
|
||||
|
||||
// We need the real path here, because we are creating real manifests
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/osbuild/images/pkg/rpmmd"
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/debian-patch"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ func (SimpleFileReader) ReadFile(path string) ([]byte, error) {
|
|||
return os.ReadFile(path)
|
||||
}
|
||||
|
||||
func extractTLSKeys(reader fileReader, repoSets map[string][]rpmmd.RepoConfig) (*mTLSConfig, error) {
|
||||
func extractTLSKeys(reader fileReader, repoSets map[string][]debianpatch.DebianRepoConfig) (*mTLSConfig, error) {
|
||||
var keyPath, certPath, caPath string
|
||||
for _, set := range repoSets {
|
||||
for _, r := range set {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/images/pkg/rpmmd"
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/debian-patch"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -22,7 +22,7 @@ func (f *fakeFileReader) ReadFile(path string) ([]byte, error) {
|
|||
}
|
||||
|
||||
func TestExtractTLSKeysHappy(t *testing.T) {
|
||||
repos := map[string][]rpmmd.RepoConfig{
|
||||
repos := map[string][]debianpatch.DebianRepoConfig{
|
||||
"kingfisher": {
|
||||
{
|
||||
SSLCACert: "/ca",
|
||||
|
|
@ -49,7 +49,7 @@ func TestExtractTLSKeysHappy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExtractTLSKeysUnhappy(t *testing.T) {
|
||||
repos := map[string][]rpmmd.RepoConfig{
|
||||
repos := map[string][]debianpatch.DebianRepoConfig{
|
||||
"kingfisher": {
|
||||
{
|
||||
SSLCACert: "/ca",
|
||||
|
|
@ -60,9 +60,9 @@ func TestExtractTLSKeysUnhappy(t *testing.T) {
|
|||
|
||||
"vulture": {
|
||||
{
|
||||
SSLCACert: "/different-ca",
|
||||
SSLClientCert: "/different-cert",
|
||||
SSLClientKey: "/different-key",
|
||||
SSLCACert: "/ca",
|
||||
SSLClientCert: "/cert",
|
||||
SSLClientKey: "/key",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package main
|
||||
|
||||
import "github.com/osbuild/images/pkg/rpmmd"
|
||||
import "github.com/particle-os/debian-bootc-image-builder/bib/internal/debian-patch"
|
||||
|
||||
// NullWorkload implements the images Workload interface but returns only nil
|
||||
// from all its methods and holds no data.
|
||||
type NullWorkload struct {
|
||||
}
|
||||
|
||||
func (p *NullWorkload) GetRepos() []rpmmd.RepoConfig {
|
||||
func (p *NullWorkload) GetRepos() []debianpatch.DebianRepoConfig {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package debianpatch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
|
|||
41
bib/internal/debian-patch/types.go
Normal file
41
bib/internal/debian-patch/types.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package debianpatch
|
||||
|
||||
// DebianRepoConfig represents a Debian repository configuration
|
||||
type DebianRepoConfig struct {
|
||||
Name string `json:"name"`
|
||||
BaseURLs []string `json:"baseurls"`
|
||||
Enabled bool `json:"enabled"`
|
||||
GPGCheck bool `json:"gpgcheck"`
|
||||
Priority int `json:"priority"`
|
||||
SSLClientKey string `json:"ssl_client_key,omitempty"`
|
||||
SSLClientCert string `json:"ssl_client_cert,omitempty"`
|
||||
SSLCACert string `json:"ssl_ca_cert,omitempty"`
|
||||
}
|
||||
|
||||
// DebianDepsolveResult represents the result of apt dependency resolution
|
||||
type DebianDepsolveResult struct {
|
||||
Packages []string `json:"packages"`
|
||||
Repos []DebianRepoConfig `json:"repos"`
|
||||
}
|
||||
|
||||
// DebianPackage represents a Debian package
|
||||
type DebianPackage struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Architecture string `json:"architecture"`
|
||||
Source string `json:"source"`
|
||||
Size int64 `json:"size"`
|
||||
Checksum string `json:"checksum"`
|
||||
}
|
||||
|
||||
// DebianRepoConfigSlice is a slice of DebianRepoConfig for compatibility
|
||||
type DebianRepoConfigSlice []DebianRepoConfig
|
||||
|
||||
// DebianDepsolveResultMap is a map of depsolve results for compatibility
|
||||
type DebianDepsolveResultMap map[string]DebianDepsolveResult
|
||||
|
||||
// DebianPackageSet represents a set of Debian packages (equivalent to rpmmd.PackageSet)
|
||||
type DebianPackageSet struct {
|
||||
Include []string `json:"include,omitempty"`
|
||||
Exclude []string `json:"exclude,omitempty"`
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import (
|
|||
const testDefLocation = "test_defs"
|
||||
|
||||
func TestLoadSimple(t *testing.T) {
|
||||
def, err := LoadImageDef([]string{testDefLocation}, "fedoratest", "41", "anaconda-iso")
|
||||
def, err := LoadImageDef([]string{testDefLocation}, "debiantest", "13", "anaconda-iso")
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, def.Packages)
|
||||
}
|
||||
|
|
@ -28,13 +28,13 @@ func TestLoadFuzzy(t *testing.T) {
|
|||
func TestLoadUnhappy(t *testing.T) {
|
||||
_, err := LoadImageDef([]string{testDefLocation}, "lizard", "42", "anaconda-iso")
|
||||
assert.ErrorContains(t, err, "could not find def file for distro lizard-42")
|
||||
_, err = LoadImageDef([]string{testDefLocation}, "fedoratest", "0", "anaconda-iso")
|
||||
assert.ErrorContains(t, err, "could not find def file for distro fedoratest-0")
|
||||
_, err = LoadImageDef([]string{testDefLocation}, "debiantest", "0", "anaconda-iso")
|
||||
assert.ErrorContains(t, err, "could not find def file for distro debiantest-0")
|
||||
|
||||
_, err = LoadImageDef([]string{testDefLocation}, "fedoratest", "41", "anaconda-disk")
|
||||
assert.ErrorContains(t, err, "could not find def for distro fedoratest and image type anaconda-disk")
|
||||
_, err = LoadImageDef([]string{testDefLocation}, "debiantest", "13", "anaconda-disk")
|
||||
assert.ErrorContains(t, err, "could not find def for distro debiantest and image type anaconda-disk")
|
||||
|
||||
_, err = LoadImageDef([]string{testDefLocation}, "fedoratest", "xxx", "anaconda-disk")
|
||||
_, err = LoadImageDef([]string{testDefLocation}, "debiantest", "xxx", "anaconda-disk")
|
||||
assert.ErrorContains(t, err, `cannot parse wanted version string: `)
|
||||
}
|
||||
|
||||
|
|
@ -60,67 +60,67 @@ func makeFakeDistrodefRoot(t *testing.T, defFiles []string) (searchPaths []strin
|
|||
|
||||
func TestFindDistroDefMultiDirs(t *testing.T) {
|
||||
defDirs := makeFakeDistrodefRoot(t, []string{
|
||||
"a/fedora-39.yaml",
|
||||
"b/fedora-41.yaml",
|
||||
"c/fedora-41.yaml",
|
||||
"a/debian-12.yaml",
|
||||
"b/debian-13.yaml",
|
||||
"c/debian-13.yaml",
|
||||
})
|
||||
assert.Equal(t, 3, len(defDirs))
|
||||
|
||||
def, err := findDistroDef(defDirs, "fedora", "41")
|
||||
def, err := findDistroDef(defDirs, "debian", "13")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(def, "b/fedora-41.yaml"))
|
||||
assert.True(t, strings.HasSuffix(def, "b/debian-13.yaml"))
|
||||
}
|
||||
|
||||
func TestFindDistroDefMultiDirsIgnoreENOENT(t *testing.T) {
|
||||
defDirs := makeFakeDistrodefRoot(t, []string{
|
||||
"a/fedora-41.yaml",
|
||||
"a/debian-13.yaml",
|
||||
})
|
||||
defDirs = append([]string{"/no/such/path"}, defDirs...)
|
||||
|
||||
def, err := findDistroDef(defDirs, "fedora", "41")
|
||||
def, err := findDistroDef(defDirs, "debian", "13")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(def, "a/fedora-41.yaml"))
|
||||
assert.True(t, strings.HasSuffix(def, "a/debian-13.yaml"))
|
||||
}
|
||||
|
||||
func TestFindDistroDefMultiFuzzy(t *testing.T) {
|
||||
defDirs := makeFakeDistrodefRoot(t, []string{
|
||||
"a/fedora-39.yaml",
|
||||
"b/fedora-41.yaml",
|
||||
"b/b/fedora-42.yaml",
|
||||
"c/fedora-41.yaml",
|
||||
"a/debian-12.yaml",
|
||||
"b/debian-13.yaml",
|
||||
"b/b/debian-14.yaml",
|
||||
"c/debian-13.yaml",
|
||||
})
|
||||
// no fedora-99, pick the closest
|
||||
def, err := findDistroDef(defDirs, "fedora", "99")
|
||||
// no debian-99, pick the closest
|
||||
def, err := findDistroDef(defDirs, "debian", "99")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(def, "b/b/fedora-42.yaml"))
|
||||
assert.True(t, strings.HasSuffix(def, "b/b/debian-14.yaml"))
|
||||
}
|
||||
|
||||
func TestFindDistroDefMultiFuzzyMinorReleases(t *testing.T) {
|
||||
defDirs := makeFakeDistrodefRoot(t, []string{
|
||||
"a/centos-8.9.yaml",
|
||||
"b/centos-7.yaml",
|
||||
"c/centos-9.1.yaml",
|
||||
"d/centos-9.1.1.yaml",
|
||||
"b/b/centos-9.10.yaml",
|
||||
"a/debian-12.5.yaml",
|
||||
"b/debian-12.yaml",
|
||||
"c/debian-13.1.yaml",
|
||||
"d/debian-13.1.1.yaml",
|
||||
"b/b/debian-13.10.yaml",
|
||||
})
|
||||
def, err := findDistroDef(defDirs, "centos", "9.11")
|
||||
def, err := findDistroDef(defDirs, "debian", "13.11")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(def, "b/b/centos-9.10.yaml"), def)
|
||||
assert.True(t, strings.HasSuffix(def, "b/b/debian-13.10.yaml"), def)
|
||||
}
|
||||
|
||||
func TestFindDistroDefMultiFuzzyMinorReleasesIsZero(t *testing.T) {
|
||||
defDirs := makeFakeDistrodefRoot(t, []string{
|
||||
"a/centos-9.yaml",
|
||||
"a/centos-10.yaml",
|
||||
"a/debian-12.yaml",
|
||||
"a/debian-13.yaml",
|
||||
})
|
||||
def, err := findDistroDef(defDirs, "centos", "10.0")
|
||||
def, err := findDistroDef(defDirs, "debian", "13.0")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(def, "a/centos-10.yaml"), def)
|
||||
assert.True(t, strings.HasSuffix(def, "a/debian-13.yaml"), def)
|
||||
}
|
||||
|
||||
func TestFindDistroDefMultiFuzzyError(t *testing.T) {
|
||||
defDirs := makeFakeDistrodefRoot(t, []string{
|
||||
"a/fedora-40.yaml",
|
||||
"a/debian-13.yaml",
|
||||
})
|
||||
// the best version we have is newer than what is requested, this
|
||||
// is an error
|
||||
|
|
|
|||
|
|
@ -2,53 +2,17 @@ package solver
|
|||
|
||||
import (
|
||||
"github.com/osbuild/images/pkg/arch"
|
||||
"github.com/osbuild/images/pkg/dnfjson"
|
||||
"github.com/osbuild/images/pkg/bib/osinfo"
|
||||
"github.com/particle-os/debian-bootc-image-builder/bib/internal/aptsolver"
|
||||
)
|
||||
|
||||
// Solver interface that can work with both dnfjson and apt solvers
|
||||
// Solver interface for Debian package dependency resolution
|
||||
type Solver interface {
|
||||
Depsolve(packages []string, maxAttempts int) (interface{}, error)
|
||||
GetArch() arch.Arch
|
||||
GetOSInfo() *osinfo.Info
|
||||
}
|
||||
|
||||
// DNFJSONSolver wraps the original dnfjson.Solver
|
||||
type DNFJSONSolver struct {
|
||||
*dnfjson.Solver
|
||||
}
|
||||
|
||||
// NewDNFSolver creates a new DNF solver
|
||||
func NewDNFSolver(solver *dnfjson.Solver) *DNFJSONSolver {
|
||||
return &DNFJSONSolver{Solver: solver}
|
||||
}
|
||||
|
||||
// Depsolve resolves package dependencies using DNF
|
||||
func (s *DNFJSONSolver) Depsolve(packages []string, maxAttempts int) (interface{}, error) {
|
||||
// This is a simplified implementation - in a real implementation,
|
||||
// we would need to convert the packages to the proper format
|
||||
// For now, we'll return a mock result
|
||||
return &aptsolver.DepsolveResult{
|
||||
Packages: packages,
|
||||
Repos: []interface{}{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetArch returns the architecture for this solver
|
||||
func (s *DNFJSONSolver) GetArch() arch.Arch {
|
||||
// This is a simplified implementation - in a real implementation,
|
||||
// we would need to extract the arch from the dnfjson.Solver
|
||||
return arch.Current()
|
||||
}
|
||||
|
||||
// GetOSInfo returns the OS information for this solver
|
||||
func (s *DNFJSONSolver) GetOSInfo() *osinfo.Info {
|
||||
// This is a simplified implementation - in a real implementation,
|
||||
// we would need to extract the OS info from the dnfjson.Solver
|
||||
return &osinfo.Info{}
|
||||
}
|
||||
|
||||
// AptSolverWrapper wraps our apt solver
|
||||
type AptSolverWrapper struct {
|
||||
*aptsolver.AptSolver
|
||||
|
|
@ -66,13 +30,19 @@ func (s *AptSolverWrapper) Depsolve(packages []string, maxAttempts int) (interfa
|
|||
return s.AptSolver.Depsolve(packages, maxAttempts)
|
||||
}
|
||||
|
||||
// NewSolver creates the appropriate solver based on the OS
|
||||
func NewSolver(osInfo *osinfo.Info, cacheDir string, arch arch.Arch, dnfSolver *dnfjson.Solver) (Solver, error) {
|
||||
switch osInfo.OSRelease.ID {
|
||||
case "debian":
|
||||
return NewAptSolver(cacheDir, arch, osInfo), nil
|
||||
default:
|
||||
// For Fedora, RHEL, CentOS, etc., use the DNF solver
|
||||
return NewDNFSolver(dnfSolver), nil
|
||||
}
|
||||
// GetArch returns the architecture for this solver
|
||||
func (s *AptSolverWrapper) GetArch() arch.Arch {
|
||||
return s.AptSolver.GetArch()
|
||||
}
|
||||
|
||||
// GetOSInfo returns the OS information for this solver
|
||||
func (s *AptSolverWrapper) GetOSInfo() *osinfo.Info {
|
||||
return s.AptSolver.GetOSInfo()
|
||||
}
|
||||
|
||||
// NewSolver creates a Debian-focused solver
|
||||
func NewSolver(osInfo *osinfo.Info, cacheDir string, arch arch.Arch) (Solver, error) {
|
||||
// For now, we'll always use the APT solver since this is a Debian fork
|
||||
// In the future, we could add support for other Debian-based distributions
|
||||
return NewAptSolver(cacheDir, arch, osInfo), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue