deps: update images to 0.99

This commit is contained in:
Lukas Zapletal 2024-11-20 08:31:59 +01:00 committed by Sanne Raymaekers
parent b5c71cd7e2
commit ff2660ef00
29 changed files with 465 additions and 117 deletions

2
go.mod
View file

@ -46,7 +46,7 @@ require (
github.com/labstack/gommon v0.4.2
github.com/openshift-online/ocm-sdk-go v0.1.438
github.com/oracle/oci-go-sdk/v54 v54.0.0
github.com/osbuild/images v0.96.0
github.com/osbuild/images v0.99.0
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d
github.com/osbuild/pulp-client v0.1.0
github.com/prometheus/client_golang v1.20.2

4
go.sum
View file

@ -534,8 +534,8 @@ github.com/openshift-online/ocm-sdk-go v0.1.438 h1:tsLCCUzbLCTL4RZG02y9RuopmGCXp
github.com/openshift-online/ocm-sdk-go v0.1.438/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
github.com/oracle/oci-go-sdk/v54 v54.0.0 h1:CDLjeSejv2aDpElAJrhKpi6zvT/zhZCZuXchUUZ+LS4=
github.com/oracle/oci-go-sdk/v54 v54.0.0/go.mod h1:+t+yvcFGVp+3ZnztnyxqXfQDsMlq8U25faBLa+mqCMc=
github.com/osbuild/images v0.96.0 h1:ZieK4i5pyKTdLaA/EwxeNEQsWBLEkX3FsZVyIaYCJKI=
github.com/osbuild/images v0.96.0/go.mod h1:4bNmMQOVadIKVC1q8zsLO8tdEQFH90zIp+MQBQUnCiE=
github.com/osbuild/images v0.99.0 h1:+L1Di9oP8bK0faYM/Zb2VmxYfFHJq4XWU4KH36e7wkY=
github.com/osbuild/images v0.99.0/go.mod h1:4bNmMQOVadIKVC1q8zsLO8tdEQFH90zIp+MQBQUnCiE=
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d h1:r9BFPDv0uuA9k1947Jybcxs36c/pTywWS1gjeizvtcQ=
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d/go.mod h1:zR1iu/hOuf+OQNJlk70tju9IqzzM4ycq0ectkFBm94U=
github.com/osbuild/pulp-client v0.1.0 h1:L0C4ezBJGTamN3BKdv+rKLuq/WxXJbsFwz/Hj7aEmJ8=

View file

@ -15,7 +15,10 @@ type FilesystemCustomization struct {
}
func (fsc *FilesystemCustomization) UnmarshalTOML(data interface{}) error {
d, _ := data.(map[string]interface{})
d, ok := data.(map[string]interface{})
if !ok {
return fmt.Errorf("customizations.filesystem is not an object")
}
switch d["mountpoint"].(type) {
case string:

View file

@ -19,6 +19,7 @@ package disk
import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"math/rand"
@ -60,6 +61,15 @@ const (
// DosFat16B used for the ESP-System partition
DosFat16B = "06"
// Partition type ID for any native Linux filesystem on dos
DosLinuxTypeID = "83"
// Partition type ID for BIOS boot partition on dos
DosBIOSBootID = "ef02"
// Partition type ID for ESP on dos
DosESPID = "ef00"
)
// FSType is the filesystem type enum.
@ -110,6 +120,59 @@ func NewFSType(s string) (FSType, error) {
}
}
// PartitionTableType is the partition table type enum.
type PartitionTableType uint64
const (
PT_NONE PartitionTableType = iota
PT_DOS
PT_GPT
)
func (t PartitionTableType) String() string {
switch t {
case PT_NONE:
return ""
case PT_DOS:
return "dos"
case PT_GPT:
return "gpt"
default:
panic(fmt.Sprintf("unknown or unsupported partition table type with enum value %d", t))
}
}
func (t PartitionTableType) MarshalJSON() ([]byte, error) {
return json.Marshal(t.String())
}
func (t *PartitionTableType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
new, err := NewPartitionTableType(s)
if err != nil {
return err
}
*t = new
return nil
}
func NewPartitionTableType(s string) (PartitionTableType, error) {
switch s {
case "":
return PT_NONE, nil
case "dos":
return PT_DOS, nil
case "gpt":
return PT_GPT, nil
default:
return PT_NONE, fmt.Errorf("unknown or unsupported partition table type name: %s", s)
}
}
// Entity is the base interface for all disk-related entities.
type Entity interface {
// Clone returns a deep copy of the entity.

View file

@ -9,12 +9,13 @@ import (
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/platform"
)
type PartitionTable struct {
Size uint64 // Size of the disk (in bytes).
UUID string // Unique identifier of the partition table (GPT only).
Type string // Partition table type, e.g. dos, gpt.
Size uint64 // Size of the disk (in bytes).
UUID string // Unique identifier of the partition table (GPT only).
Type PartitionTableType // Partition table type, e.g. dos, gpt.
Partitions []Partition
SectorSize uint64 // Sector size in bytes
@ -58,18 +59,17 @@ const (
//
// Partitioning modes: The mode controls how the partition table is modified.
//
// - Raw will not convert any partition to LVM or Btrfs.
// - Raw will not convert any partition to LVM or Btrfs.
// - LVM will convert the partition that contains the root mountpoint '/' to an
//
// - LVM will convert the partition that contains the root mountpoint '/' to an
// LVM Volume Group and create a root Logical Volume. Any extra mountpoints,
// except /boot, will be added to the Volume Group as new Logical Volumes.
//
// - Btrfs will convert the partition that contains the root mountpoint '/' to
// a Btrfs volume and create a root subvolume. Any extra mountpoints, except
// /boot, will be added to the Btrfs volume as new Btrfs subvolumes.
//
// - AutoLVM is the default mode and will convert a raw partition table to an
// LVM-based one if and only if new mountpoints are added.
// - Btrfs will convert the partition that contains the root mountpoint '/' to
// a Btrfs volume and create a root subvolume. Any extra mountpoints, except
// /boot, will be added to the Btrfs volume as new Btrfs subvolumes.
// - AutoLVM is the default mode and will convert a raw partition table to an
// LVM-based one if and only if new mountpoints are added.
//
// Directory sizes: The requiredSizes argument defines a map of minimum sizes
// for specific directories. These indirectly control the minimum sizes of
@ -82,7 +82,7 @@ const (
// most cases, this translates to a requirement of 3 GiB for the root
// partition, Logical Volume, or Btrfs subvolume.
//
// General principles:
// # General principles:
//
// Desired sizes for partitions, partition tables, volumes, directories, etc,
// are always treated as minimum sizes. This means that very often the full
@ -243,7 +243,7 @@ func (pt *PartitionTable) GenerateUUIDs(rng *rand.Rand) {
// if this is a MBR partition table, there is no need to generate
// uuids for the partitions themselves
if pt.Type != "gpt" {
if pt.Type != PT_GPT {
return
}
@ -339,7 +339,7 @@ func (pt *PartitionTable) CreateMountpoint(mountpoint string, size uint64) (Enti
n := len(pt.Partitions)
var maxNo int
if pt.Type == "gpt" {
if pt.Type == PT_GPT {
switch mountpoint {
case "/boot":
partition.Type = XBootLDRPartitionGUID
@ -398,7 +398,7 @@ func (pt *PartitionTable) HeaderSize() uint64 {
// this also ensure we have enough space for the MBR
header := pt.SectorsToBytes(1)
if pt.Type == "dos" {
if pt.Type == PT_DOS {
return header
}
@ -454,7 +454,7 @@ func (pt *PartitionTable) relayout(size uint64) uint64 {
footer := uint64(0)
// The GPT header is also at the end of the partition table
if pt.Type == "gpt" {
if pt.Type == PT_GPT {
footer = header
}
@ -726,7 +726,7 @@ func (pt *PartitionTable) ensureLVM() error {
// reset the vg partition size - it will be grown later
part.Size = 0
if pt.Type == "gpt" {
if pt.Type == PT_GPT {
part.Type = LVMPartitionGUID
} else {
part.Type = "8e"
@ -773,6 +773,7 @@ func (pt *PartitionTable) ensureBtrfs() error {
if err != nil {
return err
}
btrfs := &Btrfs{
Label: "root",
Subvolumes: []BtrfsSubvolume{
@ -792,10 +793,10 @@ func (pt *PartitionTable) ensureBtrfs() error {
// reset the btrfs partition size - it will be grown later
part.Size = 0
if pt.Type == "gpt" {
if pt.Type == PT_GPT {
part.Type = FilesystemDataGUID
} else {
part.Type = "83"
part.Type = DosLinuxTypeID
}
} else {
@ -894,3 +895,252 @@ func (pt *PartitionTable) GetMountpointSize(mountpoint string) (uint64, error) {
panic(fmt.Sprintf("no sizeable of the entity path for mountpoint %s, this is a programming error", mountpoint))
}
// EnsureRootFilesystem adds a root filesystem if the partition table doesn't
// already have one.
//
// When adding the root filesystem, add it to:
//
// - The first LVM Volume Group if one exists, otherwise
// - The first Btrfs volume if one exists, otherwise
// - At the end of the plain partitions.
//
// For LVM and Plain, the fsType argument must be a valid filesystem type.
func EnsureRootFilesystem(pt *PartitionTable, defaultFsType FSType) error {
// collect all labels and subvolume names to avoid conflicts
subvolNames := make(map[string]bool)
labels := make(map[string]bool)
var foundRoot bool
_ = pt.ForEachMountable(func(mnt Mountable, path []Entity) error {
if mnt.GetMountpoint() == "/" {
foundRoot = true
return nil
}
labels[mnt.GetFSSpec().Label] = true
switch mountable := mnt.(type) {
case *BtrfsSubvolume:
subvolNames[mountable.Name] = true
}
return nil
})
if foundRoot {
// nothing to do
return nil
}
for _, part := range pt.Partitions {
switch payload := part.Payload.(type) {
case *LVMVolumeGroup:
if defaultFsType == FS_NONE {
return fmt.Errorf("error creating root logical volume: no default filesystem type")
}
rootLabel, err := genUniqueString("root", labels)
if err != nil {
return fmt.Errorf("error creating root logical volume: %w", err)
}
rootfs := &Filesystem{
Type: defaultFsType.String(),
Label: rootLabel,
Mountpoint: "/",
FSTabOptions: "defaults",
}
// Let the function autogenerate the name to avoid conflicts
// with LV names from customizations.
// Set the size to 0 and it will be adjusted by
// EnsureDirectorySizes() and relayout().
if _, err := payload.CreateLogicalVolume("", 0, rootfs); err != nil {
return fmt.Errorf("error creating root logical volume: %w", err)
}
return nil
case *Btrfs:
rootName, err := genUniqueString("root", subvolNames)
if err != nil {
return fmt.Errorf("error creating root subvolume: %w", err)
}
rootsubvol := BtrfsSubvolume{
Name: rootName,
Mountpoint: "/",
}
payload.Subvolumes = append(payload.Subvolumes, rootsubvol)
return nil
}
}
// We're going to create a root partition, so we have to ensure the default type is set.
if defaultFsType == FS_NONE {
return fmt.Errorf("error creating root partition: no default filesystem type")
}
// add a plain root partition at the end of the partition table
rootLabel, err := genUniqueString("root", labels)
if err != nil {
return fmt.Errorf("error creating root partition: %w", err)
}
var partType string
switch pt.Type {
case PT_DOS:
partType = DosLinuxTypeID
case PT_GPT:
partType = FilesystemDataGUID
default:
return fmt.Errorf("error creating root partition: unknown or unsupported partition table type: %s", pt.Type)
}
rootpart := Partition{
Type: partType,
Size: 0, // Set the size to 0 and it will be adjusted by EnsureDirectorySizes() and relayout()
Payload: &Filesystem{
Type: defaultFsType.String(),
Label: rootLabel,
Mountpoint: "/",
FSTabOptions: "defaults",
},
}
pt.Partitions = append(pt.Partitions, rootpart)
return nil
}
// EnsureBootPartition creates a boot partition if one does not already exist.
// The function will append the boot partition to the end of the existing
// partition table therefore it is best to call this function early to put boot
// near the front (as is conventional).
func EnsureBootPartition(pt *PartitionTable, bootFsType FSType) error {
// collect all labels to avoid conflicts
labels := make(map[string]bool)
var foundBoot bool
_ = pt.ForEachMountable(func(mnt Mountable, path []Entity) error {
if mnt.GetMountpoint() == "/boot" {
foundBoot = true
return nil
}
labels[mnt.GetFSSpec().Label] = true
return nil
})
if foundBoot {
// nothing to do
return nil
}
if bootFsType == FS_NONE {
return fmt.Errorf("error creating boot partition: no filesystem type")
}
bootLabel, err := genUniqueString("boot", labels)
if err != nil {
return fmt.Errorf("error creating boot partition: %w", err)
}
var partType string
switch pt.Type {
case PT_DOS:
partType = DosLinuxTypeID
case PT_GPT:
partType = XBootLDRPartitionGUID
default:
return fmt.Errorf("error creating boot partition: unknown or unsupported partition table type: %s", pt.Type)
}
bootPart := Partition{
Type: partType,
Size: 512 * datasizes.MiB,
Payload: &Filesystem{
Type: bootFsType.String(),
Label: bootLabel,
Mountpoint: "/boot",
FSTabOptions: "defaults",
},
}
pt.Partitions = append(pt.Partitions, bootPart)
return nil
}
// AddPartitionsForBootMode creates partitions to satisfy the boot mode requirements:
// - BIOS/legacy: adds a 1 MiB BIOS boot partition.
// - UEFI: adds a 200 MiB EFI system partition.
// - Hybrid: adds both.
//
// The function will append the new partitions to the end of the existing
// partition table therefore it is best to call this function early to put them
// near the front (as is conventional).
func AddPartitionsForBootMode(pt *PartitionTable, bootMode platform.BootMode) error {
switch bootMode {
case platform.BOOT_LEGACY:
// add BIOS boot partition
part, err := mkBIOSBoot(pt.Type)
if err != nil {
return err
}
pt.Partitions = append(pt.Partitions, part)
return nil
case platform.BOOT_UEFI:
// add ESP
part, err := mkESP(200*datasizes.MiB, pt.Type)
if err != nil {
return err
}
pt.Partitions = append(pt.Partitions, part)
return nil
case platform.BOOT_HYBRID:
// add both
bios, err := mkBIOSBoot(pt.Type)
if err != nil {
return err
}
esp, err := mkESP(200*datasizes.MiB, pt.Type)
if err != nil {
return err
}
pt.Partitions = append(pt.Partitions, bios, esp)
return nil
case platform.BOOT_NONE:
return nil
default:
return fmt.Errorf("unknown or unsupported boot mode type with enum value %d", bootMode)
}
}
func mkBIOSBoot(ptType PartitionTableType) (Partition, error) {
var partType string
switch ptType {
case PT_DOS:
partType = DosBIOSBootID
case PT_GPT:
partType = BIOSBootPartitionGUID
default:
return Partition{}, fmt.Errorf("error creating BIOS boot partition: unknown or unsupported partition table enum: %d", ptType)
}
return Partition{
Size: 1 * datasizes.MiB,
Bootable: true,
Type: partType,
UUID: BIOSBootPartitionUUID,
}, nil
}
func mkESP(size uint64, ptType PartitionTableType) (Partition, error) {
var partType string
switch ptType {
case PT_DOS:
partType = DosESPID
case PT_GPT:
partType = EFISystemPartitionGUID
default:
return Partition{}, fmt.Errorf("error creating EFI system partition: unknown or unsupported partition table enum: %d", ptType)
}
return Partition{
Size: size,
Type: partType,
UUID: EFISystemPartitionUUID,
Payload: &Filesystem{
Type: "vfat",
UUID: EFIFilesystemUUID,
Mountpoint: "/boot/efi",
Label: "EFI-SYSTEM",
FSTabOptions: "defaults,uid=0,gid=0,umask=077,shortname=winnt",
FSTabFreq: 0,
FSTabPassNo: 2,
},
}, nil
}

View file

@ -98,7 +98,7 @@ type ImageType interface {
// Returns the corresponding partion type ("gpt", "dos") or "" the image type
// has no partition table. Only support for RHEL 8.5+
PartitionType() string
PartitionType() disk.PartitionTableType
// Returns the corresponding boot mode ("legacy", "uefi", "hybrid") or "none"
BootMode() platform.BootMode

View file

@ -173,10 +173,10 @@ func (t *imageType) getDefaultImageConfig() *distro.ImageConfig {
}
func (t *imageType) PartitionType() string {
func (t *imageType) PartitionType() disk.PartitionTableType {
basePartitionTable, exists := t.basePartitionTables[t.arch.Name()]
if !exists {
return ""
return disk.PT_NONE
}
return basePartitionTable.Type

View file

@ -354,7 +354,7 @@ func anacondaPackageSet(t *imageType) rpmmd.PackageSet {
"alsa-tools-firmware",
"anaconda",
"anaconda-dracut",
"anaconda-install-env-deps",
"anaconda-install-img-deps",
"anaconda-widgets",
"atheros-firmware",
"audit",

View file

@ -10,7 +10,7 @@ import (
var defaultBasePartitionTables = distro.BasePartitionTableMap{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -62,7 +62,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
},
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 200 * datasizes.MebiByte,
@ -108,7 +108,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
},
arch.ARCH_PPC64LE.String(): disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: 4 * datasizes.MebiByte,
@ -141,7 +141,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
arch.ARCH_S390X.String(): disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: 500 * datasizes.MebiByte,
@ -172,7 +172,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
var minimalrawPartitionTables = distro.BasePartitionTableMap{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
StartOffset: 8 * datasizes.MebiByte,
Partitions: []disk.Partition{
{
@ -219,7 +219,7 @@ var minimalrawPartitionTables = distro.BasePartitionTableMap{
},
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "0xc1748067",
Type: "dos",
Type: disk.PT_DOS,
StartOffset: 8 * datasizes.MebiByte,
Partitions: []disk.Partition{
{
@ -238,7 +238,7 @@ var minimalrawPartitionTables = distro.BasePartitionTableMap{
},
{
Size: 1 * datasizes.GibiByte,
Type: "83",
Type: disk.DosLinuxTypeID,
Payload: &disk.Filesystem{
Type: "ext4",
Mountpoint: "/boot",
@ -250,7 +250,7 @@ var minimalrawPartitionTables = distro.BasePartitionTableMap{
},
{
Size: 2 * datasizes.GibiByte,
Type: "83",
Type: disk.DosLinuxTypeID,
Payload: &disk.Filesystem{
Type: "ext4",
Label: "root",
@ -267,7 +267,7 @@ var minimalrawPartitionTables = distro.BasePartitionTableMap{
var iotBasePartitionTables = distro.BasePartitionTableMap{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
StartOffset: 8 * datasizes.MebiByte,
Partitions: []disk.Partition{
{
@ -314,7 +314,7 @@ var iotBasePartitionTables = distro.BasePartitionTableMap{
},
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "0xc1748067",
Type: "dos",
Type: disk.PT_DOS,
StartOffset: 8 * datasizes.MebiByte,
Partitions: []disk.Partition{
{
@ -333,7 +333,7 @@ var iotBasePartitionTables = distro.BasePartitionTableMap{
},
{
Size: 1 * datasizes.GibiByte,
Type: "83",
Type: disk.DosLinuxTypeID,
Payload: &disk.Filesystem{
Type: "ext4",
Mountpoint: "/boot",
@ -345,7 +345,7 @@ var iotBasePartitionTables = distro.BasePartitionTableMap{
},
{
Size: 2569 * datasizes.MebiByte,
Type: "83",
Type: disk.DosLinuxTypeID,
Payload: &disk.Filesystem{
Type: "ext4",
Label: "root",
@ -362,7 +362,7 @@ var iotBasePartitionTables = distro.BasePartitionTableMap{
var iotSimplifiedInstallerPartitionTables = distro.BasePartitionTableMap{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 501 * datasizes.MebiByte,
@ -432,7 +432,7 @@ var iotSimplifiedInstallerPartitionTables = distro.BasePartitionTableMap{
},
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 501 * datasizes.MebiByte,

View file

@ -4,6 +4,8 @@ import (
"fmt"
"strconv"
"strings"
"github.com/hashicorp/go-version"
)
// ID represents a distro name and version
@ -14,12 +16,20 @@ type ID struct {
MinorVersion int
}
func (id ID) String() string {
func (id ID) versionString() string {
if id.MinorVersion == -1 {
return fmt.Sprintf("%s-%d", id.Name, id.MajorVersion)
return fmt.Sprintf("%d", id.MajorVersion)
} else {
return fmt.Sprintf("%d.%d", id.MajorVersion, id.MinorVersion)
}
}
return fmt.Sprintf("%s-%d.%d", id.Name, id.MajorVersion, id.MinorVersion)
func (id ID) String() string {
return fmt.Sprintf("%s-%s", id.Name, id.versionString())
}
func (id ID) Version() (*version.Version, error) {
return version.NewVersion(id.versionString())
}
type ParseError struct {

View file

@ -215,10 +215,14 @@ func (t *ImageType) getDefaultInstallerConfig() (*distro.InstallerConfig, error)
return t.DefaultInstallerConfig, nil
}
func (t *ImageType) PartitionType() string {
func (t *ImageType) PartitionType() disk.PartitionTableType {
if t.BasePartitionTables == nil {
return disk.PT_NONE
}
basePartitionTable, exists := t.BasePartitionTables(t)
if !exists {
return ""
return disk.PT_NONE
}
return basePartitionTable.Type

View file

@ -12,7 +12,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -52,7 +52,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 200 * datasizes.MebiByte,
@ -86,7 +86,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_PPC64LE.String():
return disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: 4 * datasizes.MebiByte,
@ -109,7 +109,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_S390X.String():
return disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: 2 * datasizes.GibiByte,

View file

@ -259,7 +259,7 @@ func ec2PartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Size: 10 * datasizes.GibiByte,
Partitions: []disk.Partition{
{

View file

@ -286,7 +286,7 @@ func azureRhuiBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool)
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Size: 64 * datasizes.GibiByte,
Partitions: []disk.Partition{
{

View file

@ -12,7 +12,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,

View file

@ -287,7 +287,7 @@ func azureRhuiBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool)
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Size: 64 * datasizes.GibiByte,
Partitions: []disk.Partition{
{
@ -397,7 +397,7 @@ func azureRhuiBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool)
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Size: 64 * datasizes.GibiByte,
Partitions: []disk.Partition{
{

View file

@ -13,7 +13,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -53,7 +53,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 100 * datasizes.MebiByte,
@ -87,7 +87,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_PPC64LE.String():
return disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: 4 * datasizes.MebiByte,
@ -110,7 +110,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_S390X.String():
return disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: 2 * datasizes.GibiByte,
@ -136,7 +136,7 @@ func edgeBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -205,7 +205,7 @@ func edgeBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 127 * datasizes.MebiByte,
@ -283,7 +283,7 @@ func ec2PartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
x86PartitionTable := disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -323,7 +323,7 @@ func ec2PartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
if common.VersionLessThan(t.Arch().Distro().OsVersion(), "8.9") && t.IsRHEL() {
x86PartitionTable = disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -355,7 +355,7 @@ func ec2PartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 200 * datasizes.MebiByte,

View file

@ -196,7 +196,7 @@ func azureInternalBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, b
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Size: 64 * datasizes.GibiByte,
Partitions: []disk.Partition{
{
@ -305,7 +305,7 @@ func azureInternalBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, b
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Size: 64 * datasizes.GibiByte,
Partitions: []disk.Partition{
{

View file

@ -373,7 +373,7 @@ func minimalrawPartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
StartOffset: 8 * datasizes.MebiByte,
Partitions: []disk.Partition{
{
@ -421,7 +421,7 @@ func minimalrawPartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
StartOffset: 8 * datasizes.MebiByte,
Partitions: []disk.Partition{
{
@ -476,7 +476,7 @@ func edgeBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -553,7 +553,7 @@ func edgeBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 127 * datasizes.MebiByte,

View file

@ -26,7 +26,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_X86_64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 1 * datasizes.MebiByte,
@ -79,7 +79,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_AARCH64.String():
return disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Type: disk.PT_GPT,
Partitions: []disk.Partition{
{
Size: 200 * datasizes.MebiByte,
@ -126,7 +126,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_PPC64LE.String():
return disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: 4 * datasizes.MebiByte,
@ -160,7 +160,7 @@ func defaultBasePartitionTables(t *rhel.ImageType) (disk.PartitionTable, bool) {
case arch.ARCH_S390X.String():
return disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Type: disk.PT_DOS,
Partitions: []disk.Partition{
{
Size: bootSize,

View file

@ -6,6 +6,7 @@ import (
"sort"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/ostree"
@ -207,8 +208,8 @@ func (t *TestImageType) Size(size uint64) uint64 {
return size
}
func (t *TestImageType) PartitionType() string {
return ""
func (t *TestImageType) PartitionType() disk.PartitionTableType {
return disk.PT_NONE
}
func (t *TestImageType) BootMode() platform.BootMode {

View file

@ -161,6 +161,7 @@ type DepsolveResult struct {
Packages []rpmmd.PackageSpec
Repos []rpmmd.RepoConfig
SBOM *sbom.Document
Solver string
}
// Create a new Solver with the given configuration. Initialising a Solver also loads system subscription information.
@ -244,6 +245,7 @@ func (s *Solver) Depsolve(pkgSets []rpmmd.PackageSet, sbomType sbom.StandardType
Packages: packages,
Repos: repos,
SBOM: sbomDoc,
Solver: result.Solver,
}, nil
}

View file

@ -22,7 +22,7 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *SfdiskStageOptions {
}
}
stageOptions := &SfdiskStageOptions{
Label: pt.Type,
Label: pt.Type.String(),
UUID: pt.UUID,
Partitions: partitions,
}

View file

@ -143,13 +143,13 @@ func NewGrub2InstStageOption(filename string, pt *disk.PartitionTable, platform
}
core := CoreMkImage{
Type: "mkimage",
PartLabel: pt.Type,
PartLabel: pt.Type.String(),
Filesystem: bootPayload.GetFSType(),
}
prefix := PrefixPartition{
Type: "partition",
PartLabel: pt.Type,
PartLabel: pt.Type.String(),
// bootidx can't be negative after check with rootIdx above:
// nolint:gosec
Number: uint(bootIdx),

View file

@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
@ -158,20 +159,16 @@ func resolveRef(ss SourceSpec) (string, error) {
if err != nil {
return "", NewResolveRefError("error parsing ostree repository location: %v", err)
}
u.Path = path.Join(u.Path, "refs/heads/", ss.Ref)
u.Path = path.Join(u.Path, "refs", "heads", ss.Ref)
transport := http.DefaultTransport.(*http.Transport).Clone()
client := &http.Client{
Transport: transport,
Timeout: 300 * time.Second,
}
if u.Scheme == "https" {
tlsConf := &tls.Config{
MinVersion: tls.VersionTLS12,
}
// If CA is set, load the CA certificate and add it to the TLS configuration. Otherwise, use the system CA.
if ss.MTLS.CA != "" {
if ss.MTLS != nil && ss.MTLS.CA != "" {
caCertPEM, err := os.ReadFile(ss.MTLS.CA)
if err != nil {
return "", NewResolveRefError("error adding ca certificate when resolving ref: %s", err)
@ -182,7 +179,7 @@ func resolveRef(ss SourceSpec) (string, error) {
}
}
if ss.MTLS.ClientCert != "" && ss.MTLS.ClientKey != "" {
if ss.MTLS != nil && ss.MTLS.ClientCert != "" && ss.MTLS.ClientKey != "" {
cert, err := tls.LoadX509KeyPair(ss.MTLS.ClientCert, ss.MTLS.ClientKey)
if err != nil {
return "", NewResolveRefError("error adding client certificate when resolving ref: %s", err)
@ -194,9 +191,24 @@ func resolveRef(ss SourceSpec) (string, error) {
}
if ss.Proxy != "" {
transport.Proxy = func(request *http.Request) (*url.URL, error) {
return url.Parse(ss.Proxy)
host, port, err := net.SplitHostPort(ss.Proxy)
if err != nil {
return "", NewResolveRefError("error parsing MTLS proxy URL '%s': %v", ss.URL, err)
}
proxyURL, err := url.Parse("http://" + host + ":" + port)
if err != nil {
return "", NewResolveRefError("error parsing MTLS proxy URL '%s': %v", ss.URL, err)
}
transport.Proxy = func(request *http.Request) (*url.URL, error) {
return proxyURL, nil
}
}
client := &http.Client{
Transport: transport,
Timeout: 300 * time.Second,
}
req, err := http.NewRequest(http.MethodGet, u.String(), nil)

View file

@ -2,8 +2,6 @@ package reporegistry
import (
"fmt"
"path/filepath"
"runtime"
"github.com/osbuild/images/pkg/distroidparser"
"github.com/osbuild/images/pkg/rpmmd"
@ -27,19 +25,6 @@ func New(repoConfigPaths []string) (*RepoRegistry, error) {
return &RepoRegistry{repositories}, nil
}
// NewTestedDefault returns a new RepoRegistry instance with the data
// loaded from the default test repositories
func NewTestedDefault() (*RepoRegistry, error) {
_, callerSrc, _, ok := runtime.Caller(0)
var testReposPath []string
if !ok {
testReposPath = append(testReposPath, "../../test/data")
} else {
testReposPath = append(testReposPath, filepath.Join(filepath.Dir(callerSrc), "../../test/data"))
}
return New(testReposPath)
}
func NewFromDistrosRepoConfigs(distrosRepoConfigs rpmmd.DistrosRepoConfigs) *RepoRegistry {
return &RepoRegistry{distrosRepoConfigs}
}

View file

@ -1,11 +1,13 @@
package reporegistry
import (
"log"
"io/fs"
"os"
"path/filepath"
"strings"
"github.com/sirupsen/logrus"
"github.com/osbuild/images/pkg/distroidparser"
"github.com/osbuild/images/pkg/rpmmd"
)
@ -13,12 +15,24 @@ import (
// LoadAllRepositories loads all repositories for given distros from the given list of paths.
// Behavior is the same as with the LoadRepositories() method.
func LoadAllRepositories(confPaths []string) (rpmmd.DistrosRepoConfigs, error) {
var confFSes []fs.FS
for _, confPath := range confPaths {
confFSes = append(confFSes, os.DirFS(filepath.Join(confPath, "repositories")))
}
distrosRepoConfigs, err := LoadAllRepositoriesFromFS(confFSes)
if len(distrosRepoConfigs) == 0 {
return nil, &NoReposLoadedError{confPaths}
}
return distrosRepoConfigs, err
}
func LoadAllRepositoriesFromFS(confPaths []fs.FS) (rpmmd.DistrosRepoConfigs, error) {
distrosRepoConfigs := rpmmd.DistrosRepoConfigs{}
for _, confPath := range confPaths {
reposPath := filepath.Join(confPath, "repositories")
fileEntries, err := os.ReadDir(reposPath)
fileEntries, err := fs.ReadDir(confPath, ".")
if os.IsNotExist(err) {
continue
} else if err != nil {
@ -39,7 +53,7 @@ func LoadAllRepositories(confPaths []string) (rpmmd.DistrosRepoConfigs, error) {
// without a dot to separate major and minor release versions
distro, err := distroidparser.DefaultParser.Standardize(distroIDStr)
if err != nil {
log.Printf("failed to parse distro ID string, using it as is: %v", err)
logrus.Warnf("failed to parse distro ID string, using it as is: %v", err)
// NB: Before the introduction of distro ID standardization, the filename
// was used as the distro ID. This is kept for backward compatibility
// if the filename can't be parsed.
@ -52,23 +66,22 @@ func LoadAllRepositories(confPaths []string) (rpmmd.DistrosRepoConfigs, error) {
continue
}
configFile := filepath.Join(reposPath, fileEntry.Name())
distroRepos, err := rpmmd.LoadRepositoriesFromFile(configFile)
configFile, err := confPath.Open(fileEntry.Name())
if err != nil {
return nil, err
}
distroRepos, err := rpmmd.LoadRepositoriesFromReader(configFile)
if err != nil {
return nil, err
}
log.Println("Loaded repository configuration file:", configFile)
logrus.Infof("Loaded repository configuration file: %s", configFile)
distrosRepoConfigs[distro] = distroRepos
}
}
}
if len(distrosRepoConfigs) == 0 {
return nil, &NoReposLoadedError{confPaths}
}
return distrosRepoConfigs, nil
}

View file

@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
"io"
"os"
"sort"
"strings"
@ -232,10 +233,14 @@ func LoadRepositoriesFromFile(filename string) (map[string][]RepoConfig, error)
}
defer f.Close()
return LoadRepositoriesFromReader(f)
}
func LoadRepositoriesFromReader(r io.Reader) (map[string][]RepoConfig, error) {
var reposMap map[string][]repository
repoConfigs := make(map[string][]RepoConfig)
err = json.NewDecoder(f).Decode(&reposMap)
err := json.NewDecoder(r).Decode(&reposMap)
if err != nil {
return nil, err
}

2
vendor/modules.txt vendored
View file

@ -1022,7 +1022,7 @@ github.com/oracle/oci-go-sdk/v54/identity
github.com/oracle/oci-go-sdk/v54/objectstorage
github.com/oracle/oci-go-sdk/v54/objectstorage/transfer
github.com/oracle/oci-go-sdk/v54/workrequests
# github.com/osbuild/images v0.96.0
# github.com/osbuild/images v0.99.0
## explicit; go 1.21.0
github.com/osbuild/images/internal/common
github.com/osbuild/images/internal/environment