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
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.

178 changes: 44 additions & 134 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 All @@ -48,9 +36,6 @@ type ManifestConfig struct {
// CPU architecture of the image
Architecture arch.Arch

// Paths to the directory with the distro definitions
DistroDefPaths []string

// Extracted information about the source container image
SourceInfo *osinfo.Info
BuildSourceInfo *osinfo.Info
Expand Down Expand Up @@ -134,7 +119,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 +199,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.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer bootc-package-installer to bootc-rpm-installer. But I think legacy might be clearer here as something we want people to start moving away from.

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 @@ -315,11 +287,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 +327,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 +343,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 +352,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