Skip to content

Commit

Permalink
manifest: call Manifest.addPipeline() in Build.addDependent()
Browse files Browse the repository at this point in the history
Pipeline constructors that require a build pipeline all add themselves
to the build pipeline's dependents using the Build.addDependent()
method.

All our pipelines (except Build) must define a build pipeline (we always
call Build.addDependent() in their constructors) and the build pipeline
must always have a manifest associated with it if it will have
dependencies.  So now when we create a new pipeline, for example
NewOS(), we don't need to specify the manifest that the pipeline will be
added to because the pipeline constructor *requires* a build pipeline to
depend on and it *must* share a manifest reference with that pipeline
(i.e. the build and OS pipelines must belong to the same manifest if one
depends on the other).
  • Loading branch information
achilleas-k authored and thozza committed Jan 8, 2024
1 parent 3225117 commit d04b0ff
Show file tree
Hide file tree
Showing 36 changed files with 47 additions and 69 deletions.
2 changes: 1 addition & 1 deletion cmd/osbuild-playground/my-container.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (img *MyContainer) InstantiateManifest(m *manifest.Manifest,
build.Checkpoint()

// create a minimal non-bootable OS tree
os := manifest.NewOS(m, build, &platform.X86{}, repos)
os := manifest.NewOS(build, &platform.X86{}, repos)
os.ExtraBasePackages = []string{"@core"}
os.OSCustomizations.Language = "en_US.UTF-8"
os.OSCustomizations.Hostname = "my-host"
Expand Down
2 changes: 1 addition & 1 deletion cmd/osbuild-playground/my-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (img *MyImage) InstantiateManifest(m *manifest.Manifest,
}

// create a minimal bootable OS tree
os := manifest.NewOS(m, build, platform, repos)
os := manifest.NewOS(build, platform, repos)
os.PartitionTable = pt // we need a partition table
os.KernelName = "kernel" // use the default fedora kernel

Expand Down
7 changes: 4 additions & 3 deletions pkg/image/anaconda_container_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ func (img *AnacondaContainerInstaller) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, &manifest.BuildOptions{ContainerBuildable: true})
buildPipeline.Checkpoint()

anacondaPipeline := manifest.NewAnacondaInstaller(m,
anacondaPipeline := manifest.NewAnacondaInstaller(
manifest.AnacondaInstallerTypePayload,
buildPipeline,
img.Platform,
repos,
"kernel",
img.Product,
img.OSVersion)
img.OSVersion,
)

