distro: delete distro.Manifest type

Delete the distro.Manifest type and its tests.
Change all occurrences of distro.Manifest to manifest.OSBuildManifest.
This commit is contained in:
Achilleas Koutsou 2023-04-27 16:33:01 +02:00 committed by Simon de Vlieger
parent 5498764725
commit c7aecdf31c
17 changed files with 58 additions and 162 deletions

View file

@ -21,6 +21,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
@ -167,7 +168,7 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
err = fmt.Errorf("[%s] nil package specs", filename)
return
}
manifest, _, err := imgType.Manifest(cr.Blueprint.Customizations, options, repos, packageSpecs, containerSpecs, seedArg)
mf, _, err := imgType.Manifest(cr.Blueprint.Customizations, options, repos, packageSpecs, containerSpecs, seedArg)
if err != nil {
err = fmt.Errorf("[%s] failed: %s", filename, err)
return
@ -181,7 +182,7 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
Blueprint: cr.Blueprint,
OSTree: cr.OSTree,
}
err = save(manifest, packageSpecs, containerSpecs, request, path, filename)
err = save(mf, packageSpecs, containerSpecs, request, path, filename)
return
}
return job
@ -268,15 +269,15 @@ func depsolve(cacheDir string, imageType distro.ImageType, bp blueprint.Blueprin
return depsolvedSets, nil
}
func save(manifest distro.Manifest, pkgs map[string][]rpmmd.PackageSpec, containers []container.Spec, cr composeRequest, path, filename string) error {
func save(mf manifest.OSBuildManifest, pkgs map[string][]rpmmd.PackageSpec, containers []container.Spec, cr composeRequest, path, filename string) error {
data := struct {
ComposeRequest composeRequest `json:"compose-request"`
Manifest distro.Manifest `json:"manifest"`
Manifest manifest.OSBuildManifest `json:"manifest"`
RPMMD map[string][]rpmmd.PackageSpec `json:"rpmmd"`
Containers []container.Spec `json:"containers,omitempty"`
NoImageInfo bool `json:"no-image-info"`
}{
cr, manifest, pkgs, containers, true,
cr, mf, pkgs, containers, true,
}
b, err := json.MarshalIndent(data, "", " ")
if err != nil {

View file

@ -14,13 +14,14 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro/fedora"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/store"
"github.com/osbuild/osbuild-composer/internal/target"
)
func getManifest(bp blueprint.Blueprint, t distro.ImageType, a distro.Arch, d distro.Distro, cacheDir string, repos []rpmmd.RepoConfig) (distro.Manifest, []rpmmd.PackageSpec) {
func getManifest(bp blueprint.Blueprint, t distro.ImageType, a distro.Arch, d distro.Distro, cacheDir string, repos []rpmmd.RepoConfig) (manifest.OSBuildManifest, []rpmmd.PackageSpec) {
packageSets := t.PackageSets(bp, distro.ImageOptions{}, repos)
pkgSpecSets := make(map[string][]rpmmd.PackageSpec)
solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), a.Name(), d.Name(), cacheDir)

View file

@ -18,6 +18,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -1325,7 +1326,7 @@ func (h *apiHandlers) getComposeManifestsImpl(ctx echo.Context, id string) error
return HTTPErrorWithInternal(ErrorComposeNotFound, err)
}
var manifest distro.Manifest
var mf manifest.OSBuildManifest
switch buildJobType {
case worker.JobTypeOSBuild:
@ -1336,7 +1337,7 @@ func (h *apiHandlers) getComposeManifestsImpl(ctx echo.Context, id string) error
}
if len(buildJob.Manifest) != 0 {
manifest = buildJob.Manifest
mf = buildJob.Manifest
} else {
buildInfo, err := h.server.workers.OSBuildJobInfo(finalizeInfo.Deps[i], &worker.OSBuildJobResult{})
if err != nil {
@ -1346,14 +1347,14 @@ func (h *apiHandlers) getComposeManifestsImpl(ctx echo.Context, id string) error
if err != nil {
return HTTPErrorWithInternal(ErrorComposeNotFound, fmt.Errorf("job %q: %v", jobId, err))
}
manifest = manifestResult.Manifest
mf = manifestResult.Manifest
}
default:
return HTTPErrorWithInternal(ErrorInvalidJobType,
fmt.Errorf("unexpected job type in koji compose dependencies: %q", buildJobType))
}
manifestBlobs = append(manifestBlobs, manifest)
manifestBlobs = append(manifestBlobs, mf)
}
case worker.JobTypeOSBuild:
@ -1363,9 +1364,9 @@ func (h *apiHandlers) getComposeManifestsImpl(ctx echo.Context, id string) error
return HTTPErrorWithInternal(ErrorComposeNotFound, err)
}
var manifest distro.Manifest
var mf manifest.OSBuildManifest
if len(buildJob.Manifest) != 0 {
manifest = buildJob.Manifest
mf = buildJob.Manifest
} else {
buildInfo, err := h.server.workers.OSBuildJobInfo(jobId, &worker.OSBuildJobResult{})
if err != nil {
@ -1375,9 +1376,9 @@ func (h *apiHandlers) getComposeManifestsImpl(ctx echo.Context, id string) error
if err != nil {
return HTTPErrorWithInternal(ErrorComposeNotFound, fmt.Errorf("job %q: %v", jobId, err))
}
manifest = manifestResult.Manifest
mf = manifestResult.Manifest
}
manifestBlobs = append(manifestBlobs, manifest)
manifestBlobs = append(manifestBlobs, mf)
default:
return HTTPError(ErrorInvalidJobType)

View file

@ -1,12 +1,12 @@
package distro
import (
"encoding/json"
"fmt"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/container"
"github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/subscription"
)
@ -131,7 +131,7 @@ type ImageType interface {
// specified in the given blueprint; it also returns any warnings (e.g.
// deprecation notices) generated by the manifest.
// The packageSpecSets must be labelled in the same way as the originating PackageSets.
Manifest(b *blueprint.Customizations, options ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (Manifest, []string, error)
Manifest(b *blueprint.Customizations, options ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (manifest.OSBuildManifest, []string, error)
}
// The ImageOptions specify options for a specific image build
@ -176,43 +176,6 @@ type FactsImageOptions struct {
type BasePartitionTableMap map[string]disk.PartitionTable
// A Manifest is an opaque JSON object, which is a valid input to osbuild
type Manifest []byte
func (m Manifest) MarshalJSON() ([]byte, error) {
return json.RawMessage(m).MarshalJSON()
}
func (m *Manifest) UnmarshalJSON(payload []byte) error {
var raw json.RawMessage
err := (&raw).UnmarshalJSON(payload)
if err != nil {
return err
}
*m = Manifest(raw)
return nil
}
type manifestVersion struct {
Version string `json:"version"`
}
func (m Manifest) Version() (string, error) {
mver := new(manifestVersion)
if err := json.Unmarshal(m, mver); err != nil {
return "", err
}
switch mver.Version {
case "":
return "1", nil
case "2":
return "2", nil
default:
return "", fmt.Errorf("Unsupported Manifest version %s", mver.Version)
}
}
// Fallbacks: When a new method is added to an interface to provide to provide
// information that isn't available for older implementations, the older
// methods should return a fallback/default value by calling the appropriate

View file

@ -30,84 +30,6 @@ func TestDistro_Manifest(t *testing.T) {
)
}
var (
v1manifests = []string{
`{}`,
`
{
"sources": {
"org.osbuild.files": {
"urls": {}
}
},
"pipeline": {
"build": {
"pipeline": {
"stages": []
},
"runner": "org.osbuild.rhel84"
},
"stages": [],
"assembler": {
"name": "org.osbuild.qemu",
"options": {}
}
}
}`,
}
v2manifests = []string{
`{"version": "2"}`,
`
{
"version": "2",
"pipelines": [
{
"name": "build",
"runner": "org.osbuild.rhel84",
"stages": []
}
],
"sources": {
"org.osbuild.curl": {
"items": {}
}
}
}`,
}
)
func TestDistro_Version(t *testing.T) {
require := require.New(t)
expectedVersion := "1"
for idx, rawManifest := range v1manifests {
manifest := distro.Manifest(rawManifest)
detectedVersion, err := manifest.Version()
require.NoError(err, "Could not detect Manifest version for %d: %v", idx, err)
require.Equal(expectedVersion, detectedVersion, "in manifest %d", idx)
}
expectedVersion = "2"
for idx, rawManifest := range v2manifests {
manifest := distro.Manifest(rawManifest)
detectedVersion, err := manifest.Version()
require.NoError(err, "Could not detect Manifest version for %d: %v", idx, err)
require.Equal(expectedVersion, detectedVersion, "in manifest %d", idx)
}
{
manifest := distro.Manifest("")
_, err := manifest.Version()
require.Error(err, "Empty manifest did not return an error")
}
{
manifest := distro.Manifest("{")
_, err := manifest.Version()
require.Error(err, "Invalid manifest did not return an error")
}
}
// Ensure that all package sets defined in the package set chains are defined for the image type
func TestImageType_PackageSetsChains(t *testing.T) {
distros := distroregistry.NewDefault()

View file

@ -18,6 +18,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
@ -49,7 +50,7 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis
var tt struct {
ComposeRequest *composeRequest `json:"compose-request"`
PackageSpecSets map[string][]rpmmd.PackageSpec `json:"rpmmd"`
Manifest distro.Manifest `json:"manifest,omitempty"`
Manifest manifest.OSBuildManifest `json:"manifest,omitempty"`
Containers []container.Spec `json:"containers,omitempty"`
}
file, err := os.ReadFile(fileName)

View file

@ -257,7 +257,7 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
repos []rpmmd.RepoConfig,
packageSpecs map[string][]rpmmd.PackageSpec,
containers []container.Spec,
seed int64) (distro.Manifest, []string, error) {
seed int64) (manifest.OSBuildManifest, []string, error) {
bp := &blueprint.Blueprint{Name: "empty blueprint"}
err := bp.Initialize()
@ -321,9 +321,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
ret, err := manifest.Serialize(packageSpecs)
if err != nil {
return distro.Manifest(ret), nil, err
return ret, nil, err
}
return distro.Manifest(ret), warnings, err
return ret, warnings, err
}
// checkOptions checks the validity and compatibility of options and customizations for the image type.

View file

@ -154,7 +154,7 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
repos []rpmmd.RepoConfig,
packageSpecs map[string][]rpmmd.PackageSpec,
containers []container.Spec,
seed int64) (distro.Manifest, []string, error) {
seed int64) (manifest.OSBuildManifest, []string, error) {
bp := &blueprint.Blueprint{Name: "empty blueprint"}
err := bp.Initialize()
@ -223,9 +223,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
ret, err := manifest.Serialize(packageSpecs)
if err != nil {
return distro.Manifest(ret), nil, err
return ret, nil, err
}
return distro.Manifest(ret), warnings, err
return ret, warnings, err
}
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {

View file

@ -187,7 +187,7 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
repos []rpmmd.RepoConfig,
packageSpecs map[string][]rpmmd.PackageSpec,
containers []container.Spec,
seed int64) (distro.Manifest, []string, error) {
seed int64) (manifest.OSBuildManifest, []string, error) {
bp := &blueprint.Blueprint{Name: "empty blueprint"}
err := bp.Initialize()
@ -256,9 +256,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
ret, err := manifest.Serialize(packageSpecs)
if err != nil {
return distro.Manifest(ret), nil, err
return ret, nil, err
}
return distro.Manifest(ret), warnings, err
return ret, warnings, err
}
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {

View file

@ -190,7 +190,7 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
repos []rpmmd.RepoConfig,
packageSpecs map[string][]rpmmd.PackageSpec,
containers []container.Spec,
seed int64) (distro.Manifest, []string, error) {
seed int64) (manifest.OSBuildManifest, []string, error) {
bp := &blueprint.Blueprint{Name: "empty blueprint"}
err := bp.Initialize()
@ -256,9 +256,9 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
ret, err := manifest.Serialize(packageSpecs)
if err != nil {
return distro.Manifest(ret), nil, err
return ret, nil, err
}
return distro.Manifest(ret), warnings, err
return ret, warnings, err
}
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {

View file

@ -10,6 +10,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/container"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
@ -243,7 +244,7 @@ func (t *TestImageType) Exports() []string {
return distro.ExportsFallback()
}
func (t *TestImageType) Manifest(b *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (distro.Manifest, []string, error) {
func (t *TestImageType) Manifest(b *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (manifest.OSBuildManifest, []string, error) {
mountpoints := b.GetFilesystems()
invalidMountpoints := []string{}

View file

@ -7,6 +7,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/target"
)
@ -23,7 +24,7 @@ func (ste *StateTransitionError) Error() string {
type ImageBuild struct {
ID int
ImageType distro.ImageType
Manifest distro.Manifest
Manifest manifest.OSBuildManifest
Targets []*target.Target
JobCreated time.Time
JobStarted time.Time

View file

@ -12,6 +12,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/target"
)
@ -41,15 +42,15 @@ type composesV0 map[uuid.UUID]composeV0
// ImageBuild represents a single image build inside a compose
type imageBuildV0 struct {
ID int `json:"id"`
ImageType string `json:"image_type"`
Manifest distro.Manifest `json:"manifest"`
Targets []*target.Target `json:"targets"`
JobCreated time.Time `json:"job_created"`
JobStarted time.Time `json:"job_started"`
JobFinished time.Time `json:"job_finished"`
Size uint64 `json:"size"`
JobID uuid.UUID `json:"jobid,omitempty"`
ID int `json:"id"`
ImageType string `json:"image_type"`
Manifest manifest.OSBuildManifest `json:"manifest"`
Targets []*target.Target `json:"targets"`
JobCreated time.Time `json:"job_created"`
JobStarted time.Time `json:"job_started"`
JobFinished time.Time `json:"job_finished"`
Size uint64 `json:"size"`
JobID uuid.UUID `json:"jobid,omitempty"`
// Kept for backwards compatibility. Image builds which were done
// before the move to the job queue use this to store whether they

View file

@ -19,6 +19,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/jsondb"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/common"
@ -365,7 +366,7 @@ func (s *Store) GetAllComposes() map[uuid.UUID]Compose {
}
func (s *Store) PushCompose(composeID uuid.UUID,
manifest distro.Manifest,
manifest manifest.OSBuildManifest,
imageType distro.ImageType,
bp *blueprint.Blueprint,
size uint64,
@ -404,7 +405,7 @@ func (s *Store) PushCompose(composeID uuid.UUID,
// Set testSuccess to create a fake successful compose, otherwise it will create a failed compose
// It does not actually run a compose job
func (s *Store) PushTestCompose(composeID uuid.UUID,
manifest distro.Manifest,
manifest manifest.OSBuildManifest,
imageType distro.ImageType,
bp *blueprint.Blueprint,
size uint64,

View file

@ -11,6 +11,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distro/test_distro"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/target"
@ -34,7 +35,7 @@ type storeTest struct {
myDistro *test_distro.TestDistro
myArch distro.Arch
myImageType distro.ImageType
myManifest distro.Manifest
myManifest manifest.OSBuildManifest
myRepoConfig []rpmmd.RepoConfig
myPackageSpec []rpmmd.PackageSpec
myImageOptions distro.ImageOptions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/target"
@ -16,7 +17,7 @@ import (
//
type OSBuildJob struct {
Manifest distro.Manifest `json:"manifest,omitempty"`
Manifest manifest.OSBuildManifest `json:"manifest,omitempty"`
// Index of the ManifestJobByIDResult instance in the job's dynamic arguments slice
ManifestDynArgsIdx *int `json:"manifest_dyn_args_idx,omitempty"`
Targets []*target.Target `json:"targets,omitempty"`
@ -243,8 +244,8 @@ type DepsolveJobResult struct {
type ManifestJobByID struct{}
type ManifestJobByIDResult struct {
Manifest distro.Manifest `json:"data,omitempty"`
Error string `json:"error"`
Manifest manifest.OSBuildManifest `json:"data,omitempty"`
Error string `json:"error"`
JobResult
}

View file

@ -19,6 +19,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distro/test_distro"
"github.com/osbuild/osbuild-composer/internal/jobqueue/fsjobqueue"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -409,7 +410,7 @@ func TestRequestJobById(t *testing.T) {
func TestMixedOSBuildJob(t *testing.T) {
require := require.New(t)
emptyManifestV2 := distro.Manifest(`{"version":"2","pipelines":{}}`)
emptyManifestV2 := manifest.OSBuildManifest(`{"version":"2","pipelines":{}}`)
server := newTestServer(t, t.TempDir(), time.Millisecond*10, "/", false)
fbPipelines := &worker.PipelineNames{Build: distro.BuildPipelinesFallback(), Payload: distro.PayloadPipelinesFallback()}