diff --git a/internal/distro/fedora/images.go b/internal/distro/fedora/images.go index dc37d8744..c49281f37 100644 --- a/internal/distro/fedora/images.go +++ b/internal/distro/fedora/images.go @@ -182,25 +182,20 @@ func iotCommitImage(workload workload.Workload, packageSets map[string]rpmmd.PackageSet, rng *rand.Rand) (image.ImageKind, error) { - img := image.NewOSTreeArchive() + img := image.NewOSTreeArchive(options.OSTree.ImageRef) img.Platform = t.platform img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], customizations) img.Environment = t.environment img.Workload = workload - var parent *manifest.OSTreeParent if options.OSTree.FetchChecksum != "" && options.OSTree.URL != "" { - parent = &manifest.OSTreeParent{ + img.OSTreeParent = &ostree.CommitSpec{ Checksum: options.OSTree.FetchChecksum, URL: options.OSTree.URL, } } - img.OSTreeParent = manifest.OSTree{ - Parent: parent, - } - img.OSTreeRef = options.OSTree.ImageRef img.OSVersion = t.arch.distro.osVersion img.Filename = t.Filename() @@ -215,7 +210,7 @@ func iotContainerImage(workload workload.Workload, packageSets map[string]rpmmd.PackageSet, rng *rand.Rand) (image.ImageKind, error) { - img := image.NewOSTreeContainer() + img := image.NewOSTreeContainer(options.OSTree.ImageRef) img.Platform = t.platform img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], customizations) @@ -223,18 +218,13 @@ func iotContainerImage(workload workload.Workload, img.Environment = t.environment img.Workload = workload - var parent *manifest.OSTreeParent if options.OSTree.FetchChecksum != "" && options.OSTree.URL != "" { - parent = &manifest.OSTreeParent{ + img.OSTreeParent = &ostree.CommitSpec{ Checksum: options.OSTree.FetchChecksum, URL: options.OSTree.URL, } } - img.OSTreeParent = manifest.OSTree{ - Parent: parent, - } - img.OSTreeRef = options.OSTree.ImageRef img.OSVersion = t.arch.distro.osVersion img.ExtraContainerPackages = packageSets[containerPkgsKey] diff --git a/internal/image/ostree_archive.go b/internal/image/ostree_archive.go index ff6e6c0a4..10208872f 100644 --- a/internal/image/ostree_archive.go +++ b/internal/image/ostree_archive.go @@ -6,6 +6,7 @@ import ( "github.com/osbuild/osbuild-composer/internal/artifact" "github.com/osbuild/osbuild-composer/internal/environment" "github.com/osbuild/osbuild-composer/internal/manifest" + "github.com/osbuild/osbuild-composer/internal/ostree" "github.com/osbuild/osbuild-composer/internal/platform" "github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/runner" @@ -18,15 +19,16 @@ type OSTreeArchive struct { OSCustomizations manifest.OSCustomizations Environment environment.Environment Workload workload.Workload - OSTreeParent manifest.OSTree + OSTreeParent *ostree.CommitSpec OSTreeRef string OSVersion string Filename string } -func NewOSTreeArchive() *OSTreeArchive { +func NewOSTreeArchive(ref string) *OSTreeArchive { return &OSTreeArchive{ - Base: NewBase("ostree-archive"), + Base: NewBase("ostree-archive"), + OSTreeRef: ref, } } @@ -41,7 +43,8 @@ func (img *OSTreeArchive) InstantiateManifest(m *manifest.Manifest, osPipeline.OSCustomizations = img.OSCustomizations osPipeline.Environment = img.Environment osPipeline.Workload = img.Workload - osPipeline.OSTree = &img.OSTreeParent + osPipeline.OSTreeParent = img.OSTreeParent + osPipeline.OSTreeRef = img.OSTreeRef ostreeCommitPipeline := manifest.NewOSTreeCommit(m, buildPipeline, osPipeline, img.OSTreeRef) ostreeCommitPipeline.OSVersion = img.OSVersion diff --git a/internal/image/ostree_container.go b/internal/image/ostree_container.go index fd2419416..6ac68cd0b 100644 --- a/internal/image/ostree_container.go +++ b/internal/image/ostree_container.go @@ -6,6 +6,7 @@ import ( "github.com/osbuild/osbuild-composer/internal/artifact" "github.com/osbuild/osbuild-composer/internal/environment" "github.com/osbuild/osbuild-composer/internal/manifest" + "github.com/osbuild/osbuild-composer/internal/ostree" "github.com/osbuild/osbuild-composer/internal/platform" "github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/runner" @@ -18,17 +19,18 @@ type OSTreeContainer struct { OSCustomizations manifest.OSCustomizations Environment environment.Environment Workload workload.Workload - OSTreeParent manifest.OSTree - OSTreeRef string // TODO: merge into the above + OSTreeRef string + OSTreeParent *ostree.CommitSpec OSVersion string ExtraContainerPackages rpmmd.PackageSet ContainerLanguage string Filename string } -func NewOSTreeContainer() *OSTreeContainer { +func NewOSTreeContainer(ref string) *OSTreeContainer { return &OSTreeContainer{ - Base: NewBase("ostree-container"), + Base: NewBase("ostree-container"), + OSTreeRef: ref, } } @@ -43,7 +45,8 @@ func (img *OSTreeContainer) InstantiateManifest(m *manifest.Manifest, osPipeline.OSCustomizations = img.OSCustomizations osPipeline.Environment = img.Environment osPipeline.Workload = img.Workload - osPipeline.OSTree = &img.OSTreeParent + osPipeline.OSTreeRef = img.OSTreeRef + osPipeline.OSTreeParent = img.OSTreeParent commitPipeline := manifest.NewOSTreeCommit(m, buildPipeline, osPipeline, img.OSTreeRef) commitPipeline.OSVersion = img.OSVersion diff --git a/internal/manifest/commit.go b/internal/manifest/commit.go index 5d7dce497..64bcc7c93 100644 --- a/internal/manifest/commit.go +++ b/internal/manifest/commit.go @@ -43,15 +43,15 @@ func (p *OSTreeCommit) getBuildPackages() []string { func (p *OSTreeCommit) serialize() osbuild.Pipeline { pipeline := p.Base.serialize() - if p.treePipeline.OSTree == nil { + if p.treePipeline.OSTreeRef == "" { panic("tree is not ostree") } pipeline.AddStage(osbuild.NewOSTreeInitStage(&osbuild.OSTreeInitStageOptions{Path: "/repo"})) var parent string - if p.treePipeline.OSTree.Parent != nil { - parent = p.treePipeline.OSTree.Parent.Checksum + if p.treePipeline.OSTreeParent != nil { + parent = p.treePipeline.OSTreeParent.Checksum } pipeline.AddStage(osbuild.NewOSTreeCommitStage( &osbuild.OSTreeCommitStageOptions{ diff --git a/internal/manifest/os.go b/internal/manifest/os.go index 726afed80..8540d98bb 100644 --- a/internal/manifest/os.go +++ b/internal/manifest/os.go @@ -10,21 +10,13 @@ import ( "github.com/osbuild/osbuild-composer/internal/disk" "github.com/osbuild/osbuild-composer/internal/environment" "github.com/osbuild/osbuild-composer/internal/osbuild" + "github.com/osbuild/osbuild-composer/internal/ostree" "github.com/osbuild/osbuild-composer/internal/platform" "github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/users" "github.com/osbuild/osbuild-composer/internal/workload" ) -type OSTree struct { - Parent *OSTreeParent -} - -type OSTreeParent struct { - Checksum string - URL string -} - // OSCustomizations encapsulates all configuration applied to the base // operating system independently of where and how it is integrated and what // workload it is running. @@ -101,8 +93,10 @@ type OS struct { Environment environment.Environment // Workload to install on top of the base system Workload workload.Workload - // OSTree configuration, if nil the tree cannot be in an OSTree commit - OSTree *OSTree + // Ref of ostree commit, if empty the tree cannot be in an ostree commit + OSTreeRef string + // OSTree parent spec, if nil the new commit (if applicable) will have no parent + OSTreeParent *ostree.CommitSpec // Partition table, if nil the tree cannot be put on a partitioned disk PartitionTable *disk.PartitionTable @@ -136,8 +130,10 @@ func (p *OS) getPackageSetChain() []rpmmd.PackageSet { packages = append(packages, p.KernelName) } - // If we have a logical volume we need to include the lvm2 package - if p.PartitionTable != nil && p.OSTree == nil { + // If we have a logical volume we need to include the lvm2 package. + // OSTree-based images (commit and container) aren't bootable images and + // don't have partition tables. + if p.PartitionTable != nil && p.OSTreeRef == "" { packages = append(packages, p.PartitionTable.GetBuildPackages()...) } @@ -181,7 +177,7 @@ func (p *OS) getPackageSetChain() []rpmmd.PackageSet { func (p *OS) getBuildPackages() []string { packages := p.platform.GetBuildPackages() packages = append(packages, "rpm") - if p.OSTree != nil { + if p.OSTreeRef != "" { packages = append(packages, "rpm-ostree") } if p.SElinux != "" { @@ -193,10 +189,10 @@ func (p *OS) getBuildPackages() []string { func (p *OS) getOSTreeCommits() []osTreeCommit { commits := []osTreeCommit{} - if p.OSTree != nil && p.OSTree.Parent != nil { + if p.OSTreeRef != "" && p.OSTreeParent != nil { commits = append(commits, osTreeCommit{ - checksum: p.OSTree.Parent.Checksum, - url: p.OSTree.Parent.URL, + checksum: p.OSTreeParent.Checksum, + url: p.OSTreeParent.URL, }) } return commits @@ -231,8 +227,8 @@ func (p *OS) serialize() osbuild.Pipeline { pipeline := p.Base.serialize() - if p.OSTree != nil && p.OSTree.Parent != nil { - pipeline.AddStage(osbuild.NewOSTreePasswdStage("org.osbuild.source", p.OSTree.Parent.Checksum)) + if p.OSTreeRef != "" && p.OSTreeParent != nil { + pipeline.AddStage(osbuild.NewOSTreePasswdStage("org.osbuild.source", p.OSTreeParent.Checksum)) } rpmOptions := osbuild.NewRPMStageOptions(p.repos) @@ -243,7 +239,7 @@ func (p *OS) serialize() osbuild.Pipeline { rpmOptions.Exclude.Docs = true } rpmOptions.GPGKeysFromTree = p.GPGKeyFiles - if p.OSTree != nil { + if p.OSTreeRef != "" { rpmOptions.OSTreeBooted = common.BoolToPtr(true) rpmOptions.DBPath = "/usr/share/rpm" } @@ -274,7 +270,7 @@ func (p *OS) serialize() osbuild.Pipeline { } if len(p.Users) > 0 { - if p.OSTree != nil { + if p.OSTreeRef != "" { // 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 @@ -435,7 +431,7 @@ func (p *OS) serialize() osbuild.Pipeline { })) } - if p.OSTree != nil { + if p.OSTreeRef != "" { pipeline.AddStage(osbuild.NewOSTreePrepTreeStage(&osbuild.OSTreePrepTreeStageOptions{ EtcGroupMembers: []string{ // NOTE: We may want to make this configurable.