Skip to content
114 changes: 65 additions & 49 deletions cmd/image-builder/bib_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/osbuild/image-builder/pkg/customizations/kickstart"
"github.com/osbuild/image-builder/pkg/depsolvednf"
"github.com/osbuild/image-builder/pkg/disk"
"github.com/osbuild/image-builder/pkg/distro/bootc"
bootcdistro "github.com/osbuild/image-builder/pkg/distro/bootc"
"github.com/osbuild/image-builder/pkg/distro/defs"
"github.com/osbuild/image-builder/pkg/distro/generic"
"github.com/osbuild/image-builder/pkg/image"
Expand All @@ -24,7 +24,7 @@ import (
"github.com/osbuild/image-builder/pkg/platform"
"github.com/osbuild/image-builder/pkg/rpmmd"

podman_container "github.com/osbuild/image-builder/pkg/bootc"
"github.com/osbuild/image-builder/pkg/bootc"
)

// all possible locations for the bib's distro definitions
Expand Down Expand Up @@ -61,70 +61,86 @@ type ManifestConfig struct {
UseLibrepo bool
}

func manifestFromCobraForLegacyISO(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheRoot string, config *blueprint.Blueprint, useLibrepo bool, cntArch arch.Arch) ([]byte, *mTLSConfig, error) {
container, err := podman_container.NewContainer(imgref)
if err != nil {
return nil, nil, err
}
defer func() {
if err := container.Stop(); err != nil {
olog.Printf("ERROR: problem stopping container: %v", err)
func manifestForLegacyISO(imgref, buildImgref, rootFs, rpmCacheRoot string, config *blueprint.Blueprint, useLibrepo bool, cntArch arch.Arch) ([]byte, *mTLSConfig, error) {
var baseCnt, buildCnt *bootc.Container
var sourceinfo, buildSourceinfo *osinfo.Info
if buildImgref == "" {
// no build container: start the base container and also treat it as a
// build container
container, err := bootc.NewContainerWithRepos(imgref)
if err != nil {
return nil, nil, err
}
}()
defer func() {
if err := container.Stop(); err != nil {
olog.Printf("error stopping container: %v", err)
}
}()

var rootfsType string
if rootFs != "" {
rootfsType = rootFs
} else {
bic, err := container.InstallConfiguration()
baseCnt = container
buildCnt = container

sourceinfo, err = osinfo.Load(container.Root())
if err != nil {
return nil, nil, fmt.Errorf("cannot get rootfs type for container: %w", err)
}
rootfsType = bic.Filesystem.Root.Type
if rootfsType == "" {
return nil, nil, fmt.Errorf(`no default root filesystem type specified in container, please use "--rootfs" to set manually`)
return nil, nil, err
}
}
buildSourceinfo = sourceinfo

// 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
defer func() {
if startedBuildContainer {
if err := buildContainer.Stop(); err != nil {
olog.Printf("ERROR: problem stopping container: %v", err)
}
buildImgref = imgref
} else {
var err error
// separate build container: start both, but only start the build
// container with repos support
baseCnt, err = bootc.NewContainer(imgref)
if err != nil {
return nil, nil, err
}
}()
defer func() {
if err := baseCnt.Stop(); err != nil {
olog.Printf("error stopping base container: %v", err)
}
}()

if buildImgref != "" {
buildContainer, err = podman_container.NewContainer(buildImgref)
buildCnt, err = bootc.NewContainerWithRepos(buildImgref)
if err != nil {
return nil, nil, err
}
startedBuildContainer = true
defer func() {
if err := buildCnt.Stop(); err != nil {
olog.Printf("error stopping build container: %v", err)
}
}()

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

var rootfsType string
if rootFs != "" {
rootfsType = rootFs
} else {
buildImgref = imgref
bic, err := baseCnt.InstallConfiguration()
if err != nil {
return nil, nil, fmt.Errorf("cannot get rootfs type for container: %w", err)
}
rootfsType = bic.Filesystem.Root.Type
if rootfsType == "" {
return nil, nil, fmt.Errorf(`no default root filesystem type specified in container, please use "--rootfs" to set manually`)
}
}

// This is needed just for RHEL and RHSM in most cases, but let's run it every time in case
// the image has some non-standard dnf plugins.
if err := buildContainer.InitDNF(); err != nil {
if err := buildCnt.InitDNF(); err != nil {
return nil, nil, err
}
solver, err := buildContainer.NewContainerSolver(rpmCacheRoot, cntArch, sourceinfo)
solver, err := buildCnt.NewContainerSolver(rpmCacheRoot, cntArch, sourceinfo)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -302,7 +318,7 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro
if isoCust != nil && isoCust.VolumeID != "" {
img.ISOCustomizations.Label = isoCust.VolumeID
} else {
img.ISOCustomizations.Label = bootc.LabelForISO(&c.SourceInfo.OSRelease, c.Architecture.String())
img.ISOCustomizations.Label = bootcdistro.LabelForISO(&c.SourceInfo.OSRelease, c.Architecture.String())
}
img.InstallerCustomizations.FIPS = customizations.GetFIPS()
img.Kickstart, err = kickstart.New(customizations)
Expand Down Expand Up @@ -337,8 +353,8 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro
img.Kickstart.OSTree = &kickstart.OSTree{
OSName: "default",
}
img.InstallerCustomizations.LoraxTemplates = bootc.LoraxTemplates(c.SourceInfo.OSRelease)
img.InstallerCustomizations.LoraxTemplatePackage = bootc.LoraxTemplatePackage(c.SourceInfo.OSRelease)
img.InstallerCustomizations.LoraxTemplates = bootcdistro.LoraxTemplates(c.SourceInfo.OSRelease)
img.InstallerCustomizations.LoraxTemplatePackage = bootcdistro.LoraxTemplatePackage(c.SourceInfo.OSRelease)

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

mf := manifest.New()

foundDistro, foundRunner, err := bootc.GetDistroAndRunner(c.SourceInfo.OSRelease)
foundDistro, foundRunner, err := bootcdistro.GetDistroAndRunner(c.SourceInfo.OSRelease)
if err != nil {
return nil, fmt.Errorf("failed to infer distro and runner: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/image-builder/bib_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func bibManifestFromCobra(cmd *cobra.Command, args []string, pbar progress.Progr

// The anaconda-iso code is different enough for a separate function
if imgTypeStr == "anaconda-iso" || imgTypeStr == "iso" {
return manifestFromCobraForLegacyISO(imgref, buildImgref, imgTypeStr, rootFs, rpmCacheRoot, config, useLibrepo, cntArch)
return manifestForLegacyISO(imgref, buildImgref, rootFs, rpmCacheRoot, config, useLibrepo, cntArch)
}

bootcInfo, err := bootc.ResolveBootcInfo(imgref)
Expand Down
1 change: 0 additions & 1 deletion pkg/bib/container/container_test.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/bib/container/solver.go

This file was deleted.

Loading
Loading