diff --git a/data/distrodefs/bootc-generic/imagetypes.yaml b/data/distrodefs/bootc-generic/imagetypes.yaml new file mode 100644 index 0000000000..0ce899df61 --- /dev/null +++ b/data/distrodefs/bootc-generic/imagetypes.yaml @@ -0,0 +1,138 @@ +--- +# This file contains the image definitions for the bootc +# "distro". bootc is special in the sense that a lot of what would +# normally be in the YAML is introspected from the bootc container. So +# the definitions are a lot smaller. They are used by +# pkg/distro/bootc. +# +# Note that we want to explore to use the "generic" distro for +# bootc as well but that is still some way off. + +.common: + kernel_options: + bootc_kernel_options: &bootc_kernel_options + # TODO: Drop this as we expect kargs to come from the container image, + # xref https://github.com/CentOS/centos-bootc-layered/blob/main/cloud/usr/lib/bootc/install/05-cloud-kargs.toml + - rw + - console=tty0 + - console=ttyS0 + + disk_sizes: + default_required_partition_sizes: &default_required_dir_sizes + "/": "1 GiB" + "/usr": "2 GiB" + partitioning: + ids: + - &prep_partition_dosid "41" + - &filesystem_linux_dosid "83" + - &fat16_bdosid "06" + guids: + - &bios_boot_partition_guid "21686148-6449-6E6F-744E-656564454649" + - &efi_system_partition_guid "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" + - &filesystem_data_guid "0FC63DAF-8483-4772-8E79-3D69D8477DE4" + - &xboot_ldr_partition_guid "BC13C2FF-59E6-4262-A352-B275FD6F7172" + - &prep_partition_guid "9E1A2D38-C612-4316-AA26-8B49521E5A8B" + + partition_tables: + default_bootc_partition_table: &default_bootc_partition_table + x86_64: + type: "gpt" + partitions: + - &default_partition_table_part_bios + size: "1 MiB" + bootable: true + type: *bios_boot_partition_guid + - &default_partition_table_part_efi + size: "501 MiB" + type: *efi_system_partition_guid + payload_type: "filesystem" + payload: + type: vfat + mountpoint: "/boot/efi" + label: "EFI-SYSTEM" + fstab_options: "umask=0077,shortname=winnt" + fstab_freq: 0 + fstab_passno: 2 + - &default_partition_table_part_boot + size: "1 GiB" + type: *filesystem_data_guid + payload_type: "filesystem" + payload: + mountpoint: "/boot" + label: "boot" + fstab_options: "ro" + - &default_partition_table_part_root + size: "2 GiB" + type: *filesystem_data_guid + payload_type: "filesystem" + payload: &default_partition_table_part_root_payload + label: "root" + mountpoint: "/" + fstab_options: "ro" + aarch64: &default_partition_table_aarch64 + type: "gpt" + partitions: + - *default_partition_table_part_efi + - *default_partition_table_part_boot + - *default_partition_table_part_root + ppc64le: + type: "gpt" + partitions: + - size: "4 MiB" + bootable: true + type: *prep_partition_guid + - *default_partition_table_part_boot + - *default_partition_table_part_root + s390x: + type: "gpt" + partitions: + - *default_partition_table_part_boot + - *default_partition_table_part_root + +image_types: + "raw": &raw_image_type + filename: "disk.raw" + image_func: "bootc_disk" + mime_type: "application/octet-stream" + bootable: true + default_size: "10 GiB" + exports: ["image"] + required_partition_sizes: *default_required_dir_sizes + partition_table: *default_bootc_partition_table + image_config: + kernel_options: *bootc_kernel_options + + "ami": + <<: *raw_image_type + filename: "disk.raw" + + "qcow2": + <<: *raw_image_type + filename: "disk.qcow2" + mime_type: "application/x-qemu-disk" + exports: ["qcow2"] + + "vmdk": + <<: *raw_image_type + filename: "disk.vmdk" + mime_type: "application/x-vmdk" + exports: ["vmdk"] + + "vhd": + <<: *raw_image_type + filename: "disk.vhd" + mime_type: "application/x-vhd" + exports: ["vpc"] + + "gce": + <<: *raw_image_type + filename: "image.tar.gz" + mime_type: "application/gzip" + exports: ["gce"] + + ova: + <<: *raw_image_type + name_aliases: ["vsphere-ova"] + filename: "image.ova" + mime_type: "application/ovf" + exports: ["archive"] diff --git a/data/distrodefs/distros.yaml b/data/distrodefs/distros.yaml index 7b39bad025..60e6803ddd 100644 --- a/data/distrodefs/distros.yaml +++ b/data/distrodefs/distros.yaml @@ -379,3 +379,10 @@ distros: x86_64: "registry.access.redhat.com/ubi{{.MajorVersion}}/ubi:latest" ppc64le: "registry.access.redhat.com/ubi{{.MajorVersion}}/ubi:latest" s390x: "registry.access.redhat.com/ubi{{.MajorVersion}}/ubi:latest" + + # Note that this will not be visible by default because we do not + # ship with a reporegistry that contains repositories for it. It + # is used by the pkg/distro/bootc distro to externalize image + # definitions + - name: bootc-generic-1 + defs_path: bootc-generic diff --git a/pkg/distro/bootc/bootc.go b/pkg/distro/bootc/bootc.go index c8c2d51e9e..45814bdf39 100644 --- a/pkg/distro/bootc/bootc.go +++ b/pkg/distro/bootc/bootc.go @@ -20,6 +20,7 @@ import ( "github.com/osbuild/images/pkg/customizations/users" "github.com/osbuild/images/pkg/disk" "github.com/osbuild/images/pkg/distro" + "github.com/osbuild/images/pkg/distro/defs" "github.com/osbuild/images/pkg/image" "github.com/osbuild/images/pkg/manifest" "github.com/osbuild/images/pkg/platform" @@ -36,7 +37,7 @@ type BootcDistro struct { sourceInfo *osinfo.Info buildSourceInfo *osinfo.Info - name string + id distro.ID defaultFs string releasever string rootfsMinSize uint64 @@ -53,16 +54,6 @@ type BootcArch struct { imageTypes map[string]distro.ImageType } -var _ = distro.ImageType(&BootcImageType{}) - -type BootcImageType struct { - arch *BootcArch - - name string - export string - filename string -} - func (d *BootcDistro) SetBuildContainer(imgref string) (err error) { if imgref == "" { return nil @@ -109,7 +100,7 @@ func (d *BootcDistro) DefaultFs() string { } func (d *BootcDistro) Name() string { - return d.name + return d.id.String() } func (d *BootcDistro) Codename() string { @@ -125,7 +116,7 @@ func (d *BootcDistro) OsVersion() string { } func (d *BootcDistro) Product() string { - return d.name + return d.id.String() } func (d *BootcDistro) ModulePlatformID() string { @@ -201,12 +192,20 @@ func (a *BootcArch) addImageTypes(imageTypes ...BootcImageType) { } } +var _ = distro.ImageType(&BootcImageType{}) + +type BootcImageType struct { + defs.ImageTypeYAML + + arch *BootcArch +} + func (t *BootcImageType) Name() string { - return t.name + return t.ImageTypeYAML.Name() } func (t *BootcImageType) Aliases() []string { - return nil + return t.ImageTypeYAML.NameAliases } func (t *BootcImageType) Arch() distro.Arch { @@ -214,11 +213,11 @@ func (t *BootcImageType) Arch() distro.Arch { } func (t *BootcImageType) Filename() string { - return t.filename + return t.ImageTypeYAML.Filename } func (t *BootcImageType) MIMEType() string { - return "application/x-test" + return t.ImageTypeYAML.MimeType } func (t *BootcImageType) OSTreeRef() string { @@ -237,11 +236,20 @@ func (t *BootcImageType) Size(size uint64) uint64 { } func (t *BootcImageType) PartitionType() disk.PartitionTableType { - return disk.PT_NONE + // XXX: duplicated from generic/imagetype.go + basePartitionTable, err := t.BasePartitionTable() + if errors.Is(err, defs.ErrNoPartitionTableForImgType) { + return disk.PT_NONE + } + if err != nil { + panic(err) + } + + return basePartitionTable.Type } func (t *BootcImageType) BasePartitionTable() (*disk.PartitionTable, error) { - return nil, nil + return t.ImageTypeYAML.PartitionTable(t.arch.distro.id, t.arch.arch.String()) } func (t *BootcImageType) BootMode() platform.BootMode { @@ -255,20 +263,12 @@ func (t *BootcImageType) BootMode() platform.BootMode { return platform.BOOT_HYBRID } -func (t *BootcImageType) BuildPipelines() []string { - return []string{"build"} -} - -func (t *BootcImageType) PayloadPipelines() []string { - return []string{""} -} - func (t *BootcImageType) PayloadPackageSets() []string { return nil } func (t *BootcImageType) Exports() []string { - return []string{t.export} + return t.ImageTypeYAML.Exports } func (t *BootcImageType) SupportedBlueprintOptions() []string { @@ -315,7 +315,7 @@ func (t *BootcImageType) Manifest(bp *blueprint.Blueprint, options distro.ImageO platform := PlatformFor(t.arch.Name(), t.arch.distro.sourceInfo.UEFIVendor) // For the bootc-disk image, the filename is the basename and // the extension is added automatically for each disk format - filename := strings.Split(t.filename, ".")[0] + filename := strings.Split(t.Filename(), ".")[0] img := image.NewBootcDiskImage(platform, filename, containerSource, buildContainerSource) img.OSCustomizations.Users = users.UsersFromBP(customizations.GetUsers()) @@ -329,14 +329,8 @@ func (t *BootcImageType) Manifest(bp *blueprint.Blueprint, options distro.ImageO img.OSCustomizations.MountConfiguration = *t.arch.distro.sourceInfo.MountConfiguration } - img.OSCustomizations.KernelOptionsAppend = []string{ - "rw", - // TODO: Drop this as we expect kargs to come from the container image, - // xref https://github.com/CentOS/centos-bootc-layered/blob/main/cloud/usr/lib/bootc/install/05-cloud-kargs.toml - "console=tty0", - "console=ttyS0", - } - + imageConfig := t.ImageTypeYAML.ImageConfig(t.arch.distro.id, t.arch.Name()) + img.OSCustomizations.KernelOptionsAppend = imageConfig.KernelOptions if kopts := customizations.GetKernel(); kopts != nil && kopts.Append != "" { img.OSCustomizations.KernelOptionsAppend = append(img.OSCustomizations.KernelOptionsAppend, kopts.Append) } @@ -408,12 +402,16 @@ func NewBootcDistro(imgref string) (*BootcDistro, error) { return newBootcDistroAfterIntrospect(cnt.Arch(), info, imgref, defaultFs, cntSize) } -func newBootcDistroAfterIntrospect(archStr string, info *osinfo.Info, imgref, defaultFs string, cntSize uint64) (*BootcDistro, error) { +func newBootcDistroAfterIntrospect(archStr string, info *osinfo.Info, imgref, defaultFsStr string, cntSize uint64) (*BootcDistro, error) { nameVer := fmt.Sprintf("bootc-%s-%s", info.OSRelease.ID, info.OSRelease.VersionID) + id, err := distro.ParseID(nameVer) + if err != nil { + return nil, err + } bd := &BootcDistro{ - name: nameVer, + id: *id, releasever: info.OSRelease.VersionID, - defaultFs: defaultFs, + defaultFs: defaultFsStr, rootfsMinSize: cntSize * containerSizeToDiskSizeMultiplier, imgref: imgref, @@ -431,55 +429,30 @@ func newBootcDistroAfterIntrospect(archStr string, info *osinfo.Info, imgref, de ba := &BootcArch{ arch: archi, } - // TODO: add iso image types, see bootc-image-builder - // - // Note that the file extension is hardcoded in - // pkg/image/bootc_disk.go, we have no way to access - // it here so we need to duplicate it - // XXX: find a way to avoid this duplication - ba.addImageTypes( - BootcImageType{ - name: "ami", - export: "image", - filename: "disk.raw", - }, - BootcImageType{ - name: "qcow2", - export: "qcow2", - filename: "disk.qcow2", - }, - BootcImageType{ - name: "raw", - export: "image", - filename: "disk.raw", - }, - BootcImageType{ - name: "vmdk", - export: "vmdk", - filename: "disk.vmdk", - }, - BootcImageType{ - name: "vhd", - export: "bpc", - filename: "disk.vhd", - }, - BootcImageType{ - name: "gce", - export: "gce", - filename: "image.tar.gz", - }, - BootcImageType{ - name: "ova", - export: "archive", - filename: "image.ova", - }, - ) + + distroYAML, err := defs.LoadDistroWithoutImageTypes("bootc-generic-1") + if err != nil { + return nil, err + } + defaultFs, err := disk.NewFSType(defaultFsStr) + if err != nil { + return nil, err + } + distroYAML.DefaultFSType = defaultFs + if err := distroYAML.LoadImageTypes(); err != nil { + return nil, err + } + for _, imgTypeYaml := range distroYAML.ImageTypes() { + ba.addImageTypes(BootcImageType{ + ImageTypeYAML: imgTypeYaml, + }) + } + // XXX: move into YAML as well ba.imageTypes["bootc-installer"] = &BootcAnacondaInstaller{ arch: ba, name: "bootc-installer", export: "bootiso", } - bd.addArches(ba) return bd, nil diff --git a/pkg/distro/bootc/export_test.go b/pkg/distro/bootc/export_test.go index 1a464fecb4..d0413f6643 100644 --- a/pkg/distro/bootc/export_test.go +++ b/pkg/distro/bootc/export_test.go @@ -12,7 +12,6 @@ import ( var ( CheckFilesystemCustomizations = checkFilesystemCustomizations - PartitionTables = partitionTables UpdateFilesystemSizes = updateFilesystemSizes CalcRequiredDirectorySizes = calcRequiredDirectorySizes @@ -22,7 +21,8 @@ var ( func NewTestBootcDistro() *BootcDistro { info := &osinfo.Info{ OSRelease: osinfo.OSRelease{ - ID: "bootc-test", + ID: "bootc-test", + VersionID: "1", }, } return common.Must(newBootcDistroAfterIntrospect("x86_64", info, "quay.io/example/example:ref", "xfs", 0)) diff --git a/pkg/distro/bootc/image_test.go b/pkg/distro/bootc/image_test.go index ac8f2fcc2c..09986d45ad 100644 --- a/pkg/distro/bootc/image_test.go +++ b/pkg/distro/bootc/image_test.go @@ -9,7 +9,6 @@ import ( "github.com/osbuild/blueprint/pkg/blueprint" "github.com/osbuild/images/internal/common" - "github.com/osbuild/images/pkg/arch" "github.com/osbuild/images/pkg/datasizes" "github.com/osbuild/images/pkg/disk" "github.com/osbuild/images/pkg/disk/partition" @@ -172,20 +171,6 @@ func TestLocalMountpointPolicy(t *testing.T) { } } -func TestBasePartitionTablesHaveRoot(t *testing.T) { - // make sure that all base partition tables have at least a root partition defined - for arch, pt := range bootc.PartitionTables { - rootMountable := pt.FindMountable("/") - if rootMountable == nil { - t.Errorf("partition table %q does not define a root filesystem", arch) - } - _, isFS := rootMountable.(*disk.Filesystem) - if !isFS { - t.Errorf("root mountable for %q is not an ordinary filesystem", arch) - } - } -} - func TestUpdateFilesystemSizes(t *testing.T) { type testCase struct { customizations []blueprint.FilesystemCustomization @@ -374,9 +359,9 @@ func TestGenPartitionTableSetsRootfsForAllFilesystemsBtrfs(t *testing.T) { mnt, _ := findMountableSizeableFor(pt, "/") assert.Equal(t, "btrfs", mnt.GetFSType()) - // btrfs has a default (ext4) /boot + // btrfs has a default (xfs) /boot mnt, _ = findMountableSizeableFor(pt, "/boot") - assert.Equal(t, "ext4", mnt.GetFSType()) + assert.Equal(t, "xfs", mnt.GetFSType()) // ESP is always vfat mnt, _ = findMountableSizeableFor(pt, "/boot/efi") @@ -672,9 +657,10 @@ func TestGenPartitionTableFromOSInfo(t *testing.T) { imgType := bootc.NewTestBootcImageType() // pretend a custom partition table is set via the bootc // container sourceInfo mechanism - newPt := bootc.PartitionTables[arch.Current().String()] + newPt, err := imgType.BasePartitionTable() + assert.NoError(t, err) newPt.UUID = "01010101-01011-01011-01011-01010101" - imgType.SetSourceInfoPartitionTable(&newPt) + imgType.SetSourceInfoPartitionTable(newPt) // validate that the container uuid is part of the generated // manifest diff --git a/pkg/distro/bootc/partition.go b/pkg/distro/bootc/partition.go index 1c54672f51..2c6169c894 100644 --- a/pkg/distro/bootc/partition.go +++ b/pkg/distro/bootc/partition.go @@ -14,8 +14,6 @@ import ( ) const ( - DEFAULT_SIZE = datasizes.Size(10 * GibiByte) - // As a baseline heuristic we double the size of // the input container to support in-place updates. // This is planned to be more configurable in the @@ -66,14 +64,12 @@ func (t *BootcImageType) basePartitionTable() (*disk.PartitionTable, error) { if t.arch.distro.sourceInfo != nil && t.arch.distro.sourceInfo.PartitionTable != nil { return t.arch.distro.sourceInfo.PartitionTable, nil } - // get it from the build-in fallback partition tables - if pt, ok := partitionTables[t.arch.Name()]; ok { - return &pt, nil - } - return nil, fmt.Errorf("cannot find a base partition table for %q", t.Name()) + // otherwise we use our YAML + return t.ImageTypeYAML.PartitionTable(t.arch.distro.id, t.arch.Name()) } func (t *BootcImageType) genPartitionTable(customizations *blueprint.Customizations, rootfsMinSize uint64, rng *rand.Rand) (*disk.PartitionTable, error) { + // XXX: much duplication with generic/imagetype.go:getPartitionTable() fsCust := customizations.GetFilesystems() diskCust, err := customizations.GetPartitioning() if err != nil { @@ -97,7 +93,6 @@ func (t *BootcImageType) genPartitionTable(customizations *blueprint.Customizati var partitionTable *disk.PartitionTable switch { - // XXX: move into images library case fsCust != nil && diskCust != nil: return nil, fmt.Errorf("cannot combine disk and filesystem customizations") case diskCust != nil: @@ -112,6 +107,7 @@ func (t *BootcImageType) genPartitionTable(customizations *blueprint.Customizati } } + // XXX: make this generic/configurable // Ensure ext4 rootfs has fs-verity enabled rootfs := partitionTable.FindMountable("/") if rootfs != nil { @@ -169,15 +165,7 @@ func (t *BootcImageType) genPartitionTableFsCust(basept *disk.PartitionTable, fs } fsCustomizations := updateFilesystemSizes(fsCust, rootfsMinSize) - pt, err := disk.NewPartitionTable(basept, fsCustomizations, DEFAULT_SIZE, partitioningMode, t.arch.arch, nil, t.arch.distro.defaultFs, rng) - if err != nil { - return nil, err - } - - if err := setFSTypes(pt, t.arch.distro.defaultFs); err != nil { - return nil, fmt.Errorf("error setting root filesystem type: %w", err) - } - return pt, nil + return disk.NewPartitionTable(basept, fsCustomizations, t.ImageTypeYAML.DefaultSize, partitioningMode, t.arch.arch, nil, t.arch.distro.defaultFs, rng) } func checkMountpoints(filesystems []blueprint.FilesystemCustomization, policy *pathpolicy.PathPolicies) error { @@ -274,36 +262,3 @@ func updateFilesystemSizes(fsCustomizations []blueprint.FilesystemCustomization, } return updated } - -// setFSTypes sets the filesystem types for all mountable entities to match the -// selected rootfs type. -// If rootfs is 'btrfs', the function will keep '/boot' to its default. -func setFSTypes(pt *disk.PartitionTable, rootfs string) error { - if rootfs == "" { - return fmt.Errorf("root filesystem type is empty") - } - - return pt.ForEachMountable(func(mnt disk.Mountable, _ []disk.Entity) error { - switch mnt.GetMountpoint() { - case "/boot/efi": - // never change the efi partition's type - return nil - case "/boot": - // change only if we're not doing btrfs - if rootfs == "btrfs" { - return nil - } - fallthrough - default: - switch elem := mnt.(type) { - case *disk.Filesystem: - elem.Type = rootfs - case *disk.BtrfsSubvolume: - // nothing to do - default: - return fmt.Errorf("the mountable disk entity for %q of the base partition table is not an ordinary filesystem but %T", mnt.GetMountpoint(), mnt) - } - return nil - } - }) -} diff --git a/pkg/distro/bootc/partition_tables.go b/pkg/distro/bootc/partition_tables.go deleted file mode 100644 index f9c7d7e87a..0000000000 --- a/pkg/distro/bootc/partition_tables.go +++ /dev/null @@ -1,139 +0,0 @@ -package bootc - -import ( - "github.com/osbuild/images/pkg/arch" - "github.com/osbuild/images/pkg/disk" - "github.com/osbuild/images/pkg/distro" -) - -const ( - MebiByte = 1024 * 1024 // MiB - GibiByte = 1024 * 1024 * 1024 // GiB - // BootOptions defines the mountpoint options for /boot - // See https://github.com/containers/bootc/pull/341 for the rationale for - // using `ro` by default. Briefly it protects against corruption - // by non-ostree aware tools. - BootOptions = "ro" - // And we default to `ro` for the rootfs too, because we assume the input - // container image is using composefs. For more info, see - // https://github.com/containers/bootc/pull/417 and - // https://github.com/ostreedev/ostree/issues/3193 - RootOptions = "ro" -) - -// diskUuidOfUnknownOrigin is used by default for disk images, -// picked by someone in the past for unknown reasons. More in -// e.g. https://github.com/osbuild/bootc-image-builder/pull/568 and -// https://github.com/osbuild/images/pull/823 -const diskUuidOfUnknownOrigin = "D209C89E-EA5E-4FBD-B161-B461CCE297E0" - -// efiPartition defines the default ESP. See also -// https://en.wikipedia.org/wiki/EFI_system_partition -var efiPartition = disk.Partition{ - Size: 501 * MebiByte, - Type: disk.EFISystemPartitionGUID, - UUID: disk.EFISystemPartitionUUID, - Payload: &disk.Filesystem{ - Type: "vfat", - UUID: disk.EFIFilesystemUUID, - Mountpoint: "/boot/efi", - Label: "EFI-SYSTEM", - FSTabOptions: "umask=0077,shortname=winnt", - FSTabFreq: 0, - FSTabPassNo: 2, - }, -} - -// bootPartition defines a distinct filesystem for /boot -// which is needed for e.g. LVM or LUKS when using GRUB -// (which this project doesn't support today...) -// See also https://github.com/containers/bootc/pull/529/commits/e5548d8765079171e6ed39a3ab0479bc8681a1c9 -var bootPartition = disk.Partition{ - Size: 1 * GibiByte, - Type: disk.FilesystemDataGUID, - UUID: disk.DataPartitionUUID, - Payload: &disk.Filesystem{ - Type: "ext4", - Mountpoint: "/boot", - Label: "boot", - FSTabOptions: BootOptions, - FSTabFreq: 1, - FSTabPassNo: 2, - }, -} - -// rootPartition holds the root filesystem; however note -// that while the type here defines "ext4" because the data -// type requires something there, in practice we pull -// the rootfs type from the container image by default. -// See https://containers.github.io/bootc/bootc-install.html -var rootPartition = disk.Partition{ - Size: 2 * GibiByte, - Type: disk.FilesystemDataGUID, - UUID: disk.RootPartitionUUID, - Payload: &disk.Filesystem{ - Type: "ext4", - Label: "root", - Mountpoint: "/", - FSTabOptions: RootOptions, - FSTabFreq: 1, - FSTabPassNo: 1, - }, -} - -var partitionTables = distro.BasePartitionTableMap{ - arch.ARCH_X86_64.String(): disk.PartitionTable{ - UUID: diskUuidOfUnknownOrigin, - Type: disk.PT_GPT, - Partitions: []disk.Partition{ - { - Size: 1 * MebiByte, - Bootable: true, - Type: disk.BIOSBootPartitionGUID, - UUID: disk.BIOSBootPartitionUUID, - }, - efiPartition, - bootPartition, - rootPartition, - }, - }, - arch.ARCH_AARCH64.String(): disk.PartitionTable{ - UUID: diskUuidOfUnknownOrigin, - Type: disk.PT_GPT, - Partitions: []disk.Partition{ - efiPartition, - bootPartition, - rootPartition, - }, - }, - arch.ARCH_S390X.String(): disk.PartitionTable{ - UUID: diskUuidOfUnknownOrigin, - Type: disk.PT_GPT, - Partitions: []disk.Partition{ - bootPartition, - rootPartition, - }, - }, - arch.ARCH_PPC64LE.String(): disk.PartitionTable{ - UUID: diskUuidOfUnknownOrigin, - Type: disk.PT_GPT, - Partitions: []disk.Partition{ - { - Size: 4 * MebiByte, - Type: disk.PRePartitionGUID, - Bootable: true, - }, - bootPartition, - rootPartition, - }, - }, - arch.ARCH_RISCV64.String(): disk.PartitionTable{ - UUID: diskUuidOfUnknownOrigin, - Type: disk.PT_GPT, - Partitions: []disk.Partition{ - efiPartition, - bootPartition, - rootPartition, - }, - }, -} diff --git a/pkg/distro/defs/loader.go b/pkg/distro/defs/loader.go index 4f2dc4c76f..91a33f81a6 100644 --- a/pkg/distro/defs/loader.go +++ b/pkg/distro/defs/loader.go @@ -184,6 +184,21 @@ func loadDistros() (*distrosYAML, error) { // with the way distrofactory/reporegistry work which is by defining // distros via repository files. func NewDistroYAML(nameVer string) (*DistroYAML, error) { + foundDistro, err := LoadDistroWithoutImageTypes(nameVer) + if err != nil { + return nil, err + } + if foundDistro == nil { + return nil, nil + } + + if err := foundDistro.LoadImageTypes(); err != nil { + return nil, err + } + return foundDistro, nil +} + +func LoadDistroWithoutImageTypes(nameVer string) (*DistroYAML, error) { distros, err := loadDistros() if err != nil { return nil, err @@ -210,6 +225,7 @@ func NewDistroYAML(nameVer string) (*DistroYAML, error) { if foundDistro == nil { return nil, nil } + // having "foundDistro.id" avoid re-parsing this in the various helpers id, err := distro.ParseID(nameVer) if err != nil { @@ -220,10 +236,13 @@ func NewDistroYAML(nameVer string) (*DistroYAML, error) { return nil, err } - // load imageTypes - f, err := dataFS().Open(filepath.Join(foundDistro.DefsPath, "imagetypes.yaml")) + return foundDistro, err +} + +func (d *DistroYAML) LoadImageTypes() error { + f, err := dataFS().Open(filepath.Join(d.DefsPath, "imagetypes.yaml")) if err != nil { - return nil, err + return err } defer f.Close() @@ -231,26 +250,25 @@ func NewDistroYAML(nameVer string) (*DistroYAML, error) { decoder := yaml.NewDecoder(f) decoder.KnownFields(true) if err := decoder.Decode(&toplevel); err != nil { - return nil, err + return err } if len(toplevel.ImageTypes) > 0 { - foundDistro.imageTypes = make(map[string]ImageTypeYAML, len(toplevel.ImageTypes)) + d.imageTypes = make(map[string]ImageTypeYAML, len(toplevel.ImageTypes)) for name := range toplevel.ImageTypes { v := toplevel.ImageTypes[name] v.name = name - if err := v.runTemplates(foundDistro); err != nil { - return nil, err + if err := v.runTemplates(d); err != nil { + return err } - if err := v.setupDefaultFS(foundDistro.DefaultFSType.String()); err != nil { - return nil, err + if err := v.setupDefaultFS(d.DefaultFSType.String()); err != nil { + return err } - foundDistro.imageTypes[name] = v + d.imageTypes[name] = v } } - foundDistro.imageConfig = toplevel.ImageConfig.For(foundDistro.ID) - - return foundDistro, nil + d.imageConfig = toplevel.ImageConfig.For(d.ID) + return nil } // imageTypesYAML describes the image types for a given distribution diff --git a/pkg/distro/generic/imagetype.go b/pkg/distro/generic/imagetype.go index a4bb296fa7..af18a2ada2 100644 --- a/pkg/distro/generic/imagetype.go +++ b/pkg/distro/generic/imagetype.go @@ -193,7 +193,6 @@ func (t *imageType) getPartitionTable(customizations *blueprint.Customizations, func (t *imageType) getDefaultImageConfig() *distro.ImageConfig { imageConfig := t.ImageConfig(t.arch.distro.ID, t.arch.arch.String()) return imageConfig.InheritFrom(t.arch.distro.ImageConfig()) - } func (t *imageType) getDefaultInstallerConfig() (*distro.InstallerConfig, error) { diff --git a/test/data/manifest-checksums/bootc_test_os_1-aarch64-ami-empty b/test/data/manifest-checksums/bootc_test_os_1-aarch64-ami-empty index 6347a2b8e3..07718dc495 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-aarch64-ami-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-aarch64-ami-empty @@ -1 +1 @@ -be92367cbe05c5dba5c6061ad09d70d8e8357592 +6fedbadf0ad99584e25c3a2f3b8510233eb9b667 diff --git a/test/data/manifest-checksums/bootc_test_os_1-aarch64-gce-empty b/test/data/manifest-checksums/bootc_test_os_1-aarch64-gce-empty index 975ea2acd6..65301d8686 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-aarch64-gce-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-aarch64-gce-empty @@ -1 +1 @@ -5a2e44f05d0775d9cc7c988cf4479a211100e93e +1dabe7d07ac7ddf6f8e4e0a0d1f3ed3ea3d7d010 diff --git a/test/data/manifest-checksums/bootc_test_os_1-aarch64-ova-empty b/test/data/manifest-checksums/bootc_test_os_1-aarch64-ova-empty index 6e43323122..377d882b2d 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-aarch64-ova-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-aarch64-ova-empty @@ -1 +1 @@ -84fe6462a56271c998d3b51c9d74d9514aae21a4 +1d35826776093132275e4eab0f58d529628744e6 diff --git a/test/data/manifest-checksums/bootc_test_os_1-aarch64-qcow2-empty b/test/data/manifest-checksums/bootc_test_os_1-aarch64-qcow2-empty index f1f4248683..f475052284 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-aarch64-qcow2-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-aarch64-qcow2-empty @@ -1 +1 @@ -439078c68a3c2225d89dd9c925919a13b69bc4f0 +19909019b9bfdecef15e2362968c5ec193604edd diff --git a/test/data/manifest-checksums/bootc_test_os_1-aarch64-raw-empty b/test/data/manifest-checksums/bootc_test_os_1-aarch64-raw-empty index eb7f3070f8..deea8e9170 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-aarch64-raw-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-aarch64-raw-empty @@ -1 +1 @@ -d849973f6298f868a5fa965db6912d9a4b1b7da8 +556455a373d6a7567e370769ba82ad5909681dc1 diff --git a/test/data/manifest-checksums/bootc_test_os_1-aarch64-vhd-empty b/test/data/manifest-checksums/bootc_test_os_1-aarch64-vhd-empty index 32bc914f39..9e53e4f092 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-aarch64-vhd-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-aarch64-vhd-empty @@ -1 +1 @@ -b05ae8d20f891817ae01e8e930dfe5c694ab9832 +424843c3edf0d3cd69d5bf893171767a1e16a0ab diff --git a/test/data/manifest-checksums/bootc_test_os_1-aarch64-vmdk-empty b/test/data/manifest-checksums/bootc_test_os_1-aarch64-vmdk-empty index 72851794bb..2fef81f5d8 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-aarch64-vmdk-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-aarch64-vmdk-empty @@ -1 +1 @@ -f2219c91de6431632f2addbe3c9524bd1b299e93 +23129854488486a5507cb7512a7fd057d9122231 diff --git a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ami-empty b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ami-empty index f0308b6639..47e511434a 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ami-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ami-empty @@ -1 +1 @@ -e59e82acecb24375bc56f4bcf7ede6a9f966d357 +fe83f7f85a94adc72783a47a3e9043b517417cd1 diff --git a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-gce-empty b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-gce-empty index 9e93572f8f..4730163156 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-gce-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-gce-empty @@ -1 +1 @@ -adac2acafceacc285567182b2bb34ee852b0d349 +370c5f735a95fb90b3305f5264e9ce2dbfe0339d diff --git a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ova-empty b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ova-empty index c5f9252ced..309b22ec9b 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ova-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-ova-empty @@ -1 +1 @@ -94cbbc242f012edcc26e135843ab9c8dc5e5553b +fb5ef343a50900503e60b5338466ad5c79dca2e0 diff --git a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-qcow2-empty b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-qcow2-empty index 7aceba42db..ad260748c2 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-qcow2-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-qcow2-empty @@ -1 +1 @@ -8094e94ce116d8dc76554058e220c51c2b994ee8 +19ad9ca41823a44986c212dd0aa72dbdaef82767 diff --git a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-raw-empty b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-raw-empty index b03d8ff401..1262888980 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-raw-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-raw-empty @@ -1 +1 @@ -0bbeb4ef032a713f89e0f8d5eae0ecf6b4e103e2 +5ec3c7623ce59352bbb9b986b5638a023d498e7d diff --git a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vhd-empty b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vhd-empty index 091538ad41..81169dd92c 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vhd-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vhd-empty @@ -1 +1 @@ -83ddce6c176a16644a1686d5907462e9d739b56e +cb60356056e08cbca49ea0b3899acca9b00fe696 diff --git a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vmdk-empty b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vmdk-empty index bce093f7ed..3fbfa5ee67 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vmdk-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-ppc64le-vmdk-empty @@ -1 +1 @@ -22b19f974d84d60296eb9092770b887c89f0ca44 +1404d779f5f88b1b4b965a7d1918e54915e14aae diff --git a/test/data/manifest-checksums/bootc_test_os_1-s390x-ami-empty b/test/data/manifest-checksums/bootc_test_os_1-s390x-ami-empty index 6dc6729ee5..0d5ff152aa 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-s390x-ami-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-s390x-ami-empty @@ -1 +1 @@ -1f70e6bcf60915aefc48c2483dfe74332519c8da +bd583001066b2d4801f24ea03321e95ec9a04cec diff --git a/test/data/manifest-checksums/bootc_test_os_1-s390x-gce-empty b/test/data/manifest-checksums/bootc_test_os_1-s390x-gce-empty index bd14146c06..0f947bd556 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-s390x-gce-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-s390x-gce-empty @@ -1 +1 @@ -afac907d5169b9d081f6b40c67ebbecd40a50732 +535ddd2c0203292f008e90740f06e94e2b7806bd diff --git a/test/data/manifest-checksums/bootc_test_os_1-s390x-ova-empty b/test/data/manifest-checksums/bootc_test_os_1-s390x-ova-empty index fdde24ae8c..2f04c19df7 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-s390x-ova-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-s390x-ova-empty @@ -1 +1 @@ -b1c8df167d7ccc1fdf1c0421621e3f1a13f5c60f +7047760b2ae6e467d82bc7d87e619b3975a42e33 diff --git a/test/data/manifest-checksums/bootc_test_os_1-s390x-qcow2-empty b/test/data/manifest-checksums/bootc_test_os_1-s390x-qcow2-empty index 71e0632564..29e0c3f342 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-s390x-qcow2-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-s390x-qcow2-empty @@ -1 +1 @@ -9934911972c90d344f1115d43cae1a0766f72bdc +8763d786730e3afb553289e3234b7c1f4c8e34ad diff --git a/test/data/manifest-checksums/bootc_test_os_1-s390x-raw-empty b/test/data/manifest-checksums/bootc_test_os_1-s390x-raw-empty index eaab2f8a00..5a8f4491f3 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-s390x-raw-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-s390x-raw-empty @@ -1 +1 @@ -32e1db1f27426b828ea41dee6f070ac90f8e7981 +2ab9cc843a16f3acc0602a070edcc37c28166263 diff --git a/test/data/manifest-checksums/bootc_test_os_1-s390x-vhd-empty b/test/data/manifest-checksums/bootc_test_os_1-s390x-vhd-empty index 5613752ed9..946a2dedc6 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-s390x-vhd-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-s390x-vhd-empty @@ -1 +1 @@ -8a35a0035c632e2b7c88d7b48c0a793b6f8a9118 +3fd256b851a5a47b64b49221b95373bcc6068983 diff --git a/test/data/manifest-checksums/bootc_test_os_1-s390x-vmdk-empty b/test/data/manifest-checksums/bootc_test_os_1-s390x-vmdk-empty index c574d243f6..e0602590cc 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-s390x-vmdk-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-s390x-vmdk-empty @@ -1 +1 @@ -9d00abbb11187099bfba2853b6f0a8557d103b59 +d1b81b1b81e04bd231f9b8ea6c0411983215795c diff --git a/test/data/manifest-checksums/bootc_test_os_1-x86_64-ami-empty b/test/data/manifest-checksums/bootc_test_os_1-x86_64-ami-empty index 781d8c1bdb..1e8bbae907 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-x86_64-ami-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-x86_64-ami-empty @@ -1 +1 @@ -201804dda1d4fc678abf4df10e782fcd22dfdad3 +d226a2610270803fbbd1bed30b40b2c3c6da412b diff --git a/test/data/manifest-checksums/bootc_test_os_1-x86_64-gce-empty b/test/data/manifest-checksums/bootc_test_os_1-x86_64-gce-empty index fea38909ea..07a09f9c5b 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-x86_64-gce-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-x86_64-gce-empty @@ -1 +1 @@ -139423bc4831ed68f726e579e04bb1913a90f57a +411fd05605539b5363542c12b0e30bf972643481 diff --git a/test/data/manifest-checksums/bootc_test_os_1-x86_64-ova-empty b/test/data/manifest-checksums/bootc_test_os_1-x86_64-ova-empty index a6350b2625..c93bc9209e 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-x86_64-ova-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-x86_64-ova-empty @@ -1 +1 @@ -7018c3b6f62d2cd693ab0dd59ecfaa74e0d41012 +aa196e6defcc3a2c46ebd6c41c725ea10e08364d diff --git a/test/data/manifest-checksums/bootc_test_os_1-x86_64-qcow2-empty b/test/data/manifest-checksums/bootc_test_os_1-x86_64-qcow2-empty index c562a02e4d..f5b263c577 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-x86_64-qcow2-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-x86_64-qcow2-empty @@ -1 +1 @@ -f90228bb378ba066b45add09fc33eaf52d3efd56 +f0ef2ae715b47ee8fbabda5cdb9e451f71e1aa34 diff --git a/test/data/manifest-checksums/bootc_test_os_1-x86_64-raw-empty b/test/data/manifest-checksums/bootc_test_os_1-x86_64-raw-empty index c079360076..125ff4c45c 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-x86_64-raw-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-x86_64-raw-empty @@ -1 +1 @@ -eedbdd59e9ccbecad2f4be6041600d0241f6692a +92c595ecb9d27b66530178cdd5e015503099ae12 diff --git a/test/data/manifest-checksums/bootc_test_os_1-x86_64-vhd-empty b/test/data/manifest-checksums/bootc_test_os_1-x86_64-vhd-empty index 47b5bd5238..1f03fe3494 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-x86_64-vhd-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-x86_64-vhd-empty @@ -1 +1 @@ -3332836bfe8103d0b210f53f3d7a918ecea315bc +73f3c2804d99a3947e6285a8b68ba187ce14675f diff --git a/test/data/manifest-checksums/bootc_test_os_1-x86_64-vmdk-empty b/test/data/manifest-checksums/bootc_test_os_1-x86_64-vmdk-empty index a33e0f10c3..3a6effd714 100644 --- a/test/data/manifest-checksums/bootc_test_os_1-x86_64-vmdk-empty +++ b/test/data/manifest-checksums/bootc_test_os_1-x86_64-vmdk-empty @@ -1 +1 @@ -b7384e47fdec3ed6ba747dfe1d3a910b2c1426d1 +44f070a343b7fe9b1db8b57afbdaad6bd5ed3321 diff --git a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ami-empty b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ami-empty index 00d74931a8..d00b814046 100644 --- a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ami-empty +++ b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ami-empty @@ -1 +1 @@ -eb148ebc11dcde5b81b42dbc4d6fe9e3c24a221e +60a44d4dcf604e57fb3f11d6f0610010354e6ffb diff --git a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-gce-empty b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-gce-empty index a9ca6712c6..042e5592f0 100644 --- a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-gce-empty +++ b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-gce-empty @@ -1 +1 @@ -da256b6bbf359f058e6321a77843c4f70c88ecec +72abd8e9aa663874c4de41154a0872a27580ef14 diff --git a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ova-empty b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ova-empty index 033e2f6792..9c33724269 100644 --- a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ova-empty +++ b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-ova-empty @@ -1 +1 @@ -d023453511e433e6b5dab3029879e3fa98fca531 +23d850967366f636181876da271110bd65ece2a0 diff --git a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-qcow2-empty b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-qcow2-empty index 2095d8f240..fdaa1b5a7a 100644 --- a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-qcow2-empty +++ b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-qcow2-empty @@ -1 +1 @@ -26c1410ce877a24f4e0023aafdf312f5e1c7a90e +8f7b13b602ef7e7d2cb8485b144a9f531c96508c diff --git a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-raw-empty b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-raw-empty index d7972ca079..1e8050bcf3 100644 --- a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-raw-empty +++ b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-raw-empty @@ -1 +1 @@ -3a59566c39c6baaa9bfe5939aab8b0d4f1a414e1 +3577b02e4d1e0f003adebc0c587fc6e35c5a2c53 diff --git a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vhd-empty b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vhd-empty index bd18a66429..4e62f6cb30 100644 --- a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vhd-empty +++ b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vhd-empty @@ -1 +1 @@ -89d01a259aac5a45c30f4b94746c3d73756185a9 +86dc5572c6fd8894d0ee9d97f070c287e436b861 diff --git a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vmdk-empty b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vmdk-empty index fb83a36152..abcdce5977 100644 --- a/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vmdk-empty +++ b/test/data/manifest-checksums/bootc_test_os_with_build_container_1-x86_64-vmdk-empty @@ -1 +1 @@ -4cc099d9acd917bf03541b2fdfa3b0ba9fac87ab +a67d95f2e94eced982b1e85d6c5678e10b8de837