distro/rhel85: introduce the vhd image type

This commit is contained in:
Achilleas Koutsou 2021-07-07 19:11:19 +02:00 committed by Ondřej Budai
parent 3eae16badb
commit 1ed9008785
5 changed files with 110 additions and 14 deletions

View file

@ -427,7 +427,7 @@ func newDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
exports: []string{"bootiso"},
}
qcow2ImageType := imageType{
qcow2ImgType := imageType{
name: "qcow2",
filename: "disk.qcow2",
mimeType: "application/x-qemu-disk",
@ -442,6 +442,25 @@ func newDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
exports: []string{"qcow2"},
}
vhdImgType := imageType{
name: "vhd",
filename: "disk.vhd",
mimeType: "application/x-vhd",
packageSets: map[string]rpmmd.PackageSet{
"packages": vhdCommonPackageSet(),
},
enabledServices: []string{
"sshd",
"waagent",
},
defaultTarget: "multi-user.target",
kernelOptions: "ro biosdevname=0 rootdelay=300 console=ttyS0 earlyprintk=ttyS0 net.ifnames=0",
bootable: true,
defaultSize: 4 * GigaByte,
pipelines: vhdPipelines,
exports: []string{"vhd"},
}
tarImgType := imageType{
name: "tar",
filename: "root.tar.xz",
@ -501,10 +520,11 @@ func newDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
exports: []string{"container"},
}
x86_64.addImageTypes(qcow2ImageType, tarImgType, tarInstallerImgTypeX86_64, edgeCommitImgTypeX86_64, edgeInstallerImgTypeX86_64, edgeOCIImgTypeX86_64)
aarch64.addImageTypes(qcow2ImageType, tarImgType, edgeCommitImgTypeAarch64, edgeOCIImgTypeAarch64)
ppc64le.addImageTypes(qcow2ImageType, tarImgType)
s390x.addImageTypes(qcow2ImageType, tarImgType)
x86_64.addImageTypes(qcow2ImgType, vhdImgType, tarImgType, tarInstallerImgTypeX86_64, edgeCommitImgTypeX86_64, edgeInstallerImgTypeX86_64, edgeOCIImgTypeX86_64)
aarch64.addImageTypes(qcow2ImgType, tarImgType, edgeCommitImgTypeAarch64, edgeOCIImgTypeAarch64)
ppc64le.addImageTypes(qcow2ImgType, tarImgType)
s390x.addImageTypes(qcow2ImgType, tarImgType)
rd.addArches(x86_64, aarch64, ppc64le, s390x)
return rd
}

View file

