Skip to content
Closed
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
25 changes: 20 additions & 5 deletions bib/cmd/bootc-image-builder/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math"
"math/big"
"math/rand"
"os"
"slices"
"strconv"
"strings"
Expand Down Expand Up @@ -336,7 +337,7 @@ func genPartitionTableFsCust(c *ManifestConfig, fsCust []blueprint.FilesystemCus
}
fsCustomizations := updateFilesystemSizes(fsCust, c.RootfsMinsize)

pt, err := disk.NewPartitionTable(&basept, fsCustomizations, DEFAULT_SIZE, partitioningMode, c.Architecture, nil, rng)
pt, err := disk.NewPartitionTable(&basept, fsCustomizations, DEFAULT_SIZE, partitioningMode, c.Architecture, nil, c.RootFSType, rng)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -667,13 +668,27 @@ func getDistroAndRunner(osRelease osinfo.OSRelease) (manifest.Distro, runner.Run
return manifest.DISTRO_NULL, &runner.Linux{}, nil
}

func createRand() *rand.Rand {
seed, err := cryptorand.Int(cryptorand.Reader, big.NewInt(math.MaxInt64))
// XXX: copied from images:internal/cmdutil/rand.go
const RNG_SEED_ENV_KEY = "OSBUILD_TESTING_RNG_SEED"

func randSeed() int64 {
if envSeedStr := os.Getenv(RNG_SEED_ENV_KEY); envSeedStr != "" {
envSeedInt, err := strconv.ParseInt(envSeedStr, 10, 64)
if err != nil {
panic(fmt.Errorf("failed to parse %s: %s", RNG_SEED_ENV_KEY, err))
}
fmt.Fprintf(os.Stderr, "TEST MODE: using rng seed %d\n", envSeedInt)
return envSeedInt
}
randSeed, err := cryptorand.Int(cryptorand.Reader, big.NewInt(math.MaxInt64))
if err != nil {
panic("Cannot generate an RNG seed.")
panic(fmt.Errorf("failed to generate random seed: %s", err))
}
return randSeed.Int64()
}

func createRand() *rand.Rand {
// math/rand is good enough in this case
/* #nosec G404 */
return rand.New(rand.NewSource(seed.Int64()))
return rand.New(rand.NewSource(randSeed()))
}
128 changes: 106 additions & 22 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand All @@ -20,13 +21,21 @@ import (

"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/bib/blueprintload"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/cloud"
"github.com/osbuild/images/pkg/cloud/awscloud"
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/distro/generic"
"github.com/osbuild/images/pkg/dnfjson"
"github.com/osbuild/images/pkg/experimentalflags"
"github.com/osbuild/images/pkg/imagefilter"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/manifestgen"
"github.com/osbuild/images/pkg/manifestgen/manifestmock"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/reporegistry"
"github.com/osbuild/images/pkg/rpmmd"

"github.com/osbuild/bootc-image-builder/bib/internal/imagetypes"
Expand Down Expand Up @@ -140,20 +149,24 @@ 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 mani.GetContainerSourceSpecs() {
for _, c := range sourceSpecs {
resolver.Add(c)
}
specs, err := resolver.Finish()
if err != nil {
return nil, nil, fmt.Errorf("cannot resolve containers: %w", err)
}
for _, spec := range specs {
if spec.Arch != c.Architecture {
return nil, nil, fmt.Errorf("image found is for unexpected architecture %q (expected %q), if that is intentional, please make sure --target-arch matches", spec.Arch, c.Architecture)
if experimentalflags.Bool("bib-mock-resolvers") {
containerSpecs = manifestmock.ResolveContainers(mani.GetContainerSourceSpecs())
} else {
for plName, sourceSpecs := range mani.GetContainerSourceSpecs() {
for _, c := range sourceSpecs {
resolver.Add(c)
}
specs, err := resolver.Finish()
if err != nil {
return nil, nil, fmt.Errorf("cannot resolve containers: %w", err)
}
for _, spec := range specs {
if spec.Arch != c.Architecture {
return nil, nil, fmt.Errorf("image found is for unexpected architecture %q (expected %q), if that is intentional, please make sure --target-arch matches", spec.Arch, c.Architecture)
}
}
containerSpecs[plName] = specs
}
containerSpecs[plName] = specs
}

var opts manifest.SerializeOptions
Expand Down Expand Up @@ -184,6 +197,48 @@ func saveManifest(ms manifest.OSBuildManifest, fpath string) (err error) {
return nil
}

func makeManifestForDisk(bootcRef, imgTypeStr, archStr string, bp blueprint.Blueprint, rootfs string, cntSize uint64) ([]byte, *mTLSConfig, error) {
imgType, err := generic.ImageFromBootc(bootcRef, imgTypeStr, archStr, rootfs)
if err != nil {
return nil, nil, err
}
img := &imagefilter.Result{imgType.Arch().Distro(), imgType.Arch(), imgType}
var buf bytes.Buffer
randSeed := randSeed()
manifestGenOpts := &manifestgen.Options{
Output: &buf,
// XXX: hack to shut up manifestgen about missing repos
OverrideRepos: []rpmmd.RepoConfig{},
// use our own randSeed helper so that we honor OSBUILD_TESTING_RNG_SEED
CustomSeed: &randSeed,
}
repos := &reporegistry.RepoRegistry{}
mg, err := manifestgen.New(repos, manifestGenOpts)
if err != nil {
return nil, nil, err
}

partitioningMode := disk.RawPartitioningMode
if rootfs == "btrfs" {
partitioningMode = disk.BtrfsPartitioningMode
}
diskSize := max(cntSize*containerSizeToDiskSizeMultiplier, img.ImgType.Size(0))

imgOpts := &distro.ImageOptions{
Bootc: &distro.BootcRef{
Imgref: &bootcRef,
// XXX: add BuildImgref
},
PartitioningMode: partitioningMode,
Size: diskSize,
}
if err := mg.Generate(&bp, img.Distro, img.ImgType, img.Arch, imgOpts); err != nil {
return nil, nil, err
}

return buf.Bytes(), nil, nil
}

// manifestFromCobra generate an osbuild manifest from a cobra commandline.
//
// It takes an unstarted progres bar and will start it at the right
Expand Down Expand Up @@ -258,10 +313,12 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress
return nil, nil, err
}

cntSize, err := getContainerSize(imgref)
if err != nil {
return nil, nil, fmt.Errorf("cannot get container size: %w", err)
}
// XXX: This is really not nice, we need to inspect the
// container to get the embedded filesystem/disk blueprint
// and then apply them . What we should have instead is a
// imageTypeYAML like thing in bootc image that fully defines the
// partition table so that we can apply a blueprint customization
// on top still.
container, err := podman_container.New(imgref)
if err != nil {
return nil, nil, err
Expand All @@ -271,6 +328,39 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress
logrus.Warnf("error stopping container: %v", err)
}
}()
sourceinfo, err := osinfo.Load(container.Root())
if err != nil {
return nil, nil, err
}
if config.Customizations == nil {
config.Customizations = &blueprint.Customizations{}
}
if config.Customizations.GetFilesystems() == nil {
config.Customizations.Filesystem = sourceinfo.ImageCustomization.GetFilesystems()
}
if p, _ := config.Customizations.GetPartitioning(); p == nil {
diskCust, err := sourceinfo.ImageCustomization.GetPartitioning()
if err != nil {
return nil, nil, err
}
config.Customizations.Disk = diskCust
}

cntSize, err := getContainerSize(imgref)
if err != nil {
return nil, nil, fmt.Errorf("cannot get container size: %w", err)
}

// For now shortcircut here and build ding "images" for anything
// that is not the iso
if !imageTypes.BuildsISO() {
return makeManifestForDisk(imgref, imgTypes[0], cntArch.String(), blueprint.Blueprint(*config), rootFs, cntSize)
}

// XXX: this is all for iso now
// XXX2: port everything we have here so that it works the
// same with the "images" library, i.e. all tests should
// pass

var rootfsType string
if rootFs != "" {
Expand All @@ -285,12 +375,6 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress
}
}

// Gather some data from the containers distro
sourceinfo, err := osinfo.Load(container.Root())
if err != nil {
return nil, nil, err
}

buildContainer := container
buildSourceinfo := sourceinfo
startedBuildContainer := false
Expand Down
49 changes: 17 additions & 32 deletions bib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/cheggaaa/pb/v3 v3.1.7
github.com/hashicorp/go-version v1.7.0
github.com/osbuild/image-builder-cli v0.0.0-20250331194259-63bb56e12db3
github.com/osbuild/images v0.164.0
github.com/osbuild/images v0.166.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.7
Expand All @@ -16,31 +16,30 @@ require (
)

require (
dario.cat/mergo v1.0.1 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/BurntSushi/toml v1.5.1-0.20250403130103-3d3abc24416a // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.9 // indirect
github.com/Microsoft/hcsshim v0.13.0 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go v1.55.7 // indirect
github.com/containerd/cgroups/v3 v3.0.5 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect
github.com/containerd/typeurl/v2 v2.2.3 // indirect
github.com/containers/common v0.63.1 // indirect
github.com/containers/image/v5 v5.35.0 // indirect
github.com/containers/common v0.64.0 // indirect
github.com/containers/image/v5 v5.36.0 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.2.1 // indirect
github.com/containers/storage v1.58.0 // indirect
github.com/containers/storage v1.59.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v28.0.4+incompatible // indirect
github.com/docker/docker v28.3.2+incompatible // indirect
github.com/docker/docker-credential-helpers v0.9.3 // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
Expand All @@ -49,16 +48,6 @@ require (
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.1 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
Expand All @@ -71,50 +60,43 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.1-0.20220621161143-b0104c826a24 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/letsencrypt/boulder v0.0.0-20240620165639-de9c06129bec // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-sqlite3 v1.14.27 // indirect
github.com/mattn/go-sqlite3 v1.14.28 // indirect
github.com/miekg/pkcs11 v1.1.1 // indirect
github.com/mistifyio/go-zfs/v3 v3.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/capability v0.4.0 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/user v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/opencontainers/runtime-spec v1.2.1 // indirect
github.com/opencontainers/selinux v1.12.0 // indirect
github.com/osbuild/blueprint v1.10.0 // indirect
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/proglottis/gpgme v0.1.4 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
github.com/sigstore/fulcio v1.6.6 // indirect
github.com/sigstore/protobuf-specs v0.4.1 // indirect
github.com/sigstore/rekor v1.3.10 // indirect
github.com/sigstore/sigstore v1.9.3 // indirect
github.com/sigstore/sigstore v1.9.5 // indirect
github.com/smallstep/pkcs7 v0.1.1 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
github.com/sylabs/sif/v2 v2.21.1 // indirect
github.com/tchap/go-patricia/v2 v2.3.2 // indirect
github.com/tchap/go-patricia/v2 v2.3.3 // indirect
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/vbatts/tar-split v0.12.1 // indirect
github.com/vbauerster/mpb/v8 v8.9.3 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
github.com/vbauerster/mpb/v8 v8.10.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
Expand All @@ -127,9 +109,12 @@ require (
golang.org/x/sys v0.34.0 // indirect
golang.org/x/term v0.33.0 // indirect
golang.org/x/text v0.27.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
google.golang.org/grpc v1.73.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250721164621-a45f3dfb1074 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250721164621-a45f3dfb1074 // indirect
google.golang.org/grpc v1.74.2 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/osbuild/images => github.com/mvo5/images v0.0.0-20250804120706-382e17c229bc
Loading
Loading