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

main: add new --use-librepo switch #786

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sudo podman run \
quay.io/centos-bootc/bootc-image-builder:latest \
--type qcow2 \
--local \
--use-librepo=True \
quay.io/centos-bootc/centos-bootc:stream9
```

Expand Down Expand Up @@ -153,6 +154,7 @@ Global Flags:
| --target-arch | [Target arch](#-target-architecture) to build | ❌ |
| --log-level | Change log level (debug, info, error) | `error` |
| -v,--verbose | Switch output/progress to verbose mode (implies --log-level=info) | `false` |
| --use-librepo | Download rpms using librepo (faster and more robust) | `false` |

The `--type` parameter can be given multiple times and multiple
outputs will be produced. Note that comma or space separating the
Expand Down
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
20 changes: 14 additions & 6 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,20 +104,20 @@ 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)
depsolvedSets := make(map[string]dnfjson.DepsolveResult)
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)
}
depsolvedSets[name] = res.Packages
depsolvedSets[name] = *res
depsolvedRepos[name] = res.Repos
}

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 opts manifest.SerializeOptions
if c.UseLibrepo {
opts.RpmDownloader = osbuild.RpmDownloaderLibrepo
}
mf, err := mani.Serialize(depsolvedSets, containerSpecs, nil, &opts)
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
68 changes: 38 additions & 30 deletions bib/cmd/bootc-image-builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/osbuild/images/pkg/arch"
"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"

Expand Down Expand Up @@ -63,7 +64,7 @@ func TestCanChownInPathCannotChange(t *testing.T) {
type manifestTestCase struct {
config *main.ManifestConfig
imageTypes imagetypes.ImageTypes
packages map[string][]rpmmd.PackageSpec
depsolved map[string]dnfjson.DepsolveResult
containers map[string][]container.Spec
expStages map[string][]string
notExpectedStages map[string][]string
Expand Down Expand Up @@ -228,39 +229,46 @@ func TestManifestSerialization(t *testing.T) {
containerSpec,
},
}
isoPackages := map[string][]rpmmd.PackageSpec{
isoPackages := map[string]dnfjson.DepsolveResult{
"build": {
{
Name: "package",
Version: "113",
Checksum: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
Packages: []rpmmd.PackageSpec{
{
Name: "package",
Version: "113",
Checksum: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
},
},
},
"anaconda-tree": {
{
Name: "kernel",
Version: "10.11",
Checksum: "sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
},
{
Name: "package",
Version: "113",
Checksum: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
Packages: []rpmmd.PackageSpec{
{
Name: "kernel",
Version: "10.11",
Checksum: "sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
},
{
Name: "package",
Version: "113",
Checksum: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
},
},
},
}

pkgsNoBuild := map[string][]rpmmd.PackageSpec{
pkgsNoBuild := map[string]dnfjson.DepsolveResult{
"anaconda-tree": {
{
Name: "kernel",
Version: "10.11",
Checksum: "sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
},
{
Name: "package",
Version: "113",
Checksum: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
Packages: []rpmmd.PackageSpec{

{
Name: "kernel",
Version: "10.11",
Checksum: "sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
},
{
Name: "package",
Version: "113",
Checksum: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
},
},
},
}
Expand Down Expand Up @@ -368,7 +376,7 @@ func TestManifestSerialization(t *testing.T) {
config: userConfig,
imageTypes: []string{"iso"},
containers: isoContainers,
packages: isoPackages,
depsolved: isoPackages,
expStages: map[string][]string{
"build": {"org.osbuild.rpm"},
"bootiso-tree": {"org.osbuild.skopeo"}, // adds the container to the ISO tree
Expand All @@ -378,13 +386,13 @@ func TestManifestSerialization(t *testing.T) {
config: userConfig,
imageTypes: []string{"iso"},
containers: isoContainers,
packages: pkgsNoBuild,
depsolved: pkgsNoBuild,
err: "serialization not started",
},
"iso-nocontainer": {
config: userConfig,
imageTypes: []string{"iso"},
packages: isoPackages,
depsolved: isoPackages,
err: "missing ostree, container, or ospipeline parameters in ISO tree pipeline",
},
"ami-nocontainer": {
Expand Down Expand Up @@ -421,11 +429,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.depsolved, tc.containers, nil, nil)
assert.NoError(err)
})
} else {
manifestJson, err := mf.Serialize(tc.packages, tc.containers, nil, nil)
manifestJson, err := mf.Serialize(tc.depsolved, tc.containers, nil, nil)
assert.NoError(err)
assert.NoError(checkStages(manifestJson, tc.expStages, tc.notExpectedStages))
}
Expand Down
18 changes: 9 additions & 9 deletions bib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.7.0
github.com/mattn/go-isatty v0.0.20
github.com/osbuild/images v0.108.0
github.com/osbuild/images v0.109.1-0.20250117082457-97ca7c62eb09
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -115,13 +115,13 @@ require (
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/grpc v1.67.3 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Loading
Loading