@ -152,6 +152,22 @@ func qcow2CommonPackageSet() rpmmd.PackageSet {
}
}
func vhdCommonPackageSet() rpmmd.PackageSet {
return rpmmd.PackageSet{
Include: []string{
// Defaults
"@Core", "langpacks-en",
// From the lorax kickstart
"selinux-policy-targeted", "chrony", "WALinuxAgent", "python3",
"net-tools", "cloud-init", "cloud-utils-growpart", "gdisk",
},
Exclude: []string{
"dracut-config-rescue", "rng-tools",
},
}
}
// edge commit OS package set
func edgeCommitCommonPackageSet() rpmmd.PackageSet {
return rpmmd.PackageSet{

View file

@ -55,12 +55,49 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti
imagePipeline := liveImagePipeline(treePipeline.Name, diskfile, &partitionTable, t.arch.legacy)
pipelines = append(pipelines, *imagePipeline)
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename)
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, "qcow2", "0.10")
pipelines = append(pipelines, *qemuPipeline)
return pipelines, nil
}
func vhdPipelines(t *imageType, customizations *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSetSpecs map[string][]rpmmd.PackageSpec, rng *rand.Rand) ([]osbuild.Pipeline, error) {
pipelines := make([]osbuild.Pipeline, 0)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs["build"]))
treePipeline, err := osPipeline(repos, packageSetSpecs["packages"], customizations, options, t.enabledServices, t.disabledServices, t.defaultTarget)
if err != nil {
return nil, err
}
if options.Subscription != nil {
commands := []string{
fmt.Sprintf("/usr/sbin/subscription-manager register --org=%d --activationkey=%s --serverurl %s --baseurl %s", options.Subscription.Organization, options.Subscription.ActivationKey, options.Subscription.ServerUrl, options.Subscription.BaseUrl),
}
if options.Subscription.Insights {
commands = append(commands, "/usr/bin/insights-client --register")
}
treePipeline.AddStage(osbuild.NewFirstBootStage(&osbuild.FirstBootStageOptions{
Commands: commands,
WaitForNetwork: true,
},
))
}
partitionTable := defaultPartitionTable(options, t.arch, rng)
treePipeline.AddStage(osbuild.NewFSTabStage(partitionTable.FSTabStageOptionsV2()))
treePipeline.AddStage(osbuild.NewGRUB2Stage(grub2StageOptions(&partitionTable, t.kernelOptions, customizations.GetKernel(), packageSetSpecs["packages"], t.arch.uefi, t.arch.legacy)))
pipelines = append(pipelines, *treePipeline)
diskfile := "disk.img"
imagePipeline := liveImagePipeline(treePipeline.Name, diskfile, &partitionTable, t.arch.legacy)
pipelines = append(pipelines, *imagePipeline)
if err != nil {
return nil, err
}
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, "vpc", "")
pipelines = append(pipelines, *qemuPipeline)
return pipelines, nil
}
func tarPipelines(t *imageType, customizations *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSetSpecs map[string][]rpmmd.PackageSpec, rng *rand.Rand) ([]osbuild.Pipeline, error) {
pipelines := make([]osbuild.Pipeline, 0)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs["build"]))
@ -581,12 +618,12 @@ func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild2.Sta
return stages
}
func qemuPipeline(inputPipelineName string, inputFilename, outputFilename string) *osbuild.Pipeline {
func qemuPipeline(inputPipelineName, inputFilename, outputFilename, format, qcow2Compat string) *osbuild.Pipeline {
p := new(osbuild.Pipeline)
p.Name = "qcow2"
p.Name = format
p.Build = "name:build"
qemuStage := osbuild.NewQEMUStage(qemuStageOptions(outputFilename), qemuStageInputs(inputPipelineName, inputFilename))
qemuStage := osbuild.NewQEMUStage(qemuStageOptions(outputFilename, format, qcow2Compat), qemuStageInputs(inputPipelineName, inputFilename))
p.AddStage(qemuStage)
return p
}

View file

@ -465,12 +465,24 @@ func grub2InstStageOptions(filename string, pt *disk.PartitionTable, platform st
}
}
func qemuStageOptions(filename string) *osbuild.QEMUStageOptions {
func qemuStageOptions(filename, format, compat string) *osbuild.QEMUStageOptions {
var options osbuild.QEMUFormatOptions
switch format {
case "qcow2":
options = osbuild.Qcow2Options{
Type: "qcow2",
Compat: compat,
}
case "vpc":
options = osbuild.VPCOptions{
Type: "vpc",
}
default:
panic("unknown format in qemu stage: " + format)
}
return &osbuild.QEMUStageOptions{
Filename: filename,
Format: osbuild.Qcow2Options{
Type: "qcow2",
Compat: "0.10",
},
Format: options,
}
}

View file

@ -32,6 +32,13 @@ type Qcow2Options struct {
func (Qcow2Options) isQEMUFormatOptions() {}
type VPCOptions struct {
// The type of the format must be 'vpc'
Type string `json:"type"`
}
func (VPCOptions) isQEMUFormatOptions() {}
func (QEMUStageOptions) isStageOptions() {}
type QEMUStageInputs struct {
@ -77,6 +84,10 @@ func (options QEMUStageOptions) MarshalJSON() ([]byte, error) {
if o.Type != "qcow2" {
return nil, fmt.Errorf("invalid format type %q for qcow2 options", o.Type)
}
case VPCOptions:
if o.Type != "vpc" {
return nil, fmt.Errorf("invalid format type %q for vpc options", o.Type)
}
default:
return nil, fmt.Errorf("unknown format options in QEMU stage: %#v", options.Format)
}