Documentation
¶
Overview ¶
Package build defines the core interfaces and contracts for the engine-ci build system.
This package provides the foundational interfaces that eliminate code duplication across language packages and enable a modular, extensible build architecture:
- LanguageBuilder: Contract for all language-specific builders
- BuildStep: Individual build pipeline steps with dependencies
- ConfigProvider: Centralized configuration management
- CacheManager: Language-specific cache management
- BuildOrchestrator: Multi-step build coordination with parallel execution
- ErrorHandler: Standardized error handling replacing os.Exit(1) patterns
- Validator: Configuration and component validation
These interfaces replace the previous scattered, duplicated code patterns with a cohesive architecture that supports:
- Interface-driven development for better testing and modularity
- Shared functionality through composition rather than inheritance
- Standardized error handling with context and recovery
- Configurable build pipelines with dependency resolution
- Language-agnostic caching strategies
- Parallel execution with proper synchronization
Example usage:
// Implement a language builder
type PythonBuilder struct {
*language.BaseLanguageBuilder
}
func (p *PythonBuilder) BuildImage(ctx context.Context) (string, error) {
// Language-specific build logic
}
// Use build orchestrator
orchestrator := NewBuildOrchestrator()
orchestrator.AddStep(pythonStep)
orchestrator.AddStep(dockerStep)
if err := orchestrator.Execute(ctx); err != nil {
// Handle build failures with proper error context
}
Index ¶
- type Build
- type BuildContext
- type BuildOrchestrator
- type BuildStep
- type BuildStepStatus
- type BuildSteps
- func (bs *BuildSteps) Add(step Build)
- func (bs *BuildSteps) AddAsync(step Build)
- func (bs *BuildSteps) Images(step ...string) []string
- func (bs *BuildSteps) Init()
- func (bs *BuildSteps) IsNotInit() bool
- func (bs *BuildSteps) PrintSteps()
- func (bs *BuildSteps) Run(step ...string) error
- func (bs *BuildSteps) String() string
- type CacheManager
- type ConfigProvider
- type ErrorHandler
- type ErrorSeverity
- type LanguageBuilder
- type RunFunc
- type ValidationResult
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildContext ¶
type BuildContext struct {
// contains filtered or unexported fields
}
func ToBuildContexts ¶ added in v0.2.1
func ToBuildContexts(steps ...Build) []*BuildContext
type BuildOrchestrator ¶ added in v0.20.0
type BuildOrchestrator interface {
// Build step management
AddStep(step BuildStep) error // Adds a build step to the orchestrator
AddSteps(steps ...BuildStep) error // Adds multiple build steps
RemoveStep(name string) error // Removes a build step by name
// Execution
Execute(ctx context.Context) error // Executes all build steps
ExecuteStep(ctx context.Context, name string) error // Executes a specific step
ExecuteSteps(ctx context.Context, names ...string) error // Executes specific steps
// Dependency management
ResolveDependencies() ([][]string, error) // Returns build steps organized by execution order
ValidateDependencies() error // Validates that all dependencies can be resolved
// Status and monitoring
GetStepStatus(name string) BuildStepStatus // Returns the status of a specific step
GetAllStepStatuses() map[string]BuildStepStatus // Returns status of all steps
// Configuration
SetMaxParallel(max int) // Sets maximum number of parallel steps
SetGlobalTimeout(timeout time.Duration) // Sets overall execution timeout
}
BuildOrchestrator manages the execution of multiple build steps with dependency resolution, parallel execution, and error handling.
type BuildStep ¶ added in v0.20.0
type BuildStep interface {
// Core identification
Name() string // Returns a human-readable name for this step
// Execution
Execute(ctx context.Context) error // Executes the build step
// Dependencies and ordering
Dependencies() []string // Returns the names of steps this step depends on
IsAsync() bool // Indicates if this step can run in parallel with others
// Configuration
Timeout() time.Duration // Returns the maximum execution time for this step
// Validation
Validate() error // Validates the step configuration before execution
}
BuildStep represents a single step in the build pipeline. This interface enables better orchestration, dependency management, and validation of build operations.
type BuildStepStatus ¶ added in v0.20.0
type BuildStepStatus int
BuildStepStatus represents the current status of a build step
const ( StatusPending BuildStepStatus = iota StatusRunning StatusCompleted StatusFailed StatusSkipped )
func (BuildStepStatus) String ¶ added in v0.20.0
func (s BuildStepStatus) String() string
type BuildSteps ¶
type BuildSteps struct {
Steps []*BuildContext
// contains filtered or unexported fields
}
func NewBuildSteps ¶
func NewBuildSteps(steps ...Build) *BuildSteps
func NewBuildStepsWithArg ¶ added in v0.11.0
func NewBuildStepsWithArg(arg container.Build, steps ...Build) *BuildSteps
func (*BuildSteps) Add ¶
func (bs *BuildSteps) Add(step Build)
func (*BuildSteps) AddAsync ¶
func (bs *BuildSteps) AddAsync(step Build)
func (*BuildSteps) Images ¶
func (bs *BuildSteps) Images(step ...string) []string
func (*BuildSteps) Init ¶ added in v0.2.1
func (bs *BuildSteps) Init()
func (*BuildSteps) IsNotInit ¶ added in v0.2.1
func (bs *BuildSteps) IsNotInit() bool
func (*BuildSteps) PrintSteps ¶
func (bs *BuildSteps) PrintSteps()
func (*BuildSteps) Run ¶
func (bs *BuildSteps) Run(step ...string) error
func (*BuildSteps) String ¶
func (bs *BuildSteps) String() string
type CacheManager ¶ added in v0.20.0
type CacheManager interface {
// Cache directory management
GetCacheDir(language string) (string, error) // Returns the cache directory for a language
EnsureCacheDir(language string) error // Ensures the cache directory exists
CleanCache(language string) error // Cleans the cache for a specific language
CleanAllCaches() error // Cleans all language caches
// Cache key generation
CacheKey(language string, dependencies []string) string // Generates a cache key
// Cache metadata
CacheSize(language string) (int64, error) // Returns the size of a language's cache
CacheLastUsed(language string) (time.Time, error) // Returns when the cache was last used
// Cache configuration
SetMaxSize(language string, maxSize int64) error // Sets maximum cache size for a language
SetTTL(language string, ttl time.Duration) error // Sets time-to-live for cache entries
}
CacheManager handles caching strategies for different languages. This interface standardizes cache management across all language builders and provides configurable caching strategies.
type ConfigProvider ¶ added in v0.20.0
type ConfigProvider interface {
// Generic configuration access
Get(key string) (interface{}, error)
Has(key string) bool
// Type-safe configuration access
GetString(key string) (string, error)
GetInt(key string) (int, error)
GetBool(key string) (bool, error)
GetDuration(key string) (time.Duration, error)
GetStringSlice(key string) ([]string, error)
GetStringMap(key string) (map[string]string, error)
// Configuration with defaults
GetStringWithDefault(key, defaultValue string) string
GetIntWithDefault(key string, defaultValue int) int
GetBoolWithDefault(key string, defaultValue bool) bool
GetDurationWithDefault(key string, defaultValue time.Duration) time.Duration
// Validation and management
Validate() error // Validates the entire configuration
Reload() error // Reloads configuration from source
GetConfigPath() string // Returns the path to the configuration file
}
ConfigProvider manages configuration for different components. This interface centralizes configuration management and enables validation and type-safe configuration access.
type ErrorHandler ¶ added in v0.20.0
type ErrorHandler interface {
// Error handling
HandleError(err error, context string) error // Handles and potentially recovers from errors
WrapError(err error, operation string) error // Wraps errors with additional context
// Error classification
IsRetryable(err error) bool // Determines if an error is retryable
IsTemporary(err error) bool // Determines if an error is temporary
GetErrorSeverity(err error) ErrorSeverity // Returns the severity of an error
// Recovery
SuggestRecovery(err error) []string // Suggests recovery actions for an error
}
ErrorHandler provides standardized error handling across the build system. This interface replaces the scattered os.Exit(1) patterns with proper error handling and recovery mechanisms.
type ErrorSeverity ¶ added in v0.20.0
type ErrorSeverity int
ErrorSeverity represents the severity level of an error
const ( SeverityInfo ErrorSeverity = iota SeverityWarning SeverityError SeverityFatal )
func (ErrorSeverity) String ¶ added in v0.20.0
func (s ErrorSeverity) String() string
type LanguageBuilder ¶ added in v0.20.0
type LanguageBuilder interface {
// Core identification methods
Name() string // Returns the name of the language (e.g., "golang", "python", "maven")
IsAsync() bool // Indicates if this builder can run asynchronously
// Image management methods
BaseImage() string // Returns the base container image for this language
Images() []string // Returns all images required by this builder
BuildImage() (string, error) // Builds the intermediate language-specific image
ComputeImageTag(data []byte) string // Computes a deterministic tag from dockerfile content
// Container operations
Pull() error // Pulls required base images
Build() (string, error) // Executes the build process and returns the resulting image ID
// Configuration methods
CacheLocation() string // Returns the default cache directory inside the container
DefaultEnvironment() []string // Returns default environment variables for this language
BuildTimeout() time.Duration // Returns the maximum build time allowed
// Build script generation
BuildScript() string // Generates the build script for this language
// Lifecycle management
PreBuild() error // Executes pre-build setup operations
PostBuild() error // Executes post-build cleanup operations
// Validation
Validate() error // Validates the builder configuration and dependencies
}
LanguageBuilder defines the contract for all language-specific builders. This interface eliminates code duplication across language packages by providing a common set of operations that all language builders must implement.
type ValidationResult ¶ added in v0.20.0
type ValidationResult struct {
Context map[string]interface{}
Errors []error
Warnings []string
IsValid bool
}
ValidationResult represents the result of a validation operation
type Validator ¶ added in v0.20.0
type Validator interface {
Validate(ctx context.Context, target interface{}) (*ValidationResult, error)
ValidateConfiguration(config interface{}) (*ValidationResult, error)
ValidateBuildStep(step BuildStep) (*ValidationResult, error)
ValidateLanguageBuilder(builder LanguageBuilder) (*ValidationResult, error)
}
Validator provides validation capabilities for different components