- Add internal/phases/ with complete phase management system - Add internal/types/ with core data structures - Add internal/treefile/ for OSTree treefile generation - Update examples with YAML configurations - Update .gitignore to properly exclude test artifacts and build outputs - Update dependencies and configuration files
331 lines
9.6 KiB
Go
331 lines
9.6 KiB
Go
package types
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
// Engine represents the interface that phases need to interact with the compose engine
|
|
type Engine interface {
|
|
// Configuration
|
|
GetConfig() *Config
|
|
GetTreefile() *Treefile
|
|
GetOutputDir() string
|
|
GetWorkDir() string
|
|
|
|
// Logging
|
|
GetLogger() *log.Logger
|
|
|
|
// Systems
|
|
GetBuildSystem() BuildSystem
|
|
GetOSTreeTool() OSTreeTool
|
|
GetOutputManager() OutputManager
|
|
}
|
|
|
|
// Config represents the compose configuration
|
|
type Config struct {
|
|
// Release information
|
|
Release struct {
|
|
Name string `yaml:"name"`
|
|
Short string `yaml:"short"`
|
|
Version string `yaml:"version"`
|
|
Type string `yaml:"type"`
|
|
Internal bool `yaml:"internal"`
|
|
} `yaml:"release"`
|
|
|
|
// Build system configuration
|
|
BuildSystem struct {
|
|
Type string `yaml:"type"`
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
AuthToken string `yaml:"auth_token"`
|
|
MaxWorkers int `yaml:"max_workers"`
|
|
} `yaml:"build_system"`
|
|
|
|
// OSTree configuration
|
|
OSTree struct {
|
|
Repository string `yaml:"repository"`
|
|
Mode string `yaml:"mode"`
|
|
Signing struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
Key string `yaml:"key"`
|
|
} `yaml:"signing"`
|
|
} `yaml:"ostree"`
|
|
|
|
// Output configuration
|
|
Output struct {
|
|
Formats []string `yaml:"formats"`
|
|
DiskImage struct {
|
|
Formats []string `yaml:"formats"`
|
|
Size string `yaml:"size"`
|
|
} `yaml:"disk_image"`
|
|
Container struct {
|
|
Registry string `yaml:"registry"`
|
|
Tag string `yaml:"tag"`
|
|
} `yaml:"container"`
|
|
} `yaml:"output"`
|
|
|
|
// Repository configuration
|
|
Repositories []Repository `yaml:"repositories"`
|
|
|
|
// Variants configuration
|
|
Variants []Variant `yaml:"variants"`
|
|
|
|
// Architecture configuration
|
|
Architectures []string `yaml:"architectures"`
|
|
|
|
// Logging configuration
|
|
Logging struct {
|
|
Level string `yaml:"level"`
|
|
File string `yaml:"file"`
|
|
Format string `yaml:"format"`
|
|
} `yaml:"logging"`
|
|
|
|
// Cache configuration
|
|
Cache struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
Dir string `yaml:"dir"`
|
|
Size string `yaml:"size"`
|
|
} `yaml:"cache"`
|
|
}
|
|
|
|
// Repository represents a Debian package repository
|
|
type Repository struct {
|
|
Name string `yaml:"name"`
|
|
URL string `yaml:"url"`
|
|
Suite string `yaml:"suite"`
|
|
Component string `yaml:"component"`
|
|
Arch string `yaml:"arch"`
|
|
Enabled bool `yaml:"enabled"`
|
|
}
|
|
|
|
// Variant represents a Debian variant
|
|
type Variant struct {
|
|
Name string `yaml:"name"`
|
|
Description string `yaml:"description"`
|
|
Architectures []string `yaml:"architectures"`
|
|
Packages VariantPackages `yaml:"packages"`
|
|
Exclude []string `yaml:"exclude"`
|
|
Config map[string]interface{} `yaml:"config"`
|
|
}
|
|
|
|
// VariantPackages defines package sets for a variant
|
|
type VariantPackages struct {
|
|
Required []string `yaml:"required"`
|
|
Optional []string `yaml:"optional"`
|
|
Recommended []string `yaml:"recommended"`
|
|
Development []string `yaml:"development"`
|
|
Kernel []string `yaml:"kernel"`
|
|
Bootloader []string `yaml:"bootloader"`
|
|
}
|
|
|
|
// Treefile represents a Debian treefile manifest
|
|
type Treefile struct {
|
|
// Basic information
|
|
Name string `json:"name"`
|
|
Version string `json:"version"`
|
|
Description string `json:"description"`
|
|
Release string `json:"release"`
|
|
|
|
// Package configuration
|
|
Packages PackageSet `json:"packages"`
|
|
Exclude []string `json:"exclude"`
|
|
|
|
// Repository configuration
|
|
Repositories []Repository `json:"repositories"`
|
|
|
|
// Architecture and variant configuration
|
|
Architecture []string `json:"architecture"`
|
|
Variants []Variant `json:"variants"`
|
|
|
|
// Build configuration
|
|
Build struct {
|
|
Type string `json:"type"`
|
|
Environment map[string]string `json:"environment"`
|
|
Options map[string]interface{} `json:"options"`
|
|
} `json:"build"`
|
|
|
|
// OSTree configuration
|
|
OSTree struct {
|
|
Ref string `json:"ref"`
|
|
Parent string `json:"parent"`
|
|
Subject string `json:"subject"`
|
|
Body string `json:"body"`
|
|
Timestamp string `json:"timestamp"`
|
|
} `json:"ostree"`
|
|
|
|
// Output configuration
|
|
Output struct {
|
|
Formats []string `json:"formats"`
|
|
Container struct {
|
|
BaseImage string `json:"base_image"`
|
|
Labels map[string]string `json:"labels"`
|
|
Entrypoint []string `json:"entrypoint"`
|
|
CMD []string `json:"cmd"`
|
|
} `json:"container"`
|
|
DiskImage struct {
|
|
Size string `json:"size"`
|
|
Formats []string `json:"formats"`
|
|
Bootloader string `json:"bootloader"`
|
|
Kernel string `json:"kernel"`
|
|
Initramfs bool `json:"initramfs"`
|
|
} `json:"disk_image"`
|
|
} `json:"output"`
|
|
|
|
// Metadata
|
|
Metadata map[string]interface{} `json:"metadata"`
|
|
}
|
|
|
|
// PackageSet defines the packages to include in the image
|
|
type PackageSet struct {
|
|
Required []string `json:"required"`
|
|
Optional []string `json:"optional"`
|
|
Recommended []string `json:"recommended"`
|
|
Development []string `json:"development"`
|
|
Kernel []string `json:"kernel"`
|
|
Bootloader []string `json:"bootloader"`
|
|
}
|
|
|
|
// GetPackagesForVariant returns all packages for a specific variant and architecture
|
|
func (t *Treefile) GetPackagesForVariant(variantName, arch string) PackageSet {
|
|
var result PackageSet
|
|
|
|
// Find the variant
|
|
var variant *Variant
|
|
for _, v := range t.Variants {
|
|
if v.Name == variantName {
|
|
variant = &v
|
|
break
|
|
}
|
|
}
|
|
|
|
if variant == nil {
|
|
return result
|
|
}
|
|
|
|
// Check if architecture is supported by this variant
|
|
archSupported := false
|
|
for _, variantArch := range variant.Architectures {
|
|
if variantArch == arch {
|
|
archSupported = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !archSupported {
|
|
return result
|
|
}
|
|
|
|
// Merge global packages with variant packages
|
|
result.Required = append(t.Packages.Required, variant.Packages.Required...)
|
|
result.Optional = append(t.Packages.Optional, variant.Packages.Optional...)
|
|
result.Recommended = append(t.Packages.Recommended, variant.Packages.Recommended...)
|
|
result.Development = append(t.Packages.Development, variant.Packages.Development...)
|
|
result.Kernel = append(t.Packages.Kernel, variant.Packages.Kernel...)
|
|
result.Bootloader = append(t.Packages.Bootloader, variant.Packages.Bootloader...)
|
|
|
|
return result
|
|
}
|
|
|
|
// GetExcludedPackagesForVariant returns excluded packages for a specific variant and architecture
|
|
func (t *Treefile) GetExcludedPackagesForVariant(variantName, arch string) []string {
|
|
var result []string
|
|
|
|
// Add global excludes
|
|
result = append(result, t.Exclude...)
|
|
|
|
// Find the variant and add its excludes
|
|
for _, v := range t.Variants {
|
|
if v.Name == variantName {
|
|
result = append(result, v.Exclude...)
|
|
break
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// GetOSTreeRef returns the OSTree reference for a variant and architecture
|
|
func (t *Treefile) GetOSTreeRef(variantName, arch string) string {
|
|
if t.OSTree.Ref != "" {
|
|
return t.OSTree.Ref
|
|
}
|
|
|
|
// Generate default reference
|
|
return fmt.Sprintf("%s/%s/%s/%s", t.Release, t.Version, arch, variantName)
|
|
}
|
|
|
|
// BuildSystem represents the interface to the build system
|
|
type BuildSystem interface {
|
|
TestConnection() error
|
|
CreateBuildEnvironment(arch string) (*BuildEnvironment, error)
|
|
InstallDependencies(packages []string, arch string) error
|
|
BuildPackage(packageName, arch string) (*BuildResult, error)
|
|
WaitForBuild(buildID string, timeout time.Duration) (*BuildResult, error)
|
|
GetBuildStatus(buildID string) (*BuildStatus, error)
|
|
CleanupBuildEnvironment(env *BuildEnvironment) error
|
|
}
|
|
|
|
// BuildEnvironment represents a build environment
|
|
type BuildEnvironment struct {
|
|
ID string `json:"id"`
|
|
Arch string `json:"arch"`
|
|
Status string `json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Metadata map[string]string `json:"metadata"`
|
|
Environment map[string]string `json:"environment"`
|
|
}
|
|
|
|
// BuildResult represents the result of a build
|
|
type BuildResult struct {
|
|
ID string `json:"id"`
|
|
PackageName string `json:"package_name"`
|
|
Arch string `json:"arch"`
|
|
Status string `json:"status"`
|
|
Result string `json:"result"`
|
|
StartedAt time.Time `json:"started_at"`
|
|
CompletedAt time.Time `json:"completed_at"`
|
|
Logs []string `json:"logs"`
|
|
Artifacts []string `json:"artifacts"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// BuildStatus represents the status of a build
|
|
type BuildStatus struct {
|
|
ID string `json:"id"`
|
|
Status string `json:"status"`
|
|
Progress int `json:"progress"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// OSTreeTool represents the interface to the OSTree tool
|
|
type OSTreeTool interface {
|
|
InitRepo() error
|
|
CreateCommit(ref, subject, body string, packages []string) (string, error)
|
|
GetCommit(commitID string) (*CommitInfo, error)
|
|
ListRefs() ([]string, error)
|
|
UpdateRef(ref, commitID string) error
|
|
CreateArchive(ref, outputPath string) error
|
|
ValidateCommit(commitID string) error
|
|
}
|
|
|
|
// CommitInfo represents information about an OSTree commit
|
|
type CommitInfo struct {
|
|
ID string `json:"id"`
|
|
Ref string `json:"ref"`
|
|
Subject string `json:"subject"`
|
|
Body string `json:"body"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Parent string `json:"parent,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata"`
|
|
}
|
|
|
|
// OutputManager represents the interface for managing output artifacts
|
|
type OutputManager interface {
|
|
GenerateContainerImage(commitID, outputPath string, config map[string]interface{}) error
|
|
GenerateDiskImage(commitID, outputPath string, config map[string]interface{}) error
|
|
GenerateTarball(commitID, outputPath string, config map[string]interface{}) error
|
|
ValidateOutput(outputPath string, config map[string]interface{}) error
|
|
CleanupOutput(outputPath string) error
|
|
}
|