store: merge the compose package into the store
The types exposed by the compose package are only used in the store API, so move them there where they belong. Making the ownership of the types clear, rather than having them live in a package for themselves, will make it clearer how the types can be modified in follow-up commits. Also remove the JSON annotations, as these types are no longer used for serialization. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
571a21c3ac
commit
df7a0fec22
7 changed files with 44 additions and 52 deletions
99
internal/store/compose.go
Normal file
99
internal/store/compose.go
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
)
|
||||
|
||||
type StateTransitionError struct {
|
||||
message string
|
||||
}
|
||||
|
||||
func (ste *StateTransitionError) Error() string {
|
||||
return ste.message
|
||||
}
|
||||
|
||||
// ImageBuild represents a single image build inside a compose
|
||||
type ImageBuild struct {
|
||||
Id int
|
||||
ImageType common.ImageType
|
||||
Manifest *osbuild.Manifest
|
||||
Targets []*target.Target
|
||||
JobCreated time.Time
|
||||
JobStarted time.Time
|
||||
JobFinished time.Time
|
||||
Size uint64
|
||||
JobId uuid.UUID
|
||||
// Kept for backwards compatibility. Image builds which were done
|
||||
// before the move to the job queue use this to store whether they
|
||||
// finished successfully.
|
||||
QueueStatus common.ImageBuildState
|
||||
}
|
||||
|
||||
// DeepCopy creates a copy of the ImageBuild structure
|
||||
func (ib *ImageBuild) DeepCopy() ImageBuild {
|
||||
var newManifestPtr *osbuild.Manifest = nil
|
||||
if ib.Manifest != nil {
|
||||
manifestCopy := *ib.Manifest
|
||||
newManifestPtr = &manifestCopy
|
||||
}
|
||||
var newTargets []*target.Target
|
||||
for _, t := range ib.Targets {
|
||||
newTarget := *t
|
||||
newTargets = append(newTargets, &newTarget)
|
||||
}
|
||||
// Create new image build struct
|
||||
return ImageBuild{
|
||||
Id: ib.Id,
|
||||
QueueStatus: ib.QueueStatus,
|
||||
ImageType: ib.ImageType,
|
||||
Manifest: newManifestPtr,
|
||||
Targets: newTargets,
|
||||
JobCreated: ib.JobCreated,
|
||||
JobStarted: ib.JobStarted,
|
||||
JobFinished: ib.JobFinished,
|
||||
Size: ib.Size,
|
||||
JobId: ib.JobId,
|
||||
}
|
||||
}
|
||||
|
||||
func (ib *ImageBuild) GetLocalTargetOptions() *target.LocalTargetOptions {
|
||||
for _, t := range ib.Targets {
|
||||
switch options := t.Options.(type) {
|
||||
case *target.LocalTargetOptions:
|
||||
return options
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// A Compose represent the task of building a set of images from a single blueprint.
|
||||
// It contains all the information necessary to generate the inputs for the job, as
|
||||
// well as the job's state.
|
||||
type Compose struct {
|
||||
Blueprint *blueprint.Blueprint
|
||||
ImageBuilds []ImageBuild
|
||||
}
|
||||
|
||||
// DeepCopy creates a copy of the Compose structure
|
||||
func (c *Compose) DeepCopy() Compose {
|
||||
var newBpPtr *blueprint.Blueprint = nil
|
||||
if c.Blueprint != nil {
|
||||
bpCopy := *c.Blueprint
|
||||
newBpPtr = &bpCopy
|
||||
}
|
||||
newImageBuilds := []ImageBuild{}
|
||||
for _, ib := range c.ImageBuilds {
|
||||
newImageBuilds = append(newImageBuilds, ib.DeepCopy())
|
||||
}
|
||||
return Compose{
|
||||
Blueprint: newBpPtr,
|
||||
ImageBuilds: newImageBuilds,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue