Skip to content

Commit

Permalink
main: add new experimental --use-librepo switch
Browse files Browse the repository at this point in the history
This commit adds a new `--use-librepo` switch that will
enable librepo based downloading so that people can play with
the new backend.
  • Loading branch information
mvo5 committed Jan 14, 2025
1 parent fff4c12 commit effac82
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion bib/cmd/bootc-image-builder/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -103,15 +104,15 @@ 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)
}

// 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)
Expand All @@ -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)
}
Expand All @@ -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())
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions bib/cmd/bootc-image-builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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)
})
})
Expand Down

0 comments on commit effac82

Please sign in to comment.