From 64b4ad7c31946d76379603f2bfc61085b9f3124e Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 4 Jul 2022 22:34:59 +0100 Subject: [PATCH] manifest/os: make ostree parameters optional The OSTree parameters can be set after initialisation. We should only require parameters to be set at initialisation time if we have no good defaults. In the case of OSTree the default is to not enable OSTree support. --- cmd/osbuild-playground/playground.go | 2 +- internal/distro/fedora/pipelines.go | 15 +++++++++++- internal/manifest/commit.go | 10 +++++++- internal/manifest/os.go | 36 +++++++++++++++------------- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/cmd/osbuild-playground/playground.go b/cmd/osbuild-playground/playground.go index b9acbc024..df6377f33 100644 --- a/cmd/osbuild-playground/playground.go +++ b/cmd/osbuild-playground/playground.go @@ -31,7 +31,7 @@ func MyManifest(m *manifest.Manifest, options *MyOptions, repos []rpmmd.RepoConf build := manifest.NewBuildPipeline(m, runner, repos) // create a non-bootable OS tree containing the `core` comps group - os := manifest.NewOSPipeline(m, build, false, "", "", repos, nil, manifest.BOOTLOADER_GRUB, "", "") + os := manifest.NewOSPipeline(m, build, repos, nil, manifest.BOOTLOADER_GRUB, "", "") os.ExtraBasePackages = []string{ "@core", } diff --git a/internal/distro/fedora/pipelines.go b/internal/distro/fedora/pipelines.go index 903554c4e..5b4a8c768 100644 --- a/internal/distro/fedora/pipelines.go +++ b/internal/distro/fedora/pipelines.go @@ -221,7 +221,20 @@ func osPipeline(m *manifest.Manifest, kernelName = c.GetKernel().Name } - pl := manifest.NewOSPipeline(m, buildPipeline, t.rpmOstree, options.OSTree.Parent, options.OSTree.URL, repos, pt, bootLoader, t.arch.legacy, kernelName) + pl := manifest.NewOSPipeline(m, buildPipeline, repos, pt, bootLoader, t.arch.legacy, kernelName) + + if t.rpmOstree { + var parent *manifest.OSPipelineOSTreeParent + if options.OSTree.Parent != "" && options.OSTree.URL != "" { + parent = &manifest.OSPipelineOSTreeParent{ + Checksum: options.OSTree.Parent, + URL: options.OSTree.URL, + } + } + pl.OSTree = &manifest.OSPipelineOSTree{ + Parent: parent, + } + } if len(osChain) >= 1 { pl.ExtraBasePackages = osChain[0].Include diff --git a/internal/manifest/commit.go b/internal/manifest/commit.go index 8b2bfdf1b..e22040327 100644 --- a/internal/manifest/commit.go +++ b/internal/manifest/commit.go @@ -43,6 +43,10 @@ func (p *OSTreeCommitPipeline) getBuildPackages() []string { func (p *OSTreeCommitPipeline) serialize() osbuild2.Pipeline { pipeline := p.BasePipeline.serialize() + if p.treePipeline.OSTree == nil { + panic("tree is not ostree") + } + pipeline.AddStage(osbuild2.NewOSTreeInitStage(&osbuild2.OSTreeInitStageOptions{Path: "/repo"})) commitStageInput := new(osbuild2.OSTreeCommitStageInput) @@ -50,11 +54,15 @@ func (p *OSTreeCommitPipeline) serialize() osbuild2.Pipeline { commitStageInput.Origin = "org.osbuild.pipeline" commitStageInput.References = osbuild2.OSTreeCommitStageReferences{"name:" + p.treePipeline.Name()} + var parent string + if p.treePipeline.OSTree.Parent != nil { + parent = p.treePipeline.OSTree.Parent.Checksum + } pipeline.AddStage(osbuild2.NewOSTreeCommitStage( &osbuild2.OSTreeCommitStageOptions{ Ref: p.ref, OSVersion: p.OSVersion, - Parent: p.treePipeline.osTreeParent, + Parent: parent, }, &osbuild2.OSTreeCommitStageInputs{Tree: commitStageInput}), ) diff --git a/internal/manifest/os.go b/internal/manifest/os.go index d1693756b..c8f58a3c5 100644 --- a/internal/manifest/os.go +++ b/internal/manifest/os.go @@ -19,6 +19,15 @@ const ( BOOTLOADER_ZIPL ) +type OSPipelineOSTree struct { + Parent *OSPipelineOSTreeParent +} + +type OSPipelineOSTreeParent struct { + Checksum string + URL string +} + // OSPipeline represents the filesystem tree of the target image. This roughly // correpsonds to the root filesystem once an instance of the image is running. type OSPipeline struct { @@ -36,6 +45,8 @@ type OSPipeline struct { UserPackages []string // Repositories to install the user packages from. UserRepos []rpmmd.RepoConfig + // OSTree configuration, if nil the tree cannot be in an OSTree commit + OSTree *OSPipelineOSTree // KernelOptionsAppend are appended to the kernel commandline KernelOptionsAppend []string // UEFIVendor indicates whether or not the OS should support UEFI and @@ -84,9 +95,6 @@ type OSPipeline struct { PwQuality *osbuild2.PwqualityConfStageOptions WAAgentConfig *osbuild2.WAAgentConfStageOptions - osTree bool - osTreeParent string - osTreeURL string repos []rpmmd.RepoConfig packageSpecs []rpmmd.PackageSpec partitionTable *disk.PartitionTable @@ -104,9 +112,6 @@ type OSPipeline struct { // kernel package that will be used on the target system. func NewOSPipeline(m *Manifest, buildPipeline *BuildPipeline, - osTree bool, - osTreeParent string, - osTreeURL string, repos []rpmmd.RepoConfig, partitionTable *disk.PartitionTable, bootLoader BootLoader, @@ -114,9 +119,6 @@ func NewOSPipeline(m *Manifest, kernelName string) *OSPipeline { p := &OSPipeline{ BasePipeline: NewBasePipeline(m, "os", buildPipeline, nil), - osTree: osTree, - osTreeParent: osTreeParent, - osTreeURL: osTreeURL, repos: repos, partitionTable: partitionTable, bootLoader: bootLoader, @@ -157,7 +159,7 @@ func (p *OSPipeline) getBuildPackages() []string { if p.grubLegacy != "" { packages = append(packages, "grub2-pc") } - if p.osTree { + if p.OSTree != nil { packages = append(packages, "rpm-ostree") } return packages @@ -165,10 +167,10 @@ func (p *OSPipeline) getBuildPackages() []string { func (p *OSPipeline) getOSTreeCommits() []osTreeCommit { commits := []osTreeCommit{} - if p.osTreeParent != "" && p.osTreeURL != "" { + if p.OSTree != nil && p.OSTree.Parent != nil { commits = append(commits, osTreeCommit{ - checksum: p.osTreeParent, - url: p.osTreeURL, + checksum: p.OSTree.Parent.Checksum, + url: p.OSTree.Parent.URL, }) } return commits @@ -203,8 +205,8 @@ func (p *OSPipeline) serialize() osbuild2.Pipeline { pipeline := p.BasePipeline.serialize() - if p.osTree && p.osTreeParent != "" { - pipeline.AddStage(osbuild2.NewOSTreePasswdStage("org.osbuild.source", p.osTreeParent)) + if p.OSTree != nil && p.OSTree.Parent != nil { + pipeline.AddStage(osbuild2.NewOSTreePasswdStage("org.osbuild.source", p.OSTree.Parent.Checksum)) } rpmOptions := osbuild2.NewRPMStageOptions(p.repos) @@ -247,7 +249,7 @@ func (p *OSPipeline) serialize() osbuild2.Pipeline { // TODO: move encryption into weldr panic("password encryption failed") } - if p.osTree { + if p.OSTree != nil { // for ostree, writing the key during user creation is // redundant and can cause issues so create users without keys // and write them on first boot @@ -390,7 +392,7 @@ func (p *OSPipeline) serialize() osbuild2.Pipeline { })) } - if p.osTree { + if p.OSTree != nil { pipeline.AddStage(osbuild2.NewOSTreePrepTreeStage(&osbuild2.OSTreePrepTreeStageOptions{ EtcGroupMembers: []string{ // NOTE: We may want to make this configurable.