Skip to content
Draft
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
7 changes: 3 additions & 4 deletions bib/cmd/bootc-image-builder/export_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main

var (
CanChownInPath = canChownInPath
GetDistroAndRunner = getDistroAndRunner
CreateRand = createRand
BuildCobraCmdline = buildCobraCmdline
CanChownInPath = canChownInPath
CreateRand = createRand
BuildCobraCmdline = buildCobraCmdline
)

func MockOsGetuid(new func() int) (restore func()) {
Expand Down
58 changes: 0 additions & 58 deletions bib/cmd/bootc-image-builder/image_test.go

This file was deleted.

150 changes: 12 additions & 138 deletions bib/cmd/bootc-image-builder/legacy_iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ package main
import (
"fmt"
"math/rand"
"slices"
"strconv"
"strings"

"github.com/sirupsen/logrus"

"github.com/osbuild/blueprint/pkg/blueprint"
"github.com/osbuild/images/pkg/arch"
podman_container "github.com/osbuild/images/pkg/bib/container"
"github.com/osbuild/images/pkg/bib/osinfo"
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/customizations/anaconda"
"github.com/osbuild/images/pkg/customizations/kickstart"
"github.com/osbuild/images/pkg/depsolvednf"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro/bootc"
"github.com/osbuild/images/pkg/image"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/runner"
"github.com/sirupsen/logrus"

podman_container "github.com/osbuild/images/pkg/bib/container"

"github.com/osbuild/bootc-image-builder/bib/internal/distrodef"
)
Expand Down Expand Up @@ -215,54 +212,6 @@ func makeISOManifest(c *ManifestConfig, solver *depsolvednf.Solver, cacheRoot st
return mf, depsolvedRepos, nil
}

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)
default:
return fmt.Sprintf("Container-Installer-%s", arch)
}
}

// from:https://github.com/osbuild/images/blob/v0.201.0/data/distrodefs/rhel-10/imagetypes.yaml#L169
var loraxRhelTemplates = []string{
"80-rhel/runtime-postinstall.tmpl",
"80-rhel/runtime-cleanup.tmpl",
}

// from:https://github.com/osbuild/images/blob/v0.201.0/data/distrodefs/fedora/imagetypes.yaml#L408
var loraxFedoraTemplates = []string{
"99-generic/runtime-postinstall.tmpl",
"99-generic/runtime-cleanup.tmpl",
}

func loraxTemplates(si osinfo.OSRelease) []string {
switch {
case si.ID == "rhel" || slices.Contains(si.IDLike, "rhel") || si.VersionID == "eln":
return loraxRhelTemplates
default:
return loraxFedoraTemplates
}
}

func loraxTemplatePackage(si osinfo.OSRelease) string {
switch {
case si.ID == "rhel" || slices.Contains(si.IDLike, "rhel") || si.VersionID == "eln":
return "lorax-templates-rhel"
default:
return "lorax-templates-generic"
}
}

