Documentation
¶
Overview ¶
Package config provides centralized configuration management for engine-ci.
This package eliminates scattered configuration and magic numbers throughout the codebase by providing a unified configuration system with:
- Language-specific settings for different build environments
- Container runtime configuration and registry authentication
- Cache management with configurable strategies and limits
- Build execution parameters with retry and timeout settings
- Feature flags for gradual rollout of new functionality
- Comprehensive validation with detailed error reporting
Configuration can be loaded from YAML files, environment variables, or programmatically using the DefaultConfig() function.
Example usage:
config, err := LoadConfig("./config.yaml")
if err != nil {
log.Fatal(err)
}
// Access language-specific settings
pythonConfig := config.Languages["python"]
fmt.Printf("Python base image: %s\n", pythonConfig.BaseImage)
// Validate entire configuration
if err := ValidateConfig(config); err != nil {
log.Fatalf("Invalid configuration: %v", err)
}
This file implements the ConfigProvider interface for centralized configuration management in engine-ci.
The Provider type enables:
- Type-safe configuration access with automatic type conversion
- Dot notation for nested configuration values (e.g., "languages.python.base_image")
- Default value handling for missing configuration keys
- Environment variable override support
- Configuration validation and reloading
The provider eliminates scattered configuration access patterns throughout the codebase by centralizing all configuration operations through a single, well-defined interface.
Example usage:
provider := NewProvider(config)
// Type-safe access with error handling
pythonImage, err := provider.GetString("languages.python.base_image")
if err != nil {
log.Printf("Using default: %v", err)
}
// Access with defaults
timeout := provider.GetDurationWithDefault("build.timeout", 30*time.Minute)
// Validate entire configuration
if err := provider.Validate(); err != nil {
log.Fatalf("Invalid configuration: %v", err)
}
Index ¶
- type BuildConfig
- type CacheConfig
- type Config
- func (c *Config) GetConfigPath() string
- func (c *Config) GetEnabledLanguages() []string
- func (c *Config) GetLanguageConfig(language string) (*LanguageConfig, bool)
- func (c *Config) IsFeatureEnabled(feature string) bool
- func (c *Config) IsLanguageEnabled(language string) bool
- func (c *Config) SaveConfig(path string) error
- func (c *Config) Validate() error
- type ContainerConfig
- type FeatureFlags
- type LanguageConfig
- type LoggingConfig
- type PlatformConfig
- type Provider
- func (p *Provider) Get(key string) (interface{}, error)
- func (p *Provider) GetBool(key string) (bool, error)
- func (p *Provider) GetBoolWithDefault(key string, defaultValue bool) bool
- func (p *Provider) GetConfigPath() string
- func (p *Provider) GetDuration(key string) (time.Duration, error)
- func (p *Provider) GetDurationWithDefault(key string, defaultValue time.Duration) time.Duration
- func (p *Provider) GetInt(key string) (int, error)
- func (p *Provider) GetIntWithDefault(key string, defaultValue int) int
- func (p *Provider) GetString(key string) (string, error)
- func (p *Provider) GetStringMap(key string) (map[string]string, error)
- func (p *Provider) GetStringSlice(key string) ([]string, error)
- func (p *Provider) GetStringWithDefault(key, defaultValue string) string
- func (p *Provider) Has(key string) bool
- func (p *Provider) Reload() error
- func (p *Provider) Validate() error
- type PushConfig
- type RegistryAuth
- type RegistryConfig
- type TLSConfig
- type ValidationError
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildConfig ¶
type BuildConfig struct {
DefaultTarget string `yaml:"default_target"`
Parallel int `yaml:"parallel" validate:"min=1,max=20"`
Timeout time.Duration `yaml:"timeout" validate:"min=1m,max=8h"`
RetryCount int `yaml:"retry_count" validate:"min=0,max=5"`
RetryDelay time.Duration `yaml:"retry_delay" validate:"min=1s,max=5m"`
FailFast bool `yaml:"fail_fast"`
}
BuildConfig contains build execution configuration
type CacheConfig ¶
type CacheConfig struct {
Strategies map[string]string `yaml:"strategies"`
BaseDir string `yaml:"base_dir" validate:"required"`
MaxSize string `yaml:"max_size" validate:"required"`
TTL time.Duration `yaml:"ttl" validate:"min=1h"`
Enabled bool `yaml:"enabled"`
}
CacheConfig contains cache management configuration
type Config ¶
type Config struct {
// Language-specific settings
Languages map[string]*LanguageConfig `yaml:"languages" validate:"required"`
// Container settings
Container *ContainerConfig `yaml:"container" validate:"required"`
// Cache settings
Cache *CacheConfig `yaml:"cache" validate:"required"`
// Build settings
Build *BuildConfig `yaml:"build" validate:"required"`
// Registry settings
Registry *RegistryConfig `yaml:"registry" validate:"required"`
// Feature flags
Features *FeatureFlags `yaml:"features"`
// Logging settings
Logging *LoggingConfig `yaml:"logging"`
// contains filtered or unexported fields
}
Config represents the centralized configuration for engine-ci. This eliminates scattered configuration and magic numbers throughout the codebase.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a configuration with sensible defaults for all settings
func LoadConfig ¶
LoadConfig loads configuration from a file, falling back to defaults if not found
func (*Config) GetConfigPath ¶
GetConfigPath returns the path to the configuration file
func (*Config) GetEnabledLanguages ¶
GetEnabledLanguages returns a list of enabled languages
func (*Config) GetLanguageConfig ¶
func (c *Config) GetLanguageConfig(language string) (*LanguageConfig, bool)
GetLanguageConfig returns the configuration for a specific language
func (*Config) IsFeatureEnabled ¶
IsFeatureEnabled checks if a feature flag is enabled
func (*Config) IsLanguageEnabled ¶
IsLanguageEnabled checks if a language is enabled
func (*Config) SaveConfig ¶
SaveConfig saves the current configuration to the specified file
type ContainerConfig ¶
type ContainerConfig struct {
PlatformConfig *PlatformConfig `yaml:"platform"`
RegistryAuth map[string]*RegistryAuth `yaml:"registry_auth"`
Runtime string `yaml:"runtime" validate:"oneof=docker podman"`
DefaultUser string `yaml:"default_user"`
NetworkMode string `yaml:"network_mode"`
PullTimeout time.Duration `yaml:"pull_timeout" validate:"min=30s,max=10m"`
BuildTimeout time.Duration `yaml:"build_timeout" validate:"min=1m,max=4h"`
}
ContainerConfig contains container runtime configuration
type FeatureFlags ¶
type FeatureFlags struct {
NewLanguageBuilders bool `yaml:"new_language_builders"`
CentralizedConfig bool `yaml:"centralized_config"`
EnhancedErrorHandling bool `yaml:"enhanced_error_handling"`
ParallelOptimization bool `yaml:"parallel_optimization"`
AdvancedCaching bool `yaml:"advanced_caching"`
DetailedLogging bool `yaml:"detailed_logging"`
}
FeatureFlags contains feature flag configuration
type LanguageConfig ¶
type LanguageConfig struct {
Environment map[string]string `yaml:"environment"` // Container environment variables
BaseImage string `yaml:"base_image" validate:"required"` // Base container image
CacheLocation string `yaml:"cache_location" validate:"required"` // Dependency cache directory
WorkingDir string `yaml:"working_dir"` // Container working directory
ProdImage string `yaml:"prod_image,omitempty"` // Production image override
CustomArgs []string `yaml:"custom_args"` // Additional toolchain arguments
BuildTimeout time.Duration `yaml:"build_timeout" validate:"min=1m,max=2h"` // Maximum build duration
Enabled bool `yaml:"enabled"` // Whether this language is enabled
}
LanguageConfig contains language-specific configuration settings. This structure centralizes all language-specific parameters that were previously scattered as constants throughout individual language packages.
Fields:
- Environment: Environment variables to set in the build container
- BaseImage: The base container image for this language (e.g., "python:3.11-slim-bookworm")
- CacheLocation: Directory inside container where dependencies are cached
- WorkingDir: Working directory inside the build container (defaults to "/src")
- ProdImage: Optional production-ready image override
- CustomArgs: Additional command-line arguments for the language toolchain
- BuildTimeout: Maximum time allowed for builds (1m-2h range)
- Enabled: Whether this language builder is active
type LoggingConfig ¶
type LoggingConfig struct {
Level string `yaml:"level" validate:"oneof=debug info warn error"`
Format string `yaml:"format" validate:"oneof=text json"`
Output string `yaml:"output"`
TimeFormat string `yaml:"time_format"`
AddSource bool `yaml:"add_source"`
}
LoggingConfig contains logging configuration
type PlatformConfig ¶
type PlatformConfig struct {
Host string `yaml:"host"`
Container string `yaml:"container"`
Supported []string `yaml:"supported"`
}
PlatformConfig contains platform-specific settings
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the ConfigProvider interface for centralized configuration management
func NewProvider ¶
NewProvider creates a new configuration provider with the given configuration
func (*Provider) Get ¶
Get retrieves a configuration value by key using dot notation (e.g., "container.runtime")
func (*Provider) GetBoolWithDefault ¶
GetBoolWithDefault retrieves a boolean value with a default fallback
func (*Provider) GetConfigPath ¶
GetConfigPath returns the path to the configuration file
func (*Provider) GetDuration ¶
GetDuration retrieves a duration configuration value
func (*Provider) GetDurationWithDefault ¶
GetDurationWithDefault retrieves a duration value with a default fallback
func (*Provider) GetIntWithDefault ¶
GetIntWithDefault retrieves an integer value with a default fallback
func (*Provider) GetStringMap ¶
GetStringMap retrieves a string map configuration value
func (*Provider) GetStringSlice ¶
GetStringSlice retrieves a string slice configuration value
func (*Provider) GetStringWithDefault ¶
GetStringWithDefault retrieves a string value with a default fallback
type PushConfig ¶
type PushConfig struct {
RetryCount int `yaml:"retry_count" validate:"min=0,max=10"`
RetryDelay time.Duration `yaml:"retry_delay" validate:"min=1s,max=30s"`
Enabled bool `yaml:"enabled"`
RemoveAfterPush bool `yaml:"remove_after_push"`
}
PushConfig contains image push configuration
type RegistryAuth ¶
type RegistryAuth struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Token string `yaml:"token,omitempty"`
}
RegistryAuth contains authentication information for container registries
type RegistryConfig ¶
type RegistryConfig struct {
TLS *TLSConfig `yaml:"tls"`
PushConfig *PushConfig `yaml:"push"`
Default string `yaml:"default" validate:"required"`
Mirrors []string `yaml:"mirrors"`
Insecure []string `yaml:"insecure"`
Timeout time.Duration `yaml:"timeout" validate:"min=30s,max=10m"`
}
RegistryConfig contains container registry configuration
type TLSConfig ¶
type TLSConfig struct {
CertFile string `yaml:"cert_file"`
KeyFile string `yaml:"key_file"`
CAFile string `yaml:"ca_file"`
InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
}
TLSConfig contains TLS configuration for registries
type ValidationError ¶
ValidationError represents a configuration validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors represents multiple validation errors
func (ValidationErrors) Error ¶
func (e ValidationErrors) Error() string