pipelines: introduce pipeline abstractions

Create a new package to encapsulate pipelines. This introduces only the build
pipeline and uses it in fedora.

No functional change.
This commit is contained in:
Tom Gundersen 2022-06-25 15:12:54 +01:00
parent b8815aab4c
commit b6d6626a5d
4 changed files with 128 additions and 16 deletions

View file

@ -11,13 +11,18 @@ import (
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/distro"
pipeline "github.com/osbuild/osbuild-composer/internal/distro/pipelines"
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
func qcow2Pipelines(t *imageType, 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)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
buildPipeline := pipeline.NewBuildPipeline(t.arch.distro.runner)
buildPipeline.Repos = repos
buildPipeline.PackageSpecs = packageSetSpecs[buildPkgsKey]
pipelines = append(pipelines, buildPipeline.Serialize())
partitionTable, err := t.getPartitionTable(customizations.GetFilesystems(), options, rng)
if err != nil {
@ -54,7 +59,11 @@ func prependKernelCmdlineStage(pipeline *osbuild.Pipeline, kernelOptions string,
func vhdPipelines(t *imageType, 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)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
buildPipeline := pipeline.NewBuildPipeline(t.arch.distro.runner)
buildPipeline.Repos = repos
buildPipeline.PackageSpecs = packageSetSpecs[buildPkgsKey]
pipelines = append(pipelines, buildPipeline.Serialize())
partitionTable, err := t.getPartitionTable(customizations.GetFilesystems(), options, rng)
if err != nil {
@ -79,7 +88,11 @@ func vhdPipelines(t *imageType, customizations *blueprint.Customizations, option
func vmdkPipelines(t *imageType, 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)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
buildPipeline := pipeline.NewBuildPipeline(t.arch.distro.runner)
buildPipeline.Repos = repos
buildPipeline.PackageSpecs = packageSetSpecs[buildPkgsKey]
pipelines = append(pipelines, buildPipeline.Serialize())
partitionTable, err := t.getPartitionTable(customizations.GetFilesystems(), options, rng)
if err != nil {
@ -104,7 +117,11 @@ func vmdkPipelines(t *imageType, customizations *blueprint.Customizations, optio
func openstackPipelines(t *imageType, 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)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
buildPipeline := pipeline.NewBuildPipeline(t.arch.distro.runner)
buildPipeline.Repos = repos
buildPipeline.PackageSpecs = packageSetSpecs[buildPkgsKey]
pipelines = append(pipelines, buildPipeline.Serialize())
partitionTable, err := t.getPartitionTable(customizations.GetFilesystems(), options, rng)
if err != nil {
@ -131,7 +148,11 @@ func ec2CommonPipelines(t *imageType, customizations *blueprint.Customizations,
repos []rpmmd.RepoConfig, packageSetSpecs map[string][]rpmmd.PackageSpec,
rng *rand.Rand, diskfile string) ([]osbuild.Pipeline, error) {
pipelines := make([]osbuild.Pipeline, 0)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
buildPipeline := pipeline.NewBuildPipeline(t.arch.distro.runner)
buildPipeline.Repos = repos
buildPipeline.PackageSpecs = packageSetSpecs[buildPkgsKey]
pipelines = append(pipelines, buildPipeline.Serialize())
partitionTable, err := t.getPartitionTable(customizations.GetFilesystems(), options, rng)
if err != nil {
@ -164,7 +185,12 @@ func makeISORootPath(p string) string {
func iotInstallerPipelines(t *imageType, 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)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
buildPipeline := pipeline.NewBuildPipeline(t.arch.distro.runner)
buildPipeline.Repos = repos
buildPipeline.PackageSpecs = packageSetSpecs[buildPkgsKey]
pipelines = append(pipelines, buildPipeline.Serialize())
installerPackages := packageSetSpecs[installerPkgsKey]
d := t.arch.distro
archName := t.Arch().Name()
@ -177,15 +203,22 @@ func iotInstallerPipelines(t *imageType, customizations *blueprint.Customization
}
ksUsers := len(customizations.GetUsers())+len(customizations.GetGroups()) > 0
pipelines = append(pipelines, *anacondaTreePipeline(repos, installerPackages, kernelVer, archName, d.product, d.osVersion, "IoT", ksUsers))
isolabel := fmt.Sprintf(d.isolabelTmpl, archName)
pipelines = append(pipelines, *bootISOTreePipeline(kernelVer, archName, d.vendor, d.product, d.osVersion, isolabel, kickstartOptions, payloadStages))
pipelines = append(pipelines, *bootISOPipeline(t.Filename(), d.isolabelTmpl, archName, false))
return pipelines, nil
}
func iotCorePipelines(t *imageType, customizations *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSetSpecs map[string][]rpmmd.PackageSpec) ([]osbuild.Pipeline, error) {
pipelines := make([]osbuild.Pipeline, 0)
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
buildPipeline := pipeline.NewBuildPipeline(t.arch.distro.runner)
buildPipeline.Repos = repos
buildPipeline.PackageSpecs = packageSetSpecs[buildPkgsKey]
pipelines = append(pipelines, buildPipeline.Serialize())
treePipeline, err := osPipeline(t, repos, packageSetSpecs[osPkgsKey], customizations, options, nil)
if err != nil {
@ -193,6 +226,7 @@ func iotCorePipelines(t *imageType, customizations *blueprint.Customizations, op
}
pipelines = append(pipelines, *treePipeline)
pipelines = append(pipelines, *ostreeCommitPipeline(options, t.arch.distro.osVersion))
return pipelines, nil
@ -225,15 +259,6 @@ func iotContainerPipelines(t *imageType, customizations *blueprint.Customization
return pipelines, nil
}
func buildPipeline(repos []rpmmd.RepoConfig, buildPackageSpecs []rpmmd.PackageSpec, runner string) *osbuild.Pipeline {
p := new(osbuild.Pipeline)
p.Name = "build"
p.Runner = runner
p.AddStage(osbuild.NewRPMStage(osbuild.NewRPMStageOptions(repos), osbuild.NewRpmStageSourceFilesInputs(buildPackageSpecs)))
p.AddStage(osbuild.NewSELinuxStage(selinuxStageOptions(true)))
return p
}
func osPipeline(t *imageType,
repos []rpmmd.RepoConfig,
packages []rpmmd.PackageSpec,

View file

@ -0,0 +1,29 @@
package pipeline
import (
"github.com/osbuild/osbuild-composer/internal/osbuild2"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
type BuildPipeline struct {
Pipeline
Repos []rpmmd.RepoConfig
PackageSpecs []rpmmd.PackageSpec
}
func NewBuildPipeline(runner string) BuildPipeline {
pipeline := BuildPipeline{
Pipeline: New("build", nil),
}
pipeline.runner = &runner
return pipeline
}
func (p BuildPipeline) Serialize() osbuild2.Pipeline {
pipeline := p.Pipeline.Serialize()
pipeline.AddStage(osbuild2.NewRPMStage(osbuild2.NewRPMStageOptions(p.Repos), osbuild2.NewRpmStageSourceFilesInputs(p.PackageSpecs)))
pipeline.AddStage(osbuild2.NewSELinuxStage(selinuxStageOptions(true)))
return pipeline
}

View file

@ -0,0 +1,38 @@
package pipeline
import (
"github.com/osbuild/osbuild-composer/internal/osbuild2"
)
type Pipeline struct {
name string
runner *string
build *Pipeline
}
func (p Pipeline) Name() string {
return p.name
}
func New(name string, build *Pipeline) Pipeline {
return Pipeline{
name: name,
build: build,
}
}
func (p Pipeline) Serialize() osbuild2.Pipeline {
var buildName string
if p.build != nil {
buildName = "name:" + p.build.Name()
}
var runner string
if p.runner != nil {
runner = *p.runner
}
return osbuild2.Pipeline{
Name: p.name,
Runner: runner,
Build: buildName,
}
}

View file

@ -0,0 +1,20 @@
package pipeline
import (
"github.com/osbuild/osbuild-composer/internal/osbuild2"
)
// selinuxStageOptions returns the options for the org.osbuild.selinux stage.
// Setting the argument to 'true' relabels the '/usr/bin/cp'
// binariy with 'install_exec_t'. This should be set in the build root.
func selinuxStageOptions(labelcp bool) *osbuild2.SELinuxStageOptions {
options := &osbuild2.SELinuxStageOptions{
FileContexts: "etc/selinux/targeted/contexts/files/file_contexts",
}
if labelcp {
options.Labels = map[string]string{
"/usr/bin/cp": "system_u:object_r:install_exec_t:s0",
}
}
return options
}