// This is only built with ELN for now
anacondaPipeline.UseRHELLoraxTemplates = true
Expand Down Expand Up @@ -109,7 +110,7 @@ func (img *AnacondaContainerInstaller) InstantiateManifest(m *manifest.Manifest,
rootfsImagePipeline := manifest.NewISORootfsImg(buildPipeline, anacondaPipeline)
rootfsImagePipeline.Size = 4 * common.GibiByte

bootTreePipeline := manifest.NewEFIBootTree(m, buildPipeline, img.Product, img.OSVersion)
bootTreePipeline := manifest.NewEFIBootTree(buildPipeline, img.Product, img.OSVersion)
bootTreePipeline.Platform = img.Platform
bootTreePipeline.UEFIVendor = img.Platform.GetUEFIVendor()
bootTreePipeline.ISOLabel = isoLabel
Expand Down
7 changes: 4 additions & 3 deletions pkg/image/anaconda_live_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ func (img *AnacondaLiveInstaller) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

livePipeline := manifest.NewAnacondaInstaller(m,
livePipeline := manifest.NewAnacondaInstaller(
manifest.AnacondaInstallerTypeLive,
buildPipeline,
img.Platform,
repos,
"kernel",
img.Product,
img.OSVersion)
img.OSVersion,
)

livePipeline.ExtraPackages = img.ExtraBasePackages.Include
livePipeline.ExcludePackages = img.ExtraBasePackages.Exclude
Expand Down Expand Up @@ -87,7 +88,7 @@ func (img *AnacondaLiveInstaller) InstantiateManifest(m *manifest.Manifest,
rootfsImagePipeline := manifest.NewISORootfsImg(buildPipeline, livePipeline)
rootfsImagePipeline.Size = 8 * common.GibiByte

bootTreePipeline := manifest.NewEFIBootTree(m, buildPipeline, img.Product, img.OSVersion)
bootTreePipeline := manifest.NewEFIBootTree(buildPipeline, img.Product, img.OSVersion)
bootTreePipeline.Platform = img.Platform
bootTreePipeline.UEFIVendor = img.Platform.GetUEFIVendor()
bootTreePipeline.ISOLabel = isoLabel
Expand Down
7 changes: 4 additions & 3 deletions pkg/image/anaconda_ostree_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ func (img *AnacondaOSTreeInstaller) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

anacondaPipeline := manifest.NewAnacondaInstaller(m,
anacondaPipeline := manifest.NewAnacondaInstaller(
manifest.AnacondaInstallerTypePayload,
buildPipeline,
img.Platform,
repos,
"kernel",
img.Product,
img.OSVersion)
img.OSVersion,
)
anacondaPipeline.ExtraPackages = img.ExtraBasePackages.Include
anacondaPipeline.ExcludePackages = img.ExtraBasePackages.Exclude
anacondaPipeline.ExtraRepos = img.ExtraBasePackages.Repositories
Expand Down Expand Up @@ -103,7 +104,7 @@ func (img *AnacondaOSTreeInstaller) InstantiateManifest(m *manifest.Manifest,
rootfsImagePipeline := manifest.NewISORootfsImg(buildPipeline, anacondaPipeline)
rootfsImagePipeline.Size = 4 * common.GibiByte

bootTreePipeline := manifest.NewEFIBootTree(m, buildPipeline, img.Product, img.OSVersion)
bootTreePipeline := manifest.NewEFIBootTree(buildPipeline, img.Product, img.OSVersion)
bootTreePipeline.Platform = img.Platform
bootTreePipeline.UEFIVendor = img.Platform.GetUEFIVendor()
bootTreePipeline.ISOLabel = isoLabel
Expand Down
9 changes: 5 additions & 4 deletions pkg/image/anaconda_tar_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ func (img *AnacondaTarInstaller) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

anacondaPipeline := manifest.NewAnacondaInstaller(m,
anacondaPipeline := manifest.NewAnacondaInstaller(
manifest.AnacondaInstallerTypePayload,
buildPipeline,
img.Platform,
repos,
"kernel",
img.Product,
img.OSVersion)
img.OSVersion,
)

anacondaPipeline.ExtraPackages = img.ExtraBasePackages.Include
anacondaPipeline.ExcludePackages = img.ExtraBasePackages.Exclude
Expand Down Expand Up @@ -122,7 +123,7 @@ func (img *AnacondaTarInstaller) InstantiateManifest(m *manifest.Manifest,
rootfsImagePipeline := manifest.NewISORootfsImg(buildPipeline, anacondaPipeline)
rootfsImagePipeline.Size = 4 * common.GibiByte

bootTreePipeline := manifest.NewEFIBootTree(m, buildPipeline, img.Product, img.OSVersion)
bootTreePipeline := manifest.NewEFIBootTree(buildPipeline, img.Product, img.OSVersion)
bootTreePipeline.Platform = img.Platform
bootTreePipeline.UEFIVendor = img.Platform.GetUEFIVendor()
bootTreePipeline.ISOLabel = isoLabel
Expand All @@ -137,7 +138,7 @@ func (img *AnacondaTarInstaller) InstantiateManifest(m *manifest.Manifest,
kernelOpts = append(kernelOpts, img.AdditionalKernelOpts...)
bootTreePipeline.KernelOpts = kernelOpts

osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline := manifest.NewOS(buildPipeline, img.Platform, repos)
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (img *Archive) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline := manifest.NewOS(buildPipeline, img.Platform, repos)
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (img *BaseContainer) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline := manifest.NewOS(buildPipeline, img.Platform, repos)
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (img *DiskImage) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline := manifest.NewOS(buildPipeline, img.Platform, repos)
osPipeline.PartitionTable = img.PartitionTable
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/ostree_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (img *OSTreeArchive) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline := manifest.NewOS(buildPipeline, img.Platform, repos)
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
Expand Down
7 changes: 4 additions & 3 deletions pkg/image/ostree_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (img *OSTreeContainer) InstantiateManifest(m *manifest.Manifest,
buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

osPipeline := manifest.NewOS(m, buildPipeline, img.Platform, repos)
osPipeline := manifest.NewOS(buildPipeline, img.Platform, repos)
osPipeline.OSCustomizations = img.OSCustomizations
osPipeline.Environment = img.Environment
osPipeline.Workload = img.Workload
Expand All @@ -60,13 +60,14 @@ func (img *OSTreeContainer) InstantiateManifest(m *manifest.Manifest,
nginxConfigPath := "/etc/nginx.conf"
listenPort := "8080"

serverPipeline := manifest.NewOSTreeCommitServer(m,
serverPipeline := manifest.NewOSTreeCommitServer(
buildPipeline,
img.Platform,
repos,
commitPipeline,
nginxConfigPath,
listenPort)
listenPort,
)
serverPipeline.Language = img.ContainerLanguage

containerPipeline := manifest.NewOCIContainer(buildPipeline, serverPipeline)
Expand Down
8 changes: 4 additions & 4 deletions pkg/image/ostree_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func NewOSTreeDiskImageFromContainer(container container.SourceSpec, ref string)
}
}

func baseRawOstreeImage(img *OSTreeDiskImage, m *manifest.Manifest, buildPipeline *manifest.Build) *manifest.RawOSTreeImage {
func baseRawOstreeImage(img *OSTreeDiskImage, buildPipeline *manifest.Build) *manifest.RawOSTreeImage {
var osPipeline *manifest.OSTreeDeployment
switch {
case img.CommitSource != nil:
osPipeline = manifest.NewOSTreeCommitDeployment(buildPipeline, m, img.CommitSource, img.OSName, img.Platform)
osPipeline = manifest.NewOSTreeCommitDeployment(buildPipeline, img.CommitSource, img.OSName, img.Platform)
case img.ContainerSource != nil:
osPipeline = manifest.NewOSTreeContainerDeployment(buildPipeline, m, img.ContainerSource, img.Ref, img.OSName, img.Platform)
osPipeline = manifest.NewOSTreeContainerDeployment(buildPipeline, img.ContainerSource, img.Ref, img.OSName, img.Platform)
default:
panic("no content source defined for ostree image")
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (img *OSTreeDiskImage) InstantiateManifest(m *manifest.Manifest,
panic(fmt.Sprintf("no compression is allowed with %q format for %q", imgFormat, img.name))
}

baseImage := baseRawOstreeImage(img, m, buildPipeline)
baseImage := baseRawOstreeImage(img, buildPipeline)
switch img.Platform.GetImageFormat() {
case platform.FORMAT_VMDK:
vmdkPipeline := manifest.NewVMDK(buildPipeline, baseImage)
Expand Down
9 changes: 5 additions & 4 deletions pkg/image/ostree_simplified_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ func (img *OSTreeSimplifiedInstaller) InstantiateManifest(m *manifest.Manifest,
imageFilename := "image.raw.xz"

// image in simplified installer is always compressed
compressedImage := manifest.NewXZ(buildPipeline, baseRawOstreeImage(img.rawImage, m, buildPipeline))
compressedImage := manifest.NewXZ(buildPipeline, baseRawOstreeImage(img.rawImage, buildPipeline))
compressedImage.SetFilename(imageFilename)

coiPipeline := manifest.NewCoreOSInstaller(m,
coiPipeline := manifest.NewCoreOSInstaller(
buildPipeline,
img.Platform,
repos,
"kernel",
img.Product,
img.OSVersion)
img.OSVersion,
)
coiPipeline.ExtraPackages = img.ExtraBasePackages.Include
coiPipeline.ExcludePackages = img.ExtraBasePackages.Exclude
coiPipeline.ExtraRepos = img.ExtraBasePackages.Repositories
Expand All @@ -100,7 +101,7 @@ func (img *OSTreeSimplifiedInstaller) InstantiateManifest(m *manifest.Manifest,

isoLabel := fmt.Sprintf(img.ISOLabelTempl, img.Platform.GetArch())

bootTreePipeline := manifest.NewEFIBootTree(m, buildPipeline, img.Product, img.OSVersion)
bootTreePipeline := manifest.NewEFIBootTree(buildPipeline, img.Product, img.OSVersion)
bootTreePipeline.Platform = img.Platform
bootTreePipeline.UEFIVendor = img.Platform.GetUEFIVendor()
bootTreePipeline.ISOLabel = isoLabel
Expand Down
4 changes: 1 addition & 3 deletions pkg/manifest/anaconda_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ type AnacondaInstaller struct {
UseRHELLoraxTemplates bool
}

func NewAnacondaInstaller(m *Manifest,
installerType AnacondaInstallerType,
func NewAnacondaInstaller(installerType AnacondaInstallerType,
buildPipeline *Build,
platform platform.Platform,
repos []rpmmd.RepoConfig,
Expand All @@ -96,7 +95,6 @@ func NewAnacondaInstaller(m *Manifest,
version: version,
}
buildPipeline.addDependent(p)
m.addPipeline(p)
return p
}

Expand Down
1 change: 0 additions & 1 deletion pkg/manifest/anaconda_installer_iso_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func NewAnacondaInstallerISOTree(buildPipeline *Build, anacondaPipeline *Anacond
isoLabel: bootTreePipeline.ISOLabel,
}
buildPipeline.addDependent(p)
anacondaPipeline.Manifest().addPipeline(p)
return p
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/manifest/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func NewBuild(m *Manifest, runner runner.Runner, repos []rpmmd.RepoConfig, opts

func (p *Build) addDependent(dep Pipeline) {
p.dependents = append(p.dependents, dep)
man := p.Manifest()
if man == nil {
panic("cannot add build dependent without a manifest")
}
man.addPipeline(dep)
}

func (p *Build) getPackageSetChain(distro Distro) []rpmmd.PackageSet {
Expand Down
1 change: 0 additions & 1 deletion pkg/manifest/coi_iso_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func NewCoreOSISOTree(
isoLabel: bootTreePipeline.ISOLabel,
}
buildPipeline.addDependent(p)
coiPipeline.Manifest().addPipeline(p)
return p
}

Expand Down
1 change: 0 additions & 1 deletion pkg/manifest/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func NewOSTreeCommit(buildPipeline *Build, treePipeline *OS, ref string) *OSTree
ref: ref,
}
buildPipeline.addDependent(p)
treePipeline.Manifest().addPipeline(p)
return p
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/manifest/commit_server_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ type OSTreeCommitServer struct {
// is a pipeline producing an ostree commit to be served. nginxConfigPath
// is the path to the main nginx config file and listenPort is the port
// nginx will be listening on.
func NewOSTreeCommitServer(m *Manifest,
buildPipeline *Build,
func NewOSTreeCommitServer(buildPipeline *Build,
platform platform.Platform,
repos []rpmmd.RepoConfig,
commitPipeline *OSTreeCommit,
Expand All @@ -53,11 +52,7 @@ func NewOSTreeCommitServer(m *Manifest,
listenPort: listenPort,
Language: "en_US",
}
if commitPipeline.Base.manifest != m {
panic("commit pipeline from different manifest")
}
buildPipeline.addDependent(p)
m.addPipeline(p)
return p
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/manifest/coreos_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ type CoreOSInstaller struct {
}

// NewCoreOSInstaller creates an CoreOS installer pipeline object.
func NewCoreOSInstaller(m *Manifest,
buildPipeline *Build,
func NewCoreOSInstaller(buildPipeline *Build,
platform platform.Platform,
repos []rpmmd.RepoConfig,
kernelName,
Expand All @@ -64,7 +63,6 @@ func NewCoreOSInstaller(m *Manifest,
version: version,
}
buildPipeline.addDependent(p)
m.addPipeline(p)
return p
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/manifest/efi_boot_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ type EFIBootTree struct {
KernelOpts []string
}

func NewEFIBootTree(m *Manifest, buildPipeline *Build, product, version string) *EFIBootTree {
func NewEFIBootTree(buildPipeline *Build, product, version string) *EFIBootTree {
p := &EFIBootTree{
Base: NewBase("efiboot-tree", buildPipeline),
product: product,
version: version,
}
buildPipeline.addDependent(p)
m.addPipeline(p)
return p
}

Expand Down
1 change: 0 additions & 1 deletion pkg/manifest/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func NewISO(buildPipeline *Build, treePipeline Pipeline, isoLabel string) *ISO {
isoLabel: isoLabel,
}
buildPipeline.addDependent(p)
treePipeline.Manifest().addPipeline(p)
return p
}

Expand Down
1 change: 0 additions & 1 deletion pkg/manifest/iso_rootfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewISORootfsImg(buildPipeline *Build, installerPipeline Pipeline) *ISORootf
installerPipeline: installerPipeline,
}
buildPipeline.addDependent(p)
installerPipeline.Manifest().addPipeline(p)
return p
}

Expand Down
1 change: 0 additions & 1 deletion pkg/manifest/oci_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func NewOCIContainer(buildPipeline *Build, treePipeline TreePipeline) *OCIContai
filename: "oci-archive.tar",
}
buildPipeline.addDependent(p)
treePipeline.Manifest().addPipeline(p)
return p
}

Expand Down
Loading

0 comments on commit d04b0ff

Please sign in to comment.