distro: introduce Arch and ImageType interfaces

Objects implementing these interfaces will represent the
architecture support for a given distro and the image type
support for a given architecture distro combination, respectively.

The idea is to always resolve to these objects early, and drop
the equilavent methods from the distro interface. This means that
we convert our input strings to real objects once, and then never
have to verify their correctness again.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-03-22 13:08:09 +01:00 committed by msehnout
parent ff0ec01eb6
commit bbd8dc338d
8 changed files with 669 additions and 33 deletions

View file

@ -16,9 +16,9 @@ import (
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
// A Distro represents composer's notion of what a given distribution is.
type Distro interface {
// Returns the name of the distro. This is the same name that was
// passed to New().
// Returns the name of the distro.
Name() string
// Return strong-typed distribution
@ -28,6 +28,10 @@ type Distro interface {
// for modularity support.
ModulePlatformID() string
// Returns an object representing the given architecture as support
// by this distro.
GetArch(arch string) (Arch, error)
// Returns a sorted list of the output formats this distro supports.
ListOutputFormats() []string
@ -54,6 +58,49 @@ type Distro interface {
Runner() string
}
// An Arch represents a given distribution's support for a given architecture.
type Arch interface {
// Returns the name of the architecture.
Name() string
// Returns a sorted list of the names of the image types this architecture
// supports.
ListImageTypes() []string
// Returns an object representing a given image format for this architecture,
// on this distro.
GetImageType(imageType string) (ImageType, error)
}
// An ImageType represents a given distribution's support for a given Image Type
// for a given architecture.
type ImageType interface {
// Returns the name of the image type.
Name() string
// Returns the canonical filename for the image type.
Filename() string
// Retrns the MIME-type for the image type.
MIMEType() string
// Returns the proper image size for a given output format. If the input size
// is 0 the default value for the format will be returned.
Size(size uint64) uint64
// Returns the default packages to include and exclude when making the image
// type.
BasePackages() ([]string, []string)
// Returns the build packages for the output type.
BuildPackages() []string
// Returns an osbuild manifest, containing the sources and pipeline necessary
// to build an image, given output format with all packages and customizations
// specified in the given blueprint.
Manifest(b *blueprint.Customizations, repos []rpmmd.RepoConfig, packageSpecs, buildPackageSpecs []rpmmd.PackageSpec, size uint64) (*osbuild.Manifest, error)
}
type Registry struct {
distros map[common.Distribution]Distro
}