debian-forge-composer/internal/manifest/oci_container.go
Tom Gundersen 4961a17ba8 manifest: implicitly track pipelines in manifest
Pipelines are now added to their manifest on creation, and we
ensure that dependants are associated with the same manifest.
2022-07-04 23:04:29 +01:00

57 lines
1.5 KiB
Go

package manifest
import (
"github.com/osbuild/osbuild-composer/internal/osbuild2"
)
// An OCIContainerPipeline represents an OCI container, containing a filesystem
// tree created by another Pipeline.
type OCIContainerPipeline struct {
BasePipeline
Cmd []string
ExposedPorts []string
treePipeline *BasePipeline
architecture string
filename string
}
func NewOCIContainerPipeline(m *Manifest,
buildPipeline *BuildPipeline,
treePipeline *BasePipeline,
architecture,
filename string) *OCIContainerPipeline {
p := &OCIContainerPipeline{
BasePipeline: NewBasePipeline(m, "container", buildPipeline, nil),
treePipeline: treePipeline,
architecture: architecture,
filename: filename,
}
if treePipeline.build.BasePipeline.manifest != m {
panic("tree pipeline from different manifest")
}
buildPipeline.addDependent(p)
m.addPipeline(p)
return p
}
func (p *OCIContainerPipeline) serialize() osbuild2.Pipeline {
pipeline := p.BasePipeline.serialize()
options := &osbuild2.OCIArchiveStageOptions{
Architecture: p.architecture,
Filename: p.filename,
Config: &osbuild2.OCIArchiveConfig{
Cmd: p.Cmd,
ExposedPorts: p.ExposedPorts,
},
}
baseInput := new(osbuild2.OCIArchiveStageInput)
baseInput.Type = "org.osbuild.tree"
baseInput.Origin = "org.osbuild.pipeline"
baseInput.References = []string{"name:" + p.treePipeline.Name()}
inputs := &osbuild2.OCIArchiveStageInputs{Base: baseInput}
pipeline.AddStage(osbuild2.NewOCIArchiveStage(options, inputs))
return pipeline
}