func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, error) {
if c.Imgref == "" {
return nil, fmt.Errorf("pipeline: no base image defined")
Expand All @@ -279,33 +228,19 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro
Local: true,
}

platform := &platform.Data{
Arch: c.Architecture,
ImageFormat: platform.FORMAT_ISO,
UEFIVendor: c.SourceInfo.UEFIVendor,
}
switch c.Architecture {
case arch.ARCH_X86_64:
platform.BIOSPlatform = "i386-pc"
case arch.ARCH_AARCH64:
if c.Architecture == arch.ARCH_AARCH64 {
// aarch64 always uses UEFI, so let's enforce the vendor
if c.SourceInfo.UEFIVendor == "" {
return nil, fmt.Errorf("UEFI vendor must be set for aarch64 ISO")
}
case arch.ARCH_S390X:
platform.ZiplSupport = true
case arch.ARCH_PPC64LE:
platform.BIOSPlatform = "powerpc-ieee1275"
case arch.ARCH_RISCV64:
// nothing special needed
default:
return nil, fmt.Errorf("unsupported architecture %v", c.Architecture)
}
platformi := bootc.PlatformFor(c.Architecture.String(), c.SourceInfo.UEFIVendor)
platformi.ImageFormat = platform.FORMAT_ISO
filename := "install.iso"

// The ref is not needed and will be removed from the ctor later
// in time
img := image.NewAnacondaContainerInstaller(platform, filename, containerSource, "")
img := image.NewAnacondaContainerInstallerLegacy(platformi, filename, containerSource, "")
img.ContainerRemoveSignatures = true
img.RootfsCompression = "zstd"

Expand All @@ -315,7 +250,7 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro

img.InstallerCustomizations.Product = c.SourceInfo.OSRelease.Name
img.InstallerCustomizations.OSVersion = c.SourceInfo.OSRelease.VersionID
img.InstallerCustomizations.ISOLabel = labelForISO(&c.SourceInfo.OSRelease, &c.Architecture)
img.InstallerCustomizations.ISOLabel = bootc.LabelForISO(&c.SourceInfo.OSRelease, c.Architecture.String())

img.ExtraBasePackages = rpmmd.PackageSet{
Include: imageDef.Packages,
Expand Down Expand Up @@ -358,8 +293,8 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro
img.Kickstart.OSTree = &kickstart.OSTree{
OSName: "default",
}
img.InstallerCustomizations.LoraxTemplates = loraxTemplates(c.SourceInfo.OSRelease)
img.InstallerCustomizations.LoraxTemplatePackage = loraxTemplatePackage(c.SourceInfo.OSRelease)
img.InstallerCustomizations.LoraxTemplates = bootc.LoraxTemplates(c.SourceInfo.OSRelease)
img.InstallerCustomizations.LoraxTemplatePackage = bootc.LoraxTemplatePackage(c.SourceInfo.OSRelease)

// see https://github.com/osbuild/bootc-image-builder/issues/733
img.InstallerCustomizations.ISORootfsType = manifest.SquashfsRootfs
Expand All @@ -372,7 +307,7 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro

mf := manifest.New()

foundDistro, foundRunner, err := getDistroAndRunner(c.SourceInfo.OSRelease)
foundDistro, foundRunner, err := bootc.GetDistroAndRunner(c.SourceInfo.OSRelease)
if err != nil {
return nil, fmt.Errorf("failed to infer distro and runner: %w", err)
}
Expand All @@ -381,64 +316,3 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro
_, err = img.InstantiateManifest(&mf, nil, foundRunner, rng)
return &mf, err
}

func getDistroAndRunner(osRelease osinfo.OSRelease) (manifest.Distro, runner.Runner, error) {
switch osRelease.ID {
case "fedora":
version, err := strconv.ParseUint(osRelease.VersionID, 10, 64)
if err != nil {
return manifest.DISTRO_NULL, nil, fmt.Errorf("cannot parse Fedora version (%s): %w", osRelease.VersionID, err)
}

return manifest.DISTRO_FEDORA, &runner.Fedora{
Version: version,
}, nil
case "centos":
version, err := strconv.ParseUint(osRelease.VersionID, 10, 64)
if err != nil {
return manifest.DISTRO_NULL, nil, fmt.Errorf("cannot parse CentOS version (%s): %w", osRelease.VersionID, err)
}
r := &runner.CentOS{
Version: version,
}
switch version {
case 9:
return manifest.DISTRO_EL9, r, nil
case 10:
return manifest.DISTRO_EL10, r, nil
default:
logrus.Warnf("Unknown CentOS version %d, using default distro for manifest generation", version)
return manifest.DISTRO_NULL, r, nil
}

case "rhel":
versionParts := strings.Split(osRelease.VersionID, ".")
if len(versionParts) != 2 {
return manifest.DISTRO_NULL, nil, fmt.Errorf("invalid RHEL version format: %s", osRelease.VersionID)
}
major, err := strconv.ParseUint(versionParts[0], 10, 64)
if err != nil {
return manifest.DISTRO_NULL, nil, fmt.Errorf("cannot parse RHEL major version (%s): %w", versionParts[0], err)
}
minor, err := strconv.ParseUint(versionParts[1], 10, 64)
if err != nil {
return manifest.DISTRO_NULL, nil, fmt.Errorf("cannot parse RHEL minor version (%s): %w", versionParts[1], err)
}
r := &runner.RHEL{
Major: major,
Minor: minor,
}
switch major {
case 9:
return manifest.DISTRO_EL9, r, nil
case 10:
return manifest.DISTRO_EL10, r, nil
default:
logrus.Warnf("Unknown RHEL version %d, using default distro for manifest generation", major)
return manifest.DISTRO_NULL, r, nil
}
}

logrus.Warnf("Unknown distro %s, using default runner", osRelease.ID)
return manifest.DISTRO_NULL, &runner.Linux{}, nil
}
23 changes: 16 additions & 7 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/osbuild/images/pkg/bib/blueprintload"
"github.com/osbuild/images/pkg/cloud"
"github.com/osbuild/images/pkg/cloud/awscloud"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/distro/bootc"
"github.com/osbuild/images/pkg/experimentalflags"
"github.com/osbuild/images/pkg/manifest"
Expand Down Expand Up @@ -93,6 +94,7 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress
targetArch, _ := cmd.Flags().GetString("target-arch")
rootFs, _ := cmd.Flags().GetString("rootfs")
buildImgref, _ := cmd.Flags().GetString("build-container")
installerPayload, _ := cmd.Flags().GetString("installer-payload")
useLibrepo, _ := cmd.Flags().GetBool("use-librepo")

// If --local was given, warn in the case of --local or --local=true (true is the default), error in the case of --local=false
Expand Down Expand Up @@ -153,21 +155,21 @@ func manifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progress
if imageTypes.Legacy() {
return manifestFromCobraForLegacyISO(imgref, buildImgref, imgType, rootFs, rpmCacheRoot, config, useLibrepo, cntArch)
}
return manifestFromCobraForDisk(imgref, buildImgref, imgType, rootFs, rpmCacheRoot, config, useLibrepo, cntArch)
return manifestFromCobraFor(imgref, buildImgref, installerPayload, imgType, rootFs, rpmCacheRoot, config, useLibrepo, cntArch)
}

func manifestFromCobraForDisk(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheRoot string, config *blueprint.Blueprint, useLibrepo bool, cntArch arch.Arch) ([]byte, *mTLSConfig, error) {
distro, err := bootc.NewBootcDistro(imgref)
func manifestFromCobraFor(imgref, buildImgref, installerPayload, imgTypeStr, rootFs, rpmCacheRoot string, config *blueprint.Blueprint, useLibrepo bool, cntArch arch.Arch) ([]byte, *mTLSConfig, error) {
distri, err := bootc.NewBootcDistro(imgref)
if err != nil {
return nil, nil, err
}
if err := distro.SetBuildContainer(buildImgref); err != nil {
if err := distri.SetBuildContainer(buildImgref); err != nil {
return nil, nil, err
}
if err := distro.SetDefaultFs(rootFs); err != nil {
if err := distri.SetDefaultFs(rootFs); err != nil {
return nil, nil, err
}
archi, err := distro.GetArch(cntArch.String())
archi, err := distri.GetArch(cntArch.String())
if err != nil {
return nil, nil, err
}
Expand All @@ -180,6 +182,7 @@ func manifestFromCobraForDisk(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheR
if err != nil {
return nil, nil, err
}

mg, err := manifestgen.New(repos, &manifestgen.Options{
// XXX: hack to skip repo loading for the bootc image.
// We need to add a SkipRepositories or similar to
Expand All @@ -193,7 +196,12 @@ func manifestFromCobraForDisk(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheR
if err != nil {
return nil, nil, err
}
manifest, err := mg.Generate(config, imgType, nil)
imgOptions := &distro.ImageOptions{
Bootc: &distro.BootcImageOptions{
InstallerPayloadRef: installerPayload,
},
}
manifest, err := mg.Generate(config, imgType, imgOptions)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -504,6 +512,7 @@ func buildCobraCmdline() (*cobra.Command, error) {
manifestCmd.Flags().String("rpmmd", "/rpmmd", "rpm metadata cache directory")
manifestCmd.Flags().String("target-arch", "", "build for the given target architecture (experimental)")
manifestCmd.Flags().String("build-container", "", "Use a custom container for the image build")
manifestCmd.Flags().String("installer-payload", "", "Use this container for the installer payload")
manifestCmd.Flags().StringArray("type", []string{"qcow2"}, fmt.Sprintf("image types to build [%s]", imagetypes.Available()))
manifestCmd.Flags().Bool("local", true, "DEPRECATED: --local is now the default behavior, make sure to pull the container image before running bootc-image-builder")
if err := manifestCmd.Flags().MarkHidden("local"); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions bib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ require (
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

replace github.com/osbuild/images => github.com/mvo5/images v0.0.0-20251009122100-a281674e76f1
4 changes: 2 additions & 2 deletions bib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mvo5/images v0.0.0-20251009122100-a281674e76f1 h1:2v+jNx7H4oI9jq93vkBYJVwVenWpQn6bS+njMKZeK1k=
github.com/mvo5/images v0.0.0-20251009122100-a281674e76f1/go.mod h1:xkXfw5CIy0bVNTNdB6GXiewu/IzBgpofkItDJPAzGA4=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
Expand All @@ -245,8 +247,6 @@ github.com/osbuild/blueprint v1.16.0 h1:f/kHih+xpeJ1v7wtIfzdHPZTsiXsqKeDQ1+rrue6
github.com/osbuild/blueprint v1.16.0/go.mod h1:HPlJzkEl7q5g8hzaGksUk7ifFAy9QFw9LmzhuFOAVm4=
github.com/osbuild/image-builder-cli v0.0.0-20250924085931-15de5139f521 h1:Mo1htXYyEoKrBQD+/RC/kluAWu4+E0oEjPorujVn/K8=
github.com/osbuild/image-builder-cli v0.0.0-20250924085931-15de5139f521/go.mod h1:oTn9T+bV9g/760hM/jX7AV0c4vuVIn6FjAnaVM9RzRo=
github.com/osbuild/images v0.202.0 h1:OPvfmr5RJHcOJgU8Win6kHyoCNQZEiILlgIDI64/YIM=
github.com/osbuild/images v0.202.0/go.mod h1:xkXfw5CIy0bVNTNdB6GXiewu/IzBgpofkItDJPAzGA4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
2 changes: 2 additions & 0 deletions bib/internal/imagetypes/imagetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var supportedImageTypes = map[string]imageType{
"vmdk": imageType{Export: "vmdk"},
"vhd": imageType{Export: "vpc"},
"gce": imageType{Export: "gce"},
// new images bootc-installer type
"bootc-installer": imageType{Export: "bootiso", ISO: true},
// the iso image types are RPM based and legacy/deprecated
"anaconda-iso": imageType{Export: "bootiso", ISO: true, Legacy: true},
"iso": imageType{Export: "bootiso", ISO: true, Legacy: true},
Expand Down
Loading
Loading