distro: use GenSources in Manifest() creation methods
Use the new helper function to generate the "sources" section of the manifest in all distros that use the v2 manifest format.
This commit is contained in:
parent
5fe3d1f6d1
commit
2555910f77
6 changed files with 26 additions and 283 deletions
|
|
@ -12,7 +12,9 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
|
|
@ -682,12 +684,6 @@ func (t *imageType) PartitionType() string {
|
|||
return basePartitionTable.Type
|
||||
}
|
||||
|
||||
// local type for ostree commit metadata used to define commit sources
|
||||
type ostreeCommit struct {
|
||||
Checksum string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
||||
options distro.ImageOptions,
|
||||
repos []rpmmd.RepoConfig,
|
||||
|
|
@ -715,9 +711,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
}
|
||||
|
||||
// handle OSTree commit inputs
|
||||
var commits []ostreeCommit
|
||||
var commits []ostree.CommitSource
|
||||
if options.OSTree.Parent != "" && options.OSTree.URL != "" {
|
||||
commits = []ostreeCommit{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
commits = []ostree.CommitSource{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
}
|
||||
|
||||
// handle inline sources
|
||||
|
|
@ -732,54 +728,11 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
osbuild.Manifest{
|
||||
Version: "2",
|
||||
Pipelines: pipelines,
|
||||
Sources: t.sources(allPackageSpecs, commits, inlineData),
|
||||
Sources: osbuild2.GenSources(allPackageSpecs, commits, inlineData),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (t *imageType) sources(packages []rpmmd.PackageSpec, ostreeCommits []ostreeCommit, inlineData []string) osbuild.Sources {
|
||||
sources := osbuild.Sources{}
|
||||
curl := &osbuild.CurlSource{
|
||||
Items: make(map[string]osbuild.CurlSourceItem),
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
item := new(osbuild.CurlSourceOptions)
|
||||
item.URL = pkg.RemoteLocation
|
||||
if pkg.Secrets == "org.osbuild.rhsm" {
|
||||
item.Secrets = &osbuild.URLSecrets{
|
||||
Name: "org.osbuild.rhsm",
|
||||
}
|
||||
}
|
||||
curl.Items[pkg.Checksum] = item
|
||||
}
|
||||
if len(curl.Items) > 0 {
|
||||
sources["org.osbuild.curl"] = curl
|
||||
}
|
||||
|
||||
ostree := &osbuild.OSTreeSource{
|
||||
Items: make(map[string]osbuild.OSTreeSourceItem),
|
||||
}
|
||||
for _, commit := range ostreeCommits {
|
||||
item := new(osbuild.OSTreeSourceItem)
|
||||
item.Remote.URL = commit.URL
|
||||
ostree.Items[commit.Checksum] = *item
|
||||
}
|
||||
if len(ostree.Items) > 0 {
|
||||
sources["org.osbuild.ostree"] = ostree
|
||||
}
|
||||
|
||||
if len(inlineData) > 0 {
|
||||
ils := osbuild.NewInlineSource()
|
||||
for _, data := range inlineData {
|
||||
ils.AddItem(data)
|
||||
}
|
||||
|
||||
sources["org.osbuild.inline"] = ils
|
||||
}
|
||||
|
||||
return sources
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
match, _ := path.Match(allowed, mountpoint)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
|
|
@ -183,59 +184,20 @@ func (t *imageTypeS2) Manifest(c *blueprint.Customizations,
|
|||
allPackageSpecs = append(allPackageSpecs, specs...)
|
||||
}
|
||||
|
||||
var commits []ostreeCommit
|
||||
var commits []ostree.CommitSource
|
||||
if t.bootISO && options.OSTree.Parent != "" && options.OSTree.URL != "" {
|
||||
commit := ostreeCommit{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}
|
||||
commits = []ostreeCommit{commit}
|
||||
commit := ostree.CommitSource{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}
|
||||
commits = []ostree.CommitSource{commit}
|
||||
}
|
||||
return json.Marshal(
|
||||
osbuild.Manifest{
|
||||
Version: "2",
|
||||
Pipelines: pipelines,
|
||||
Sources: t.sources(allPackageSpecs, commits),
|
||||
Sources: osbuild.GenSources(allPackageSpecs, commits, nil),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// local type for ostree commit metadata used to define commit sources
|
||||
type ostreeCommit struct {
|
||||
Checksum string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (t *imageTypeS2) sources(packages []rpmmd.PackageSpec, ostreeCommits []ostreeCommit) osbuild.Sources {
|
||||
sources := osbuild.Sources{}
|
||||
curl := &osbuild.CurlSource{
|
||||
Items: make(map[string]osbuild.CurlSourceItem),
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
item := new(osbuild.CurlSourceOptions)
|
||||
item.URL = pkg.RemoteLocation
|
||||
if pkg.Secrets == "org.osbuild.rhsm" {
|
||||
item.Secrets = &osbuild.URLSecrets{
|
||||
Name: "org.osbuild.rhsm",
|
||||
}
|
||||
}
|
||||
curl.Items[pkg.Checksum] = item
|
||||
}
|
||||
if len(curl.Items) > 0 {
|
||||
sources["org.osbuild.curl"] = curl
|
||||
}
|
||||
|
||||
ostree := &osbuild.OSTreeSource{
|
||||
Items: make(map[string]osbuild.OSTreeSourceItem),
|
||||
}
|
||||
for _, commit := range ostreeCommits {
|
||||
item := new(osbuild.OSTreeSourceItem)
|
||||
item.Remote.URL = commit.URL
|
||||
ostree.Items[commit.Checksum] = *item
|
||||
}
|
||||
if len(ostree.Items) > 0 {
|
||||
sources["org.osbuild.ostree"] = ostree
|
||||
}
|
||||
return sources
|
||||
}
|
||||
|
||||
func edgePipelines(t *imageTypeS2, 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
|
|
@ -364,12 +365,6 @@ func (t *imageType) PartitionType() string {
|
|||
return basePartitionTable.Type
|
||||
}
|
||||
|
||||
// local type for ostree commit metadata used to define commit sources
|
||||
type ostreeCommit struct {
|
||||
Checksum string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
||||
options distro.ImageOptions,
|
||||
repos []rpmmd.RepoConfig,
|
||||
|
|
@ -396,52 +391,19 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
allPackageSpecs = append(allPackageSpecs, specs...)
|
||||
}
|
||||
|
||||
var commits []ostreeCommit
|
||||
var commits []ostree.CommitSource
|
||||
if options.OSTree.Parent != "" && options.OSTree.URL != "" {
|
||||
commits = []ostreeCommit{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
commits = []ostree.CommitSource{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
}
|
||||
return json.Marshal(
|
||||
osbuild.Manifest{
|
||||
Version: "2",
|
||||
Pipelines: pipelines,
|
||||
Sources: t.sources(allPackageSpecs, commits),
|
||||
Sources: osbuild.GenSources(allPackageSpecs, commits, nil),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (t *imageType) sources(packages []rpmmd.PackageSpec, ostreeCommits []ostreeCommit) osbuild.Sources {
|
||||
sources := osbuild.Sources{}
|
||||
curl := &osbuild.CurlSource{
|
||||
Items: make(map[string]osbuild.CurlSourceItem),
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
item := new(osbuild.CurlSourceOptions)
|
||||
item.URL = pkg.RemoteLocation
|
||||
if pkg.Secrets == "org.osbuild.rhsm" {
|
||||
item.Secrets = &osbuild.URLSecrets{
|
||||
Name: "org.osbuild.rhsm",
|
||||
}
|
||||
}
|
||||
curl.Items[pkg.Checksum] = item
|
||||
}
|
||||
if len(curl.Items) > 0 {
|
||||
sources["org.osbuild.curl"] = curl
|
||||
}
|
||||
|
||||
ostree := &osbuild.OSTreeSource{
|
||||
Items: make(map[string]osbuild.OSTreeSourceItem),
|
||||
}
|
||||
for _, commit := range ostreeCommits {
|
||||
item := new(osbuild.OSTreeSourceItem)
|
||||
item.Remote.URL = commit.URL
|
||||
ostree.Items[commit.Checksum] = *item
|
||||
}
|
||||
if len(ostree.Items) > 0 {
|
||||
sources["org.osbuild.ostree"] = ostree
|
||||
}
|
||||
return sources
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
match, _ := path.Match(allowed, mountpoint)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
|
|
@ -442,12 +443,6 @@ func (t *imageType) PartitionType() string {
|
|||
return basePartitionTable.Type
|
||||
}
|
||||
|
||||
// local type for ostree commit metadata used to define commit sources
|
||||
type ostreeCommit struct {
|
||||
Checksum string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
||||
options distro.ImageOptions,
|
||||
repos []rpmmd.RepoConfig,
|
||||
|
|
@ -475,9 +470,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
}
|
||||
|
||||
// handle OSTree commit inputs
|
||||
var commits []ostreeCommit
|
||||
var commits []ostree.CommitSource
|
||||
if options.OSTree.Parent != "" && options.OSTree.URL != "" {
|
||||
commits = []ostreeCommit{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
commits = []ostree.CommitSource{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
}
|
||||
|
||||
// handle inline sources
|
||||
|
|
@ -492,54 +487,11 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
osbuild.Manifest{
|
||||
Version: "2",
|
||||
Pipelines: pipelines,
|
||||
Sources: t.sources(allPackageSpecs, commits, inlineData),
|
||||
Sources: osbuild.GenSources(allPackageSpecs, commits, inlineData),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (t *imageType) sources(packages []rpmmd.PackageSpec, ostreeCommits []ostreeCommit, inlineData []string) osbuild.Sources {
|
||||
sources := osbuild.Sources{}
|
||||
curl := &osbuild.CurlSource{
|
||||
Items: make(map[string]osbuild.CurlSourceItem),
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
item := new(osbuild.CurlSourceOptions)
|
||||
item.URL = pkg.RemoteLocation
|
||||
if pkg.Secrets == "org.osbuild.rhsm" {
|
||||
item.Secrets = &osbuild.URLSecrets{
|
||||
Name: "org.osbuild.rhsm",
|
||||
}
|
||||
}
|
||||
curl.Items[pkg.Checksum] = item
|
||||
}
|
||||
if len(curl.Items) > 0 {
|
||||
sources["org.osbuild.curl"] = curl
|
||||
}
|
||||
|
||||
ostree := &osbuild.OSTreeSource{
|
||||
Items: make(map[string]osbuild.OSTreeSourceItem),
|
||||
}
|
||||
for _, commit := range ostreeCommits {
|
||||
item := new(osbuild.OSTreeSourceItem)
|
||||
item.Remote.URL = commit.URL
|
||||
ostree.Items[commit.Checksum] = *item
|
||||
}
|
||||
if len(ostree.Items) > 0 {
|
||||
sources["org.osbuild.ostree"] = ostree
|
||||
}
|
||||
|
||||
if len(inlineData) > 0 {
|
||||
ils := osbuild.NewInlineSource()
|
||||
for _, data := range inlineData {
|
||||
ils.AddItem(data)
|
||||
}
|
||||
|
||||
sources["org.osbuild.inline"] = ils
|
||||
}
|
||||
|
||||
return sources
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
match, _ := path.Match(allowed, mountpoint)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
|
|
@ -442,12 +443,6 @@ func (t *imageType) PartitionType() string {
|
|||
return basePartitionTable.Type
|
||||
}
|
||||
|
||||
// local type for ostree commit metadata used to define commit sources
|
||||
type ostreeCommit struct {
|
||||
Checksum string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
||||
options distro.ImageOptions,
|
||||
repos []rpmmd.RepoConfig,
|
||||
|
|
@ -475,9 +470,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
}
|
||||
|
||||
// handle OSTree commit inputs
|
||||
var commits []ostreeCommit
|
||||
var commits []ostree.CommitSource
|
||||
if options.OSTree.Parent != "" && options.OSTree.URL != "" {
|
||||
commits = []ostreeCommit{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
commits = []ostree.CommitSource{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
}
|
||||
|
||||
// handle inline sources
|
||||
|
|
@ -492,54 +487,11 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
osbuild.Manifest{
|
||||
Version: "2",
|
||||
Pipelines: pipelines,
|
||||
Sources: t.sources(allPackageSpecs, commits, inlineData),
|
||||
Sources: osbuild.GenSources(allPackageSpecs, commits, inlineData),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (t *imageType) sources(packages []rpmmd.PackageSpec, ostreeCommits []ostreeCommit, inlineData []string) osbuild.Sources {
|
||||
sources := osbuild.Sources{}
|
||||
curl := &osbuild.CurlSource{
|
||||
Items: make(map[string]osbuild.CurlSourceItem),
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
item := new(osbuild.CurlSourceOptions)
|
||||
item.URL = pkg.RemoteLocation
|
||||
if pkg.Secrets == "org.osbuild.rhsm" {
|
||||
item.Secrets = &osbuild.URLSecrets{
|
||||
Name: "org.osbuild.rhsm",
|
||||
}
|
||||
}
|
||||
curl.Items[pkg.Checksum] = item
|
||||
}
|
||||
if len(curl.Items) > 0 {
|
||||
sources["org.osbuild.curl"] = curl
|
||||
}
|
||||
|
||||
ostree := &osbuild.OSTreeSource{
|
||||
Items: make(map[string]osbuild.OSTreeSourceItem),
|
||||
}
|
||||
for _, commit := range ostreeCommits {
|
||||
item := new(osbuild.OSTreeSourceItem)
|
||||
item.Remote.URL = commit.URL
|
||||
ostree.Items[commit.Checksum] = *item
|
||||
}
|
||||
if len(ostree.Items) > 0 {
|
||||
sources["org.osbuild.ostree"] = ostree
|
||||
}
|
||||
|
||||
if len(inlineData) > 0 {
|
||||
ils := osbuild.NewInlineSource()
|
||||
for _, data := range inlineData {
|
||||
ils.AddItem(data)
|
||||
}
|
||||
|
||||
sources["org.osbuild.inline"] = ils
|
||||
}
|
||||
|
||||
return sources
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
match, _ := path.Match(allowed, mountpoint)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
|
|
@ -377,12 +378,6 @@ func (t *imageType) PartitionType() string {
|
|||
return basePartitionTable.Type
|
||||
}
|
||||
|
||||
// local type for ostree commit metadata used to define commit sources
|
||||
type ostreeCommit struct {
|
||||
Checksum string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
||||
options distro.ImageOptions,
|
||||
repos []rpmmd.RepoConfig,
|
||||
|
|
@ -409,52 +404,19 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
allPackageSpecs = append(allPackageSpecs, specs...)
|
||||
}
|
||||
|
||||
var commits []ostreeCommit
|
||||
var commits []ostree.CommitSource
|
||||
if t.bootISO && options.OSTree.Parent != "" && options.OSTree.URL != "" {
|
||||
commits = []ostreeCommit{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
commits = []ostree.CommitSource{{Checksum: options.OSTree.Parent, URL: options.OSTree.URL}}
|
||||
}
|
||||
return json.Marshal(
|
||||
osbuild.Manifest{
|
||||
Version: "2",
|
||||
Pipelines: pipelines,
|
||||
Sources: t.sources(allPackageSpecs, commits),
|
||||
Sources: osbuild.GenSources(allPackageSpecs, commits, nil),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (t *imageType) sources(packages []rpmmd.PackageSpec, ostreeCommits []ostreeCommit) osbuild.Sources {
|
||||
sources := osbuild.Sources{}
|
||||
curl := &osbuild.CurlSource{
|
||||
Items: make(map[string]osbuild.CurlSourceItem),
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
item := new(osbuild.CurlSourceOptions)
|
||||
item.URL = pkg.RemoteLocation
|
||||
if pkg.Secrets == "org.osbuild.rhsm" {
|
||||
item.Secrets = &osbuild.URLSecrets{
|
||||
Name: "org.osbuild.rhsm",
|
||||
}
|
||||
}
|
||||
curl.Items[pkg.Checksum] = item
|
||||
}
|
||||
if len(curl.Items) > 0 {
|
||||
sources["org.osbuild.curl"] = curl
|
||||
}
|
||||
|
||||
ostree := &osbuild.OSTreeSource{
|
||||
Items: make(map[string]osbuild.OSTreeSourceItem),
|
||||
}
|
||||
for _, commit := range ostreeCommits {
|
||||
item := new(osbuild.OSTreeSourceItem)
|
||||
item.Remote.URL = commit.URL
|
||||
ostree.Items[commit.Checksum] = *item
|
||||
}
|
||||
if len(ostree.Items) > 0 {
|
||||
sources["org.osbuild.ostree"] = ostree
|
||||
}
|
||||
return sources
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
match, _ := path.Match(allowed, mountpoint)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue