From effac82451321a96046a5fbe9483c59d67b27b04 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 8 Jan 2025 08:52:05 +0100 Subject: [PATCH] main: add new experimental `--use-librepo` switch This commit adds a new `--use-librepo` switch that will enable librepo based downloading so that people can play with the new backend. --- bib/cmd/bootc-image-builder/image.go | 5 ++++- bib/cmd/bootc-image-builder/main.go | 16 ++++++++++++---- bib/cmd/bootc-image-builder/main_test.go | 6 +++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bib/cmd/bootc-image-builder/image.go b/bib/cmd/bootc-image-builder/image.go index c34bb93fc..4d0d362fc 100644 --- a/bib/cmd/bootc-image-builder/image.go +++ b/bib/cmd/bootc-image-builder/image.go @@ -62,6 +62,9 @@ type ManifestConfig struct { // RootFSType specifies the filesystem type for the root partition RootFSType string + + // use librepo ad the rpm downlaod backend + UseLibrepo bool } func Manifest(c *ManifestConfig) (*manifest.Manifest, error) { @@ -434,7 +437,7 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro // in time img := image.NewAnacondaContainerInstaller(containerSource, "") img.ContainerRemoveSignatures = true - img.SquashfsCompression = "zstd" + img.RootfsCompression = "zstd" img.Product = c.SourceInfo.OSRelease.Name img.OSVersion = c.SourceInfo.OSRelease.VersionID diff --git a/bib/cmd/bootc-image-builder/main.go b/bib/cmd/bootc-image-builder/main.go index bc734f5ca..c19209bac 100644 --- a/bib/cmd/bootc-image-builder/main.go +++ b/bib/cmd/bootc-image-builder/main.go @@ -21,6 +21,7 @@ import ( "github.com/osbuild/images/pkg/container" "github.com/osbuild/images/pkg/dnfjson" "github.com/osbuild/images/pkg/manifest" + "github.com/osbuild/images/pkg/osbuild" "github.com/osbuild/images/pkg/rpmmd" "github.com/osbuild/bootc-image-builder/bib/internal/buildconfig" @@ -103,7 +104,7 @@ func getContainerSize(imgref string) (uint64, error) { } func makeManifest(c *ManifestConfig, solver *dnfjson.Solver, cacheRoot string) (manifest.OSBuildManifest, map[string][]rpmmd.RepoConfig, error) { - manifest, err := Manifest(c) + mani, err := Manifest(c) if err != nil { return nil, nil, fmt.Errorf("cannot get manifest: %w", err) } @@ -111,7 +112,7 @@ func makeManifest(c *ManifestConfig, solver *dnfjson.Solver, cacheRoot string) ( // depsolve packages depsolvedSets := make(map[string][]rpmmd.PackageSpec) depsolvedRepos := make(map[string][]rpmmd.RepoConfig) - for name, pkgSet := range manifest.GetPackageSetChains() { + for name, pkgSet := range mani.GetPackageSetChains() { res, err := solver.Depsolve(pkgSet, 0) if err != nil { return nil, nil, fmt.Errorf("cannot depsolve: %w", err) @@ -131,7 +132,7 @@ func makeManifest(c *ManifestConfig, solver *dnfjson.Solver, cacheRoot string) ( resolver := container.NewResolver(c.Architecture.String()) containerSpecs := make(map[string][]container.Spec) - for plName, sourceSpecs := range manifest.GetContainerSourceSpecs() { + for plName, sourceSpecs := range mani.GetContainerSourceSpecs() { for _, c := range sourceSpecs { resolver.Add(c) } @@ -147,7 +148,11 @@ func makeManifest(c *ManifestConfig, solver *dnfjson.Solver, cacheRoot string) ( containerSpecs[plName] = specs } - mf, err := manifest.Serialize(depsolvedSets, containerSpecs, nil, depsolvedRepos) + var rpmDownloader osbuild.RpmDownloader + if c.UseLibrepo { + rpmDownloader = osbuild.RpmDownloaderLibrepo + } + mf, err := mani.Serialize(depsolvedSets, containerSpecs, nil, depsolvedRepos, rpmDownloader) if err != nil { return nil, nil, fmt.Errorf("[ERROR] manifest serialization failed: %s", err.Error()) } @@ -192,6 +197,7 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress tlsVerify, _ := cmd.Flags().GetBool("tls-verify") localStorage, _ := cmd.Flags().GetBool("local") rootFs, _ := cmd.Flags().GetString("rootfs") + useLibrepo, _ := cmd.Flags().GetBool("use-librepo") if targetArch != "" && arch.FromString(targetArch) != arch.Current() { // TODO: detect if binfmt_misc for target arch is @@ -317,6 +323,7 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress DistroDefPaths: distroDefPaths, SourceInfo: sourceinfo, RootFSType: rootfsType, + UseLibrepo: useLibrepo, } manifest, repos, err := makeManifest(manifestConfig, solver, rpmCacheRoot) @@ -665,6 +672,7 @@ func buildCobraCmdline() (*cobra.Command, error) { manifestCmd.Flags().StringArray("type", []string{"qcow2"}, fmt.Sprintf("image types to build [%s]", imagetypes.Available())) manifestCmd.Flags().Bool("local", false, "use a local container rather than a container from a registry") manifestCmd.Flags().String("rootfs", "", "Root filesystem type. If not given, the default configured in the source container image is used.") + manifestCmd.Flags().Bool("use-librepo", false, "(experimenal) switch to librepo for pkg download, needs new enough osbuild") // --config is only useful for developers who run bib outside // of a container to generate a manifest. so hide it by // default from users. diff --git a/bib/cmd/bootc-image-builder/main_test.go b/bib/cmd/bootc-image-builder/main_test.go index 5cb5d97b9..2e54af7fe 100644 --- a/bib/cmd/bootc-image-builder/main_test.go +++ b/bib/cmd/bootc-image-builder/main_test.go @@ -421,11 +421,11 @@ func TestManifestSerialization(t *testing.T) { if tc.err != nil { assert.PanicsWithValue(tc.err, func() { - _, err := mf.Serialize(tc.packages, tc.containers, nil, nil) + _, err := mf.Serialize(tc.packages, tc.containers, nil, nil, 0) assert.NoError(err) }) } else { - manifestJson, err := mf.Serialize(tc.packages, tc.containers, nil, nil) + manifestJson, err := mf.Serialize(tc.packages, tc.containers, nil, nil, 0) assert.NoError(err) assert.NoError(checkStages(manifestJson, tc.expStages, tc.notExpectedStages)) } @@ -443,7 +443,7 @@ func TestManifestSerialization(t *testing.T) { expError := "package \"kernel\" not found in the PackageSpec list" assert.PanicsWithError(expError, func() { - _, err := manifest.Serialize(nil, isoContainers, nil, nil) + _, err := manifest.Serialize(nil, isoContainers, nil, nil, 0) assert.NoError(err) }) })