debian-forge-composer/internal/distroregistry/distroregistry.go
Achilleas Koutsou 436d8f9b43 distro/rhel86: add RHEL 8.5 variant
Define the distribution strings for RHEL 8.5 in distro/rhel86 and add
constructors.  Remove the old 8.5 from the distro registry and use the
new constructors.

Composer can now build RHEL 8.5 image-installer on aarch64, which wasn't
supported before.

RHEL 8.5 manifests have changed to minimise the differences from 8.6.
Some changes are fixes made in 8.6 but never backported to 8.5 because
of our (older) policy of not changing definitions after the release of a
distro.
Other changes are non-functional (e.g., stage or package order).

See the list below for the source of each change.

Manifest changes:
- Stage order changed for org.osbuild.systemd-logind and
  org.osbuild.rhsm.
- org.osbuild.grub2 options: config.default = "saved"
  Reverted 111cd8871f
- Partition sizes: RHEL 8.5 had extra arbitrarily sized padding for the
  header.  Now all partitions are sized to fit headers exactly.
  Original change at b7abef54e8.
- SELinux set to permissive in Anaconda.  This was changed in RHEL 8.6
  and 9.0 but never backported to 8.5.
  See a7fbe916b7.
- Installer isolevel set to 3.  Like above, this was changed in
  8.6 and 9.0.
  Original change at d8d161480e.
- Specify a remote for edge deployments.
  Original change at b18b4e80a0.
2022-06-30 11:14:21 +02:00

139 lines
4.1 KiB
Go

package distroregistry
import (
"fmt"
"sort"
"strings"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distro/fedora"
"github.com/osbuild/osbuild-composer/internal/distro/rhel7"
"github.com/osbuild/osbuild-composer/internal/distro/rhel8"
"github.com/osbuild/osbuild-composer/internal/distro/rhel84"
"github.com/osbuild/osbuild-composer/internal/distro/rhel86"
"github.com/osbuild/osbuild-composer/internal/distro/rhel90"
"github.com/osbuild/osbuild-composer/internal/distro/rhel90beta"
)
// When adding support for a new distribution, add it here.
// Note that this is a constant, do not write to this array.
var supportedDistros = []supportedDistro{
{fedora.NewF34, fedora.NewHostDistro},
{fedora.NewF35, fedora.NewHostDistro},
{fedora.NewF36, fedora.NewHostDistro},
{rhel7.New, rhel7.NewHostDistro},
{rhel8.New, rhel8.NewHostDistro},
{rhel84.New, rhel84.NewHostDistro},
{rhel86.New, rhel86.NewHostDistro},
{rhel86.NewRHEL85, rhel86.NewRHEL85HostDistro},
{rhel86.NewRHEL87, rhel86.NewRHEL87HostDistro},
{rhel86.NewCentos, rhel86.NewCentosHostDistro},
{rhel90beta.New, rhel90beta.NewHostDistro},
{rhel90.New, rhel90.NewHostDistro},
{rhel90.NewRHEL91, rhel90.NewRHEL91HostDistro},
{rhel90.NewCentos, rhel90.NewCentosHostDistro},
}
type supportedDistro struct {
defaultDistro func() distro.Distro
hostDistro func(name, modulePlatformID, ostreeRef string) distro.Distro
}
type Registry struct {
distros map[string]distro.Distro
hostDistro distro.Distro
}
func New(hostDistro distro.Distro, distros ...distro.Distro) (*Registry, error) {
reg := &Registry{
distros: make(map[string]distro.Distro),
hostDistro: hostDistro,
}
for _, d := range distros {
name := d.Name()
if _, exists := reg.distros[name]; exists {
return nil, fmt.Errorf("New: passed two distros with the same name: %s", d.Name())
}
reg.distros[name] = d
}
return reg, nil
}
// NewDefault creates a Registry with all distributions supported by
// osbuild-composer. If you need to add a distribution here, see the
// supportedDistros variable.
func NewDefault() *Registry {
var distros []distro.Distro
var hostDistro distro.Distro
// First determine the name of the Host Distro
// If there was an error, then the hostDistroName will be an empty string
// and as a result, the hostDistro will have a nil value when calling New().
// Getting the host distro later using FromHost() will return nil as well.
hostDistroName, hostDistroIsBeta, hostDistroIsStream, _ := common.GetHostDistroName()
for _, supportedDistro := range supportedDistros {
distro := supportedDistro.defaultDistro()
if distro.Name() == hostDistroName {
hostDistro = supportedDistro.hostDistro(
mangleHostDistroName(distro.Name(), hostDistroIsBeta, hostDistroIsStream),
distro.ModulePlatformID(),
distro.OSTreeRef(),
)
}
distros = append(distros, distro)
}
registry, err := New(hostDistro, distros...)
if err != nil {
panic(fmt.Sprintf("two supported distros have the same name, this is a programming error: %v", err))
}
return registry
}
func (r *Registry) GetDistro(name string) distro.Distro {
d, ok := r.distros[name]
if !ok {
return nil
}
return d
}
// List returns the names of all distros in a Registry, sorted alphabetically.
func (r *Registry) List() []string {
list := []string{}
for _, d := range r.distros {
list = append(list, d.Name())
}
sort.Strings(list)
return list
}
func mangleHostDistroName(name string, isBeta, isStream bool) string {
hostDistroName := name
if strings.HasPrefix(hostDistroName, "rhel-8") {
hostDistroName = "rhel-8"
}
if isBeta {
hostDistroName += "-beta"
}
// override repository for centos stream, remove when CentOS 8 is EOL
if isStream && hostDistroName == "centos-8" {
hostDistroName = "centos-stream-8"
}
return hostDistroName
}
// FromHost returns a distro instance, that is specific to the host.
// Its name may differ from other supported distros, if the host version
// is e.g. a Beta or a Stream.
func (r *Registry) FromHost() distro.Distro {
return r.hostDistro
}