From 54987647257184d54cabe3e4210bd3abd49e9094 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Thu, 27 Apr 2023 14:27:48 +0200 Subject: [PATCH] manifest: serialize to OSBuildManifest instead of distro.Manifest Copy the Marshal and Unmarshal functions from distro.Manifest to manifest.OSBuildManifest to keep the same behaviour. The Version() function isn't used, so let's drop it. --- internal/distro/fedora/imagetype.go | 4 ++-- internal/distro/rhel7/imagetype.go | 4 ++-- internal/distro/rhel8/imagetype.go | 4 ++-- internal/distro/rhel9/imagetype.go | 4 ++-- internal/manifest/manifest.go | 18 +++++++++++++++--- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/internal/distro/fedora/imagetype.go b/internal/distro/fedora/imagetype.go index 5b67e2d89..93c25417d 100644 --- a/internal/distro/fedora/imagetype.go +++ b/internal/distro/fedora/imagetype.go @@ -321,9 +321,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations, ret, err := manifest.Serialize(packageSpecs) if err != nil { - return ret, nil, err + return distro.Manifest(ret), nil, err } - return ret, warnings, err + return distro.Manifest(ret), warnings, err } // checkOptions checks the validity and compatibility of options and customizations for the image type. diff --git a/internal/distro/rhel7/imagetype.go b/internal/distro/rhel7/imagetype.go index 913b34242..3cebee99a 100644 --- a/internal/distro/rhel7/imagetype.go +++ b/internal/distro/rhel7/imagetype.go @@ -223,9 +223,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations, ret, err := manifest.Serialize(packageSpecs) if err != nil { - return ret, nil, err + return distro.Manifest(ret), nil, err } - return ret, warnings, err + return distro.Manifest(ret), warnings, err } func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet { diff --git a/internal/distro/rhel8/imagetype.go b/internal/distro/rhel8/imagetype.go index 3ca69a311..9f56d819e 100644 --- a/internal/distro/rhel8/imagetype.go +++ b/internal/distro/rhel8/imagetype.go @@ -256,9 +256,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations, ret, err := manifest.Serialize(packageSpecs) if err != nil { - return ret, nil, err + return distro.Manifest(ret), nil, err } - return ret, warnings, err + return distro.Manifest(ret), warnings, err } func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet { diff --git a/internal/distro/rhel9/imagetype.go b/internal/distro/rhel9/imagetype.go index 54f518fee..33b30ad50 100644 --- a/internal/distro/rhel9/imagetype.go +++ b/internal/distro/rhel9/imagetype.go @@ -256,9 +256,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations, ret, err := manifest.Serialize(packageSpecs) if err != nil { - return ret, nil, err + return distro.Manifest(ret), nil, err } - return ret, warnings, err + return distro.Manifest(ret), warnings, err } func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet { diff --git a/internal/manifest/manifest.go b/internal/manifest/manifest.go index afd4ad577..b493f1f56 100644 --- a/internal/manifest/manifest.go +++ b/internal/manifest/manifest.go @@ -4,7 +4,6 @@ import ( "encoding/json" "github.com/osbuild/osbuild-composer/internal/container" - "github.com/osbuild/osbuild-composer/internal/distro" "github.com/osbuild/osbuild-composer/internal/osbuild" "github.com/osbuild/osbuild-composer/internal/ostree" "github.com/osbuild/osbuild-composer/internal/rpmmd" @@ -20,9 +19,22 @@ const ( ) // An OSBuildManifest is an opaque JSON object, which is a valid input to osbuild -// TODO: use this instead of distro.Manifest below type OSBuildManifest []byte +func (m OSBuildManifest) MarshalJSON() ([]byte, error) { + return json.RawMessage(m).MarshalJSON() +} + +func (m *OSBuildManifest) UnmarshalJSON(payload []byte) error { + var raw json.RawMessage + err := (&raw).UnmarshalJSON(payload) + if err != nil { + return err + } + *m = OSBuildManifest(raw) + return nil +} + type Manifest struct { pipelines []Pipeline } @@ -54,7 +66,7 @@ func (m Manifest) GetPackageSetChains() map[string][]rpmmd.PackageSet { return chains } -func (m Manifest) Serialize(packageSets map[string][]rpmmd.PackageSpec) (distro.Manifest, error) { +func (m Manifest) Serialize(packageSets map[string][]rpmmd.PackageSpec) (OSBuildManifest, error) { pipelines := make([]osbuild.Pipeline, 0) packages := make([]rpmmd.PackageSpec, 0) commits := make([]ostree.CommitSpec, 0)