Skip to content
Open
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
1 change: 0 additions & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ COPY ./group_osbuild-osbuild-fedora.repo /etc/yum.repos.d/
COPY ./package-requires.txt .
RUN grep -vE '^#' package-requires.txt | xargs dnf install -y && rm -f package-requires.txt && dnf clean all
COPY --from=builder /build/bin/* /usr/bin/
COPY bib/data /usr/share/bootc-image-builder

ENTRYPOINT ["/usr/bin/bootc-image-builder"]
VOLUME /output
Expand Down
10 changes: 5 additions & 5 deletions bib/cmd/bootc-image-builder/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
)

var (
CanChownInPath = canChownInPath
GetDistroAndRunner = getDistroAndRunner
CreateRand = createRand
BuildCobraCmdline = buildCobraCmdline
HandleAWSFlags = handleAWSFlags
CanChownInPath = canChownInPath
CreateRand = createRand
BuildCobraCmdline = buildCobraCmdline
HandleAWSFlags = handleAWSFlags
NewDistroYAMLFrom = newDistroYAMLFrom
)

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.

177 changes: 45 additions & 132 deletions bib/cmd/bootc-image-builder/legacy_iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package main
import (
"fmt"
"math/rand"
"slices"
"strconv"
"strings"

"github.com/osbuild/blueprint/pkg/blueprint"
"github.com/osbuild/images/pkg/arch"
Expand All @@ -15,28 +12,19 @@ import (
"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"
"github.com/osbuild/images/pkg/distro/bootc"
"github.com/osbuild/images/pkg/distro/defs"
"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"
)

// all possible locations for the bib's distro definitions
// ./data/defs and ./bib/data/defs are for development
// /usr/share/bootc-image-builder/defs is for the production, containerized version
var distroDefPaths = []string{
"./data/defs",
"./bib/data/defs",
"/usr/share/bootc-image-builder/defs",
}

type ManifestConfig struct {
// OCI image path (without the transport, that is always docker://)
Imgref string
Expand Down Expand Up @@ -134,7 +122,6 @@ func manifestFromCobraForLegacyISO(imgref, buildImgref, imgTypeStr, rootFs, rpmC
Config: config,
Imgref: imgref,
BuildImgref: buildImgref,
DistroDefPaths: distroDefPaths,
SourceInfo: sourceinfo,
BuildSourceInfo: buildSourceinfo,
RootFSType: rootfsType,
Expand Down Expand Up @@ -215,64 +202,52 @@ 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"
// newDistroYAMLFrom() returns the distroYAML for the given sourceInfo,
// if no direct match can be found it will it will use the ID_LIKE.
// This should ensure we work on every bootc image that puts a correct
// ID_LIKE= in /etc/os-release
func newDistroYAMLFrom(sourceInfo *osinfo.Info) (*defs.DistroYAML, *distro.ID, error) {
for _, distroID := range append([]string{sourceInfo.OSRelease.ID}, sourceInfo.OSRelease.IDLike...) {
nameVer := fmt.Sprintf("%s-%s", distroID, sourceInfo.OSRelease.VersionID)
id, err := distro.ParseID(nameVer)
if err != nil {
return nil, nil, err
}
distroYAML, err := defs.NewDistroYAML(nameVer)
if err != nil {
return nil, nil, err
}
if distroYAML != nil {
return distroYAML, id, nil
}
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.207.0/data/distrodefs/rhel-10/imagetypes.yaml#L169
var loraxRhelTemplates = []manifest.InstallerLoraxTemplate{
manifest.InstallerLoraxTemplate{Path: "80-rhel/runtime-postinstall.tmpl"},
manifest.InstallerLoraxTemplate{Path: "80-rhel/runtime-cleanup.tmpl", AfterDracut: true},
}

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

func loraxTemplates(si osinfo.OSRelease) []manifest.InstallerLoraxTemplate {
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"
}
return nil, nil, fmt.Errorf("cannot load distro definitions for %s-%s or any of %v", sourceInfo.OSRelease.ID, sourceInfo.OSRelease.VersionID, sourceInfo.OSRelease.IDLike)
}

func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, error) {
if c.Imgref == "" {
return nil, fmt.Errorf("pipeline: no base image defined")
}

imageDef, err := distrodef.LoadImageDef(c.DistroDefPaths, c.SourceInfo.OSRelease.ID, c.SourceInfo.OSRelease.VersionID, "anaconda-iso")
distroYAML, id, err := newDistroYAMLFrom(c.SourceInfo)
if err != nil {
return nil, err
}

// XXX: or "bootc-legacy-installer"?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or bootc-package-installer based on "image mode" vs. "package mode"... I have no preference.

installerImgTypeName := "bootc-rpm-installer"
imgType, ok := distroYAML.ImageTypes()[installerImgTypeName]
if !ok {
return nil, fmt.Errorf("cannot find image definition for %v", installerImgTypeName)
}
installerPkgSet, ok := imgType.PackageSets(*id, c.Architecture.String())["installer"]
if !ok {
return nil, fmt.Errorf("cannot find installer package set for %v", installerImgTypeName)
}
installerConfig := imgType.InstallerConfig(*id, c.Architecture.String())
if installerConfig == nil {
return nil, fmt.Errorf("empty installer config for %s", installerImgTypeName)
}

containerSource := container.SourceSpec{
Source: c.Imgref,
Name: c.Imgref,
Expand Down Expand Up @@ -305,7 +280,7 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro

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

Expand All @@ -315,11 +290,8 @@ 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.ExtraBasePackages = rpmmd.PackageSet{
Include: imageDef.Packages,
}
img.InstallerCustomizations.ISOLabel = bootc.LabelForISO(&c.SourceInfo.OSRelease, c.Architecture.String())
img.ExtraBasePackages = installerPkgSet

var customizations *blueprint.Customizations
if c.Config != nil {
Expand Down Expand Up @@ -358,8 +330,10 @@ 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 = installerConfig.LoraxTemplates
if installerConfig.LoraxTemplatePackage != nil {
img.InstallerCustomizations.LoraxTemplatePackage = *installerConfig.LoraxTemplatePackage
}

// see https://github.com/osbuild/bootc-image-builder/issues/733
img.InstallerCustomizations.ISORootfsType = manifest.SquashfsRootfs
Expand All @@ -372,7 +346,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 +355,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
}
51 changes: 51 additions & 0 deletions bib/cmd/bootc-image-builder/legacy_iso_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/osbuild/images/pkg/bib/osinfo"
"github.com/osbuild/images/pkg/distro"

main "github.com/osbuild/bootc-image-builder/bib/cmd/bootc-image-builder"
)

func TestNewDistroYAMLFromError(t *testing.T) {
si := &osinfo.Info{
OSRelease: osinfo.OSRelease{
ID: "weirdos",
VersionID: "2.71",
IDLike: []string{"waffleos", "barky"},
},
}
_, _, err := main.NewDistroYAMLFrom(si)
assert.EqualError(t, err, "cannot load distro definitions for weirdos-2.71 or any of [waffleos barky]")
}

func TestNewDistroYAMLFromDirect(t *testing.T) {
si := &osinfo.Info{
OSRelease: osinfo.OSRelease{
ID: "centos",
VersionID: "10",
},
}
distroYAML, id, err := main.NewDistroYAMLFrom(si)
assert.NoError(t, err)
assert.Equal(t, &distro.ID{Name: "centos", MajorVersion: 10, MinorVersion: -1}, id)
assert.Equal(t, "centos-10", distroYAML.Name)
}

func TestNewDistroYAMLFromFallback(t *testing.T) {
si := &osinfo.Info{
OSRelease: osinfo.OSRelease{
ID: "blmblinux",
VersionID: "9.6",
IDLike: []string{"non-existing", "rhel", "centos", "fedora"},
},
}
distroYAML, id, err := main.NewDistroYAMLFrom(si)
assert.NoError(t, err)
assert.Equal(t, &distro.ID{Name: "rhel", MajorVersion: 9, MinorVersion: 6}, id)
assert.Equal(t, "rhel-9.6", distroYAML.Name)
}
Loading
Loading