Skip to content

Commit

Permalink
manifest/live: add new live manifest
Browse files Browse the repository at this point in the history
This creates things that start in `live` mode, for use on ISOs.
  • Loading branch information
supakeen committed Jul 19, 2023
1 parent 0ab1cde commit ec7bfdf
Show file tree
Hide file tree
Showing 17 changed files with 48,973 additions and 958 deletions.
71 changes: 63 additions & 8 deletions pkg/distro/fedora_ng/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ var (
oscap.Standard,
}

rawImgType = imageType{
name: "raw",
diskRawImgType = imageType{
name: "disk-raw",
filename: "raw.img",
mimeType: "application/disk",
packageSets: map[string]packageSetFunc{
osPkgsKey: corePackageSet,
osPkgsKey: diskRawPackageSet,
},
rpmOstree: false,
kernelOptions: defaultKernelOptions,
Expand All @@ -50,6 +50,23 @@ var (
exports: []string{"image"},
basePartitionTables: defaultBasePartitionTables,
}

isoLiveImgType = imageType{
name: "iso-live",
nameAliases: []string{},
filename: "live.iso",
mimeType: "application/x-iso9660-image",
packageSets: map[string]packageSetFunc{
osPkgsKey: isoLivePackageSet,
},
bootable: true,
bootISO: true,
rpmOstree: false,
image: liveImage,
buildPipelines: []string{"build"},
payloadPipelines: []string{"os", "rootfs-image", "efiboot-tree", "bootiso-tree", "bootiso"},
exports: []string{"bootiso"},
}
)

type distribution struct {
Expand Down Expand Up @@ -215,29 +232,67 @@ func newDistro(version int) distro.Distro {
distro: &rd,
}

x86_64.addImageTypes(
&platform.X86{
UEFIVendor: "fedora",
BasePlatform: platform.BasePlatform{
ImageFormat: platform.FORMAT_RAW,
},
},
diskRawImgType,
)

x86_64.addImageTypes(
&platform.X86{
BIOS: true,
UEFIVendor: "fedora",
BasePlatform: platform.BasePlatform{
FirmwarePackages: []string{
"microcode_ctl", // ??
"iwl1000-firmware",
"iwl100-firmware",
"iwl105-firmware",
"iwl135-firmware",
"iwl2000-firmware",
"iwl2030-firmware",
"iwl3160-firmware",
"iwl5000-firmware",
"iwl5150-firmware",
"iwl6000-firmware",
"iwl6050-firmware",
},
},
},
isoLiveImgType,
)

aarch64 := architecture{
name: platform.ARCH_AARCH64.String(),
distro: &rd,
}

x86_64.addImageTypes(
&platform.X86{
aarch64.addImageTypes(
&platform.Aarch64{
UEFIVendor: "fedora",
BasePlatform: platform.BasePlatform{
ImageFormat: platform.FORMAT_RAW,
},
},
rawImgType,
diskRawImgType,
)

aarch64.addImageTypes(
&platform.Aarch64{
UEFIVendor: "fedora",
BasePlatform: platform.BasePlatform{
ImageFormat: platform.FORMAT_RAW,
FirmwarePackages: []string{
"uboot-images-armv8", // ??
"bcm283x-firmware",
"arm-image-installer", // ??
},
},
},
rawImgType,
isoLiveImgType,
)

rd.addArches(x86_64, aarch64)
Expand Down
22 changes: 16 additions & 6 deletions pkg/distro/fedora_ng/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ func TestFilenameFromType(t *testing.T) {
want wantResult
}{
{
name: "raw",
args: args{"raw"},
name: "disk-raw",
args: args{"disk-raw"},
want: wantResult{
filename: "raw.img",
mimeType: "application/disk",
},
},
{
name: "iso-live",
args: args{"iso-live"},
want: wantResult{
filename: "live.iso",
mimeType: "application/x-iso9660-image",
},
},
}
for _, dist := range fedoraFamilyDistros {
t.Run(dist.name, func(t *testing.T) {
Expand Down Expand Up @@ -136,13 +144,13 @@ func TestImageType_Name(t *testing.T) {
{
arch: "x86_64",
imgNames: []string{
"raw",
"disk-raw",
},
},
{
arch: "aarch64",
imgNames: []string{
"raw",
"disk-raw",
},
},
}
Expand Down Expand Up @@ -206,13 +214,15 @@ func TestArchitecture_ListImageTypes(t *testing.T) {
{
arch: "x86_64",
imgNames: []string{
"raw",
"disk-raw",
"iso-live",
},
},
{
arch: "aarch64",
imgNames: []string{
"raw",
"disk-raw",
"iso-live",
},
},
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/distro/fedora_ng/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/rand"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/oscap"
"github.com/osbuild/images/internal/users"
"github.com/osbuild/images/internal/workload"
Expand Down Expand Up @@ -221,3 +222,37 @@ func diskImage(workload workload.Workload,

return img, nil
}

func liveImage(workload workload.Workload,
t *imageType,
customizations *blueprint.Customizations,
options distro.ImageOptions,
packageSets map[string]rpmmd.PackageSet,
containers []container.SourceSpec,
rng *rand.Rand) (image.ImageKind, error) {

img := image.NewLiveImage()
img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], containers, customizations)
img.Environment = t.environment
img.Workload = workload

d := t.arch.distro

img.ISOLabelTempl = d.isolabelTmpl
img.Product = d.product
img.OSName = "fedora"
img.OSVersion = d.osVersion
img.Release = fmt.Sprintf("%s %s", d.product, d.osVersion)

// yolo!
img.OSCustomizations.Users = []users.User{
{Name: "root", Password: common.ToPtr("foobar")},
}

// TODO: move generation into LiveImage

img.Filename = t.Filename()

return img, nil
}
23 changes: 23 additions & 0 deletions pkg/distro/fedora_ng/package_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fedora_ng
// This file defines package sets that are used by more than one image type.

import (
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
)

Expand All @@ -13,3 +14,25 @@ func corePackageSet(t *imageType) rpmmd.PackageSet {
},
}
}

func diskRawPackageSet(t *imageType) rpmmd.PackageSet {
return corePackageSet(t)
}

func isoLivePackageSet(t *imageType) rpmmd.PackageSet {
ps := corePackageSet(t)

ps = ps.Append(rpmmd.PackageSet{
Include: []string{"livesys-scripts", "fedora-logos", "dracut-live"},
})

// XXX I wonder if this has to be here or in the build? We only copy it to
// XXX the correct place.
if t.arch.Name() == platform.ARCH_X86_64.String() {
ps = ps.Append(rpmmd.PackageSet{
Include: []string{"syslinux-nonlinux"},
})
}

return ps
}
120 changes: 120 additions & 0 deletions pkg/image/live.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package image

import (
"fmt"
"math/rand"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/environment"
"github.com/osbuild/images/internal/workload"
"github.com/osbuild/images/pkg/artifact"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/runner"
)

type LiveImage struct {
Base
Platform platform.Platform
Environment environment.Environment
Workload workload.Workload

ExtraBasePackages rpmmd.PackageSet

ISOLabelTempl string
Product string
Variant string
OSName string
OSVersion string
Release string

Filename string

AdditionalKernelOpts []string
OSCustomizations manifest.OSCustomizations
}

func NewLiveImage() *LiveImage {
return &LiveImage{
Base: NewBase("live-media"),
}
}

func (img *LiveImage) InstantiateManifest(m *manifest.Manifest,
repos []rpmmd.RepoConfig,
runner runner.Runner,
rng *rand.Rand) (*artifact.Artifact, error) {
buildPipeline := manifest.NewBuild(m, runner, repos)
buildPipeline.Checkpoint()

osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload

rootfsPartitionTable := &disk.PartitionTable{
Size: 20 * common.MebiByte,
Partitions: []disk.Partition{
{
Start: 0,
Size: 20 * common.MebiByte,
Payload: &disk.Filesystem{
Type: "vfat",
Mountpoint: "/",
UUID: disk.NewVolIDFromRand(rng),
},
},
},
}

// TODO: replace isoLabelTmpl with more high-level properties
isoLabel := fmt.Sprintf(img.ISOLabelTempl, img.Platform.GetArch())

rootfsImagePipeline := manifest.NewISORootfsImg(m, buildPipeline, osPipeline)
rootfsImagePipeline.Size = 8 * common.GibiByte

bootTreePipeline := manifest.NewEFIBootTree(m, buildPipeline, img.Product, img.OSVersion)
bootTreePipeline.Platform = img.Platform
bootTreePipeline.UEFIVendor = img.Platform.GetUEFIVendor()
bootTreePipeline.ISOLabel = isoLabel

kernelOpts := []string{
fmt.Sprintf("root=live:CDLABEL=%s", isoLabel),
"rd.live.image",
"quiet",
"rhgb",
}

kernelOpts = append(kernelOpts, img.AdditionalKernelOpts...)

bootTreePipeline.KernelOpts = kernelOpts

// enable ISOLinux on x86_64 only
isoLinuxEnabled := img.Platform.GetArch() == platform.ARCH_X86_64

isoTreePipeline := manifest.NewLiveTree(m,
buildPipeline,
osPipeline,
rootfsImagePipeline,
bootTreePipeline,
isoLabel)
isoTreePipeline.PartitionTable = rootfsPartitionTable
isoTreePipeline.Release = img.Release
isoTreePipeline.OSName = img.OSName

isoTreePipeline.KernelOpts = kernelOpts
isoTreePipeline.ISOLinux = isoLinuxEnabled

isoTreePipeline.Product = img.Product
isoTreePipeline.Version = img.OSVersion

isoPipeline := manifest.NewISO(m, buildPipeline, isoTreePipeline, isoLabel)
isoPipeline.Filename = img.Filename
isoPipeline.ISOLinux = isoLinuxEnabled

artifact := isoPipeline.Export()

return artifact, nil
}
Loading

0 comments on commit ec7bfdf

Please sign in to comment.