artifact: this represents the artifacts a manifest exports

For now this encapsulates osbuild export and filename in that
exported tree. In the future we could add MIME type.

For now this is a concrete type, but should probably be an
interface, so the consumer of artefacts know they are the right
type. Enforcing we only push AMIs to EC2, etc.

Similarly to how checkpoints work, each pipeline can be marked for
export, and the manifest can return all the names of the exported
pipelines, to be passed to osbuild. Additionally, the Export
function returns an artefact object, which can be used to know how
to access the exports once osbuild is done. For now, this is unused.
This commit is contained in:
Tom Gundersen 2022-07-12 21:10:37 +01:00 committed by Christian Kellner
parent 9b77e67576
commit ce40e1d810
10 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,31 @@
package artifact
type Artifact struct {
export string
filename string
mimeType string
}
func New(export, filename string, mimeType *string) *Artifact {
artifact := &Artifact{
export: export,
filename: filename,
mimeType: "application/octet-stream",
}
if mimeType != nil {
artifact.mimeType = *mimeType
}
return artifact
}
func (a *Artifact) Export() string {
return a.export
}
func (a *Artifact) Filename() string {
return a.filename
}
func (a *Artifact) MIMEType() string {
return a.mimeType
}

View file

@ -1,6 +1,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
@ -66,3 +67,9 @@ func xorrisofsStageOptions(filename, isolabel string, isolinux bool) *osbuild.Xo
return options
}
func (p *ISO) Export() *artifact.Artifact {
p.Base.export = true
mimeType := "application/x-iso9660-image"
return artifact.New(p.Name(), p.Filename, &mimeType)
}

View file

@ -98,3 +98,13 @@ func (m Manifest) GetCheckpoints() []string {
}
return checkpoints
}
func (m Manifest) GetExports() []string {
exports := []string{}
for _, p := range m.pipelines {
if p.getExport() {
exports = append(exports, p.Name())
}
}
return exports
}

View file

@ -1,6 +1,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
@ -55,3 +56,9 @@ func (p *OCIContainer) serialize() osbuild.Pipeline {
func (p *OCIContainer) getBuildPackages() []string {
return []string{"tar"}
}
func (p *OCIContainer) Export() *artifact.Artifact {
p.Base.export = true
mimeType := "application/x-tar"
return artifact.New(p.Name(), p.Filename, &mimeType)
}

View file

@ -7,6 +7,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -15,7 +16,9 @@ import (
type Pipeline interface {
Name() string
Checkpoint()
Export() *artifact.Artifact
getCheckpoint() bool
getExport() bool
getBuildPackages() []string
getPackageSetChain() []rpmmd.PackageSet
serializeStart([]rpmmd.PackageSpec)
@ -33,6 +36,7 @@ type Base struct {
name string
build *Build
checkpoint bool
export bool
}
// Name returns the name of the pipeline. The name must be unique for a given manifest.
@ -50,6 +54,14 @@ func (p Base) getCheckpoint() bool {
return p.checkpoint
}
func (p *Base) Export() *artifact.Artifact {
panic("can't export pipeline")
}
func (p Base) getExport() bool {
return p.export
}
func (p Base) GetManifest() *Manifest {
return p.manifest
}

View file

@ -1,6 +1,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
@ -50,3 +51,9 @@ func (p *QCOW2) serialize() osbuild.Pipeline {
func (p *QCOW2) getBuildPackages() []string {
return []string{"qemu-img"}
}
func (p *QCOW2) Export() *artifact.Artifact {
p.Base.export = true
mimeType := "application/x-qemu-disk"
return artifact.New(p.Name(), p.Filename, &mimeType)
}

View file

@ -1,6 +1,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/platform"
)
@ -66,3 +67,8 @@ func (p *RawImage) serialize() osbuild.Pipeline {
return pipeline
}
func (p *RawImage) Export() *artifact.Artifact {
p.Base.export = true
return artifact.New(p.Name(), p.Filename, nil)
}

View file

@ -1,6 +1,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
@ -49,3 +50,9 @@ func (p *Tar) serialize() osbuild.Pipeline {
func (p *Tar) getBuildPackages() []string {
return []string{"tar"}
}
func (p *Tar) Export() *artifact.Artifact {
p.Base.export = true
mimeType := "application/x-tar"
return artifact.New(p.Name(), p.Filename, &mimeType)
}

View file

@ -1,6 +1,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
@ -46,3 +47,9 @@ func (p *VMDK) serialize() osbuild.Pipeline {
func (p *VMDK) getBuildPackages() []string {
return []string{"qemu-img"}
}
func (p *VMDK) Export() *artifact.Artifact {
p.Base.export = true
mimeType := "application/x-vmdk"
return artifact.New(p.Name(), p.Filename, &mimeType)
}

View file

@ -1,6 +1,7 @@
package manifest
import (
"github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/osbuild"
)
@ -45,3 +46,9 @@ func (p *VPC) serialize() osbuild.Pipeline {
func (p *VPC) getBuildPackages() []string {
return []string{"qemu-img"}
}
func (p *VPC) Export() *artifact.Artifact {
p.Base.export = true
mimeType := "application/x-vhd"
return artifact.New(p.Name(), p.Filename, &mimeType)
}