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:
parent
ff0ec01eb6
commit
bbd8dc338d
8 changed files with 669 additions and 33 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
|
@ -15,12 +16,6 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
type Fedora32 struct {
|
||||
arches map[string]arch
|
||||
outputs map[string]output
|
||||
buildPackages []string
|
||||
}
|
||||
|
||||
type arch struct {
|
||||
Name string
|
||||
BootloaderPackages []string
|
||||
|
|
@ -44,6 +39,103 @@ type output struct {
|
|||
const Distro = common.Fedora32
|
||||
const ModulePlatformID = "platform:f32"
|
||||
|
||||
type Fedora32 struct {
|
||||
arches map[string]arch
|
||||
outputs map[string]output
|
||||
buildPackages []string
|
||||
}
|
||||
|
||||
type Fedora32Arch struct {
|
||||
name string
|
||||
distro *Fedora32
|
||||
arch *arch
|
||||
}
|
||||
|
||||
type Fedora32ImageType struct {
|
||||
name string
|
||||
arch *Fedora32Arch
|
||||
output *output
|
||||
}
|
||||
|
||||
func (d *Fedora32) GetArch(arch string) (distro.Arch, error) {
|
||||
a, exists := d.arches[arch]
|
||||
if !exists {
|
||||
return nil, errors.New("invalid architecture: " + arch)
|
||||
}
|
||||
|
||||
return &Fedora32Arch{
|
||||
name: arch,
|
||||
distro: d,
|
||||
arch: &a,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *Fedora32Arch) Name() string {
|
||||
return a.name
|
||||
}
|
||||
|
||||
func (a *Fedora32Arch) ListImageTypes() []string {
|
||||
return a.distro.ListOutputFormats()
|
||||
}
|
||||
|
||||
func (a *Fedora32Arch) GetImageType(imageType string) (distro.ImageType, error) {
|
||||
t, exists := a.distro.outputs[imageType]
|
||||
if !exists {
|
||||
return nil, errors.New("invalid image type: " + imageType)
|
||||
}
|
||||
|
||||
return &Fedora32ImageType{
|
||||
name: imageType,
|
||||
arch: a,
|
||||
output: &t,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *Fedora32ImageType) Name() string {
|
||||
return t.name
|
||||
}
|
||||
|
||||
func (t *Fedora32ImageType) Filename() string {
|
||||
return t.output.Name
|
||||
}
|
||||
|
||||
func (t *Fedora32ImageType) MIMEType() string {
|
||||
return t.output.MimeType
|
||||
}
|
||||
|
||||
func (t *Fedora32ImageType) Size(size uint64) uint64 {
|
||||
return t.arch.distro.GetSizeForOutputType(t.name, size)
|
||||
}
|
||||
|
||||
func (t *Fedora32ImageType) BasePackages() ([]string, []string) {
|
||||
packages := t.output.Packages
|
||||
if t.output.Bootable {
|
||||
packages = append(packages, t.arch.arch.BootloaderPackages...)
|
||||
}
|
||||
|
||||
return packages, t.output.ExcludedPackages
|
||||
}
|
||||
|
||||
func (t *Fedora32ImageType) BuildPackages() []string {
|
||||
return append(t.arch.distro.buildPackages, t.arch.arch.BuildPackages...)
|
||||
}
|
||||
|
||||
func (t *Fedora32ImageType) Manifest(c *blueprint.Customizations,
|
||||
repos []rpmmd.RepoConfig,
|
||||
packageSpecs,
|
||||
buildPackageSpecs []rpmmd.PackageSpec,
|
||||
size uint64) (*osbuild.Manifest, error) {
|
||||
pipeline, err := t.arch.distro.pipeline(c, repos, packageSpecs, buildPackageSpecs, t.arch.name, t.name, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &osbuild.Manifest{
|
||||
Sources: *t.arch.distro.sources(append(packageSpecs, buildPackageSpecs...)),
|
||||
Pipeline: *pipeline,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func New() *Fedora32 {
|
||||
const GigaByte = 1024 * 1024 * 1024
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue