pipeline: distinguish between optional and mandatory properties

The ideal is that the constructor takes mandatory properties as arguments, and fields in the struct
are all optional.

This clarifies that across the pipelines (or leaves TODOs where work remains), and where possible
makes fields optional by providing a valid default value.
This commit is contained in:
Tom Gundersen 2022-06-26 21:20:25 +01:00
parent c001af63ec
commit 1fa92f9091
7 changed files with 63 additions and 52 deletions

View file

@ -202,8 +202,9 @@ func osPipeline(buildPipeline *pipeline.BuildPipeline,
pl := pipeline.NewOSPipeline(buildPipeline, t.rpmOstree, options.OSTree.Parent, repos, packages, pt, bootLoader, t.arch.legacy, c.GetKernel().Name)
pl.UEFI = t.supportsUEFI()
pl.Vendor = t.arch.distro.vendor
if t.supportsUEFI() {
pl.UEFIVendor = t.arch.distro.vendor
}
var kernelOptions []string
if t.kernelOptions != "" {
@ -295,11 +296,7 @@ func ostreeCommitPipeline(buildPipeline *pipeline.BuildPipeline, treePipeline *p
}
func containerTreePipeline(buildPipeline *pipeline.BuildPipeline, commitPipeline *pipeline.OSTreeCommitPipeline, repos []rpmmd.RepoConfig, packages []rpmmd.PackageSpec, options distro.ImageOptions, c *blueprint.Customizations, nginxConfigPath, listenPort string) pipeline.OSTreeCommitServerTreePipeline {
p := pipeline.NewOSTreeCommitServerTreePipeline(buildPipeline, commitPipeline)
p.Repos = repos
p.PackageSpecs = packages
p.NginxConfigPath = nginxConfigPath
p.ListenPort = listenPort
p := pipeline.NewOSTreeCommitServerTreePipeline(buildPipeline, repos, packages, commitPipeline, nginxConfigPath, listenPort)
language, _ := c.GetPrimaryLocale()
if language != nil {
p.Language = *language
@ -308,9 +305,7 @@ func containerTreePipeline(buildPipeline *pipeline.BuildPipeline, commitPipeline
}
func containerPipeline(buildPipeline *pipeline.BuildPipeline, treePipeline *pipeline.Pipeline, t *imageType, nginxConfigPath, listenPort string) pipeline.OCIContainerPipeline {
p := pipeline.NewOCIContainerPipeline(buildPipeline, treePipeline)
p.Architecture = t.Arch().Name()
p.Filename = t.Filename()
p := pipeline.NewOCIContainerPipeline(buildPipeline, treePipeline, t.Arch().Name(), t.Filename())
p.Cmd = []string{"nginx", "-c", nginxConfigPath}
p.ExposedPorts = []string{listenPort}
return p
@ -328,7 +323,7 @@ func bootISOTreePipeline(buildPipeline *pipeline.BuildPipeline, anacondaPipeline
p := pipeline.NewISOTreePipeline(buildPipeline, anacondaPipeline, isoLabelTempl)
p.Release = "202010217.n.0"
p.OSName = "fedora"
p.Vendor = vendor
p.UEFIVendor = vendor
p.Users = users
p.Groups = groups
p.OSTreeRef = options.OSTree.Ref
@ -338,8 +333,7 @@ func bootISOTreePipeline(buildPipeline *pipeline.BuildPipeline, anacondaPipeline
}
func bootISOPipeline(buildPipeline *pipeline.BuildPipeline, treePipeline *pipeline.ISOTreePipeline, filename string, isolinux bool) pipeline.ISOPipeline {
p := pipeline.NewISOPipeline(buildPipeline, treePipeline)
p.Filename = filename
p := pipeline.NewISOPipeline(buildPipeline, treePipeline, filename)
p.ISOLinux = isolinux
return p
}

View file

@ -19,8 +19,7 @@ type AnacondaPipeline struct {
// name network devices when booting the installer. This may affect
// the naming of network devices on the target system.
Biosdevname bool
// Variant is the variant of the product being installed.
// TODO: what should be the default value?
// Variant is the variant of the product being installed, if applicable.
Variant string
repos []rpmmd.RepoConfig

View file

@ -10,27 +10,37 @@ import (
type OSTreeCommitServerTreePipeline struct {
Pipeline
commitPipeline *OSTreeCommitPipeline
Repos []rpmmd.RepoConfig
PackageSpecs []rpmmd.PackageSpec
// TODO: should this be configurable?
Language string
NginxConfigPath string
ListenPort string
Language string
repos []rpmmd.RepoConfig
packageSpecs []rpmmd.PackageSpec
commitPipeline *OSTreeCommitPipeline
nginxConfigPath string
listenPort string
}
func NewOSTreeCommitServerTreePipeline(buildPipeline *BuildPipeline, commitPipeline *OSTreeCommitPipeline) OSTreeCommitServerTreePipeline {
func NewOSTreeCommitServerTreePipeline(buildPipeline *BuildPipeline,
repos []rpmmd.RepoConfig,
packageSpecs []rpmmd.PackageSpec,
commitPipeline *OSTreeCommitPipeline,
nginxConfigPath,
listenPort string) OSTreeCommitServerTreePipeline {
return OSTreeCommitServerTreePipeline{
Pipeline: New("container-tree", buildPipeline, nil),
commitPipeline: commitPipeline,
Language: "en_US",
Pipeline: New("container-tree", buildPipeline, nil),
repos: repos,
packageSpecs: packageSpecs,
commitPipeline: commitPipeline,
nginxConfigPath: nginxConfigPath,
listenPort: listenPort,
Language: "en_US",
}
}
func (p OSTreeCommitServerTreePipeline) Serialize() osbuild2.Pipeline {
pipeline := p.Pipeline.Serialize()
pipeline.AddStage(osbuild2.NewRPMStage(osbuild2.NewRPMStageOptions(p.Repos), osbuild2.NewRpmStageSourceFilesInputs(p.PackageSpecs)))
pipeline.AddStage(osbuild2.NewRPMStage(osbuild2.NewRPMStageOptions(p.repos), osbuild2.NewRpmStageSourceFilesInputs(p.packageSpecs)))
pipeline.AddStage(osbuild2.NewLocaleStage(&osbuild2.LocaleStageOptions{Language: p.Language}))
htmlRoot := "/usr/share/nginx/html"
@ -47,7 +57,7 @@ func (p OSTreeCommitServerTreePipeline) Serialize() osbuild2.Pipeline {
pipeline.AddStage(osbuild2.NewChmodStage(chmodStageOptions("/var/log/nginx", "a+rwX", true)))
pipeline.AddStage(osbuild2.NewChmodStage(chmodStageOptions("/var/lib/nginx", "a+rwX", true)))
pipeline.AddStage(osbuild2.NewNginxConfigStage(nginxConfigStageOptions(p.NginxConfigPath, htmlRoot, p.ListenPort)))
pipeline.AddStage(osbuild2.NewNginxConfigStage(nginxConfigStageOptions(p.nginxConfigPath, htmlRoot, p.listenPort)))
return pipeline
}

View file

@ -6,23 +6,25 @@ import (
type ISOPipeline struct {
Pipeline
ISOLinux bool
treePipeline *ISOTreePipeline
Filename string
ISOLinux bool
filename string
}
func NewISOPipeline(buildPipeline *BuildPipeline, treePipeline *ISOTreePipeline) ISOPipeline {
func NewISOPipeline(buildPipeline *BuildPipeline, treePipeline *ISOTreePipeline, filename string) ISOPipeline {
return ISOPipeline{
Pipeline: New("bootiso", buildPipeline, nil),
treePipeline: treePipeline,
filename: filename,
}
}
func (p ISOPipeline) Serialize() osbuild2.Pipeline {
pipeline := p.Pipeline.Serialize()
pipeline.AddStage(osbuild2.NewXorrisofsStage(xorrisofsStageOptions(p.Filename, p.treePipeline.ISOLabel(), p.ISOLinux), osbuild2.NewXorrisofsStagePipelineTreeInputs(p.treePipeline.Name())))
pipeline.AddStage(osbuild2.NewImplantisomd5Stage(&osbuild2.Implantisomd5StageOptions{Filename: p.Filename}))
pipeline.AddStage(osbuild2.NewXorrisofsStage(xorrisofsStageOptions(p.filename, p.treePipeline.ISOLabel(), p.ISOLinux), osbuild2.NewXorrisofsStagePipelineTreeInputs(p.treePipeline.Name())))
pipeline.AddStage(osbuild2.NewImplantisomd5Stage(&osbuild2.Implantisomd5StageOptions{Filename: p.filename}))
return pipeline
}

View file

@ -11,16 +11,17 @@ import (
type ISOTreePipeline struct {
Pipeline
anacondaPipeline *AnacondaPipeline
Vendor string
OSName string
Release string
Users []blueprint.UserCustomization
Groups []blueprint.GroupCustomization
OSTreeParent string
OSTreeRef string
// TODO: review optional and mandatory fields and their meaning
UEFIVendor string
OSName string
Release string
Users []blueprint.UserCustomization
Groups []blueprint.GroupCustomization
OSTreeParent string
OSTreeRef string
isoLabel string
anacondaPipeline *AnacondaPipeline
isoLabel string
}
func NewISOTreePipeline(buildPipeline *BuildPipeline, anacondaPipeline *AnacondaPipeline, isoLabelTmpl string) ISOTreePipeline {
@ -44,7 +45,7 @@ func (p ISOTreePipeline) Serialize() osbuild2.Pipeline {
kspath := "/osbuild.ks"
ostreeRepoPath := "/ostree/repo"
pipeline.AddStage(osbuild2.NewBootISOMonoStage(bootISOMonoStageOptions(p.anacondaPipeline.KernelVer(), p.anacondaPipeline.Arch(), p.Vendor, p.anacondaPipeline.Product(), p.anacondaPipeline.Version(), p.ISOLabel(), kspath), osbuild2.NewBootISOMonoStagePipelineTreeInputs(p.anacondaPipeline.Name())))
pipeline.AddStage(osbuild2.NewBootISOMonoStage(bootISOMonoStageOptions(p.anacondaPipeline.KernelVer(), p.anacondaPipeline.Arch(), p.UEFIVendor, p.anacondaPipeline.Product(), p.anacondaPipeline.Version(), p.ISOLabel(), kspath), osbuild2.NewBootISOMonoStagePipelineTreeInputs(p.anacondaPipeline.Name())))
kickstartOptions, err := osbuild2.NewKickstartStageOptions(kspath, "", p.Users, p.Groups, makeISORootPath(ostreeRepoPath), p.OSTreeRef, p.OSName)
if err != nil {

View file

@ -6,17 +6,20 @@ import (
type OCIContainerPipeline struct {
Pipeline
treePipeline *Pipeline
Architecture string
Filename string
Cmd []string
ExposedPorts []string
treePipeline *Pipeline
architecture string
filename string
}
func NewOCIContainerPipeline(buildPipeline *BuildPipeline, treePipeline *Pipeline) OCIContainerPipeline {
func NewOCIContainerPipeline(buildPipeline *BuildPipeline, treePipeline *Pipeline, architecture, filename string) OCIContainerPipeline {
return OCIContainerPipeline{
Pipeline: New("container", buildPipeline, nil),
treePipeline: treePipeline,
architecture: architecture,
filename: filename,
}
}
@ -24,8 +27,8 @@ func (p OCIContainerPipeline) Serialize() osbuild2.Pipeline {
pipeline := p.Pipeline.Serialize()
options := &osbuild2.OCIArchiveStageOptions{
Architecture: p.Architecture,
Filename: p.Filename,
Architecture: p.architecture,
Filename: p.filename,
Config: &osbuild2.OCIArchiveConfig{
Cmd: p.Cmd,
ExposedPorts: p.ExposedPorts,

View file

@ -25,9 +25,9 @@ type OSPipeline struct {
Pipeline
// KernelOptionsAppend are appended to the kernel commandline
KernelOptionsAppend []string
// UEFI indicates whether or not the OS should support UEFI
UEFI bool
Vendor string
// UEFIVendor indicates whether or not the OS should support UEFI and
// if set namespaces the UEFI binaries with this string.
UEFIVendor string
// GPGKeyFiles are a list of filenames in the OS which will be imported
// as GPG keys into the RPM database.
GPGKeyFiles []string
@ -103,7 +103,9 @@ func NewOSPipeline(buildPipeline *BuildPipeline,
bootLoader: bootLoader,
grubLegacy: grubLegacy,
kernelVer: kernelVer,
Language: "C.UTF-8",
Hostname: "localhost.localdomain",
Timezone: "UTC",
}
}
@ -284,7 +286,7 @@ func (p OSPipeline) Serialize() osbuild2.Pipeline {
var bootloader *osbuild2.Stage
switch p.BootLoader() {
case BOOTLOADER_GRUB:
options := osbuild2.NewGrub2StageOptionsUnified(pt, p.kernelVer, p.UEFI, p.GRUBLegacy(), p.Vendor, false)
options := osbuild2.NewGrub2StageOptionsUnified(pt, p.kernelVer, p.UEFIVendor != "", p.GRUBLegacy(), p.UEFIVendor, false)
if cfg := p.Grub2Config; cfg != nil {
// TODO: don't store Grub2Config in OSPipeline, making the overrides unnecessary
// grub2.Config.Default is owned and set by `NewGrub2StageOptionsUnified`