Skip to content

Commit

Permalink
distro/fedora: add coreosImage function
Browse files Browse the repository at this point in the history
A new image functions called coreosImage() that requires a container
source and creates a qcow2 image from a CoreOS ostree container.
Based on the example manifest added in osbuild/osbuild#1402
  • Loading branch information
achilleas-k committed Nov 9, 2023
1 parent c2ca1a4 commit 6799523
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions pkg/distro/fedora/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,82 @@ func iotSimplifiedInstallerImage(workload workload.Workload,
return img, nil
}

func coreosImage(workload workload.Workload,
t *imageType,
bp *blueprint.Blueprint,
options distro.ImageOptions,
_ map[string]rpmmd.PackageSet,
_ []container.SourceSpec,
rng *rand.Rand) (image.ImageKind, error) {

container, ref, err := makeOSTreePayloadContainer(options.OSTree, t.OSTreeRef())
if err != nil {
return nil, fmt.Errorf("%s: %s", t.Name(), err.Error())
}
img := image.NewOSTreeContainerDiskImage(container, ref)

distro := t.Arch().Distro()

customizations := bp.Customizations
img.Users = users.UsersFromBP(customizations.GetUsers())
img.Groups = users.GroupsFromBP(customizations.GetGroups())

img.Directories, err = blueprint.DirectoryCustomizationsToFsNodeDirectories(customizations.GetDirectories())
if err != nil {
return nil, err
}
img.Files, err = blueprint.FileCustomizationsToFsNodeFiles(customizations.GetFiles())
if err != nil {
return nil, err
}

img.KernelOptionsAppend = []string{
"rw",
"console=tty0",
"console=ttyS0",
}
img.Keyboard = "us"
img.Locale = "C.UTF-8"

img.SysrootReadOnly = true

img.Platform = t.platform
img.Workload = workload

img.OSName = "fedora-coreos"
img.Remote = ostree.Remote{
Name: "fedora",
}

if !common.VersionLessThan(distro.Releasever(), "38") {
switch img.Platform.GetImageFormat() {
case platform.FORMAT_RAW:
img.IgnitionPlatform = "metal"
if bpIgnition := customizations.GetIgnition(); bpIgnition != nil && bpIgnition.FirstBoot != nil && bpIgnition.FirstBoot.ProvisioningURL != "" {
img.KernelOptionsAppend = append(img.KernelOptionsAppend, "ignition.config.url="+bpIgnition.FirstBoot.ProvisioningURL)
}
case platform.FORMAT_QCOW2:
img.IgnitionPlatform = "qemu"
}
}

if kopts := customizations.GetKernel(); kopts != nil && kopts.Append != "" {
img.KernelOptionsAppend = append(img.KernelOptionsAppend, kopts.Append)
}

// TODO: move generation into LiveImage
pt, err := t.getPartitionTable(customizations.GetFilesystems(), options, rng)
if err != nil {
return nil, err
}
img.PartitionTable = pt

img.Filename = t.Filename()
img.Compression = t.compression

return img, nil
}

// Create an ostree SourceSpec to define an ostree parent commit using the user
// options and the default ref for the image type. Additionally returns the
// ref to be used for the new commit to be created.
Expand Down Expand Up @@ -695,6 +771,26 @@ func makeOSTreePayloadCommit(options *ostree.ImageOptions, defaultRef string) (o
}, nil
}

// Create a container Sourcespec to define an encapsulated ostree payload using
// the user options and the default ref for the image type.
func makeOSTreePayloadContainer(options *ostree.ImageOptions, defaultRef string) (container.SourceSpec, string, error) {
if options == nil || options.Container == "" {
return container.SourceSpec{}, "", fmt.Errorf("ostree container source required")
}

ref := defaultRef
if options.ImageRef != "" {
// user option overrides default ref
ref = options.ImageRef
}

return container.SourceSpec{
Source: options.Container,
Name: options.Container,
TLSVerify: options.TLSVerify,
}, ref, nil
}

// initialSetupKickstart returns the File configuration for a kickstart file
// that's required to enable initial-setup to run on first boot.
func initialSetupKickstart() *fsnode.File {
Expand Down

0 comments on commit 6799523

Please sign in to comment.