config

package
v0.30.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

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

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

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a file, falling back to defaults if not found

func (*Config) GetConfigPath

func (c *Config) GetConfigPath() string

GetConfigPath returns the path to the configuration file

func (*Config) GetEnabledLanguages

func (c *Config) GetEnabledLanguages() []string

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

func (c *Config) IsFeatureEnabled(feature string) bool

IsFeatureEnabled checks if a feature flag is enabled

func (*Config) IsLanguageEnabled

func (c *Config) IsLanguageEnabled(language string) bool

IsLanguageEnabled checks if a language is enabled

func (*Config) SaveConfig

func (c *Config) SaveConfig(path string) error

SaveConfig saves the current configuration to the specified file

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the entire configuration and returns any validation errors

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

func NewProvider(config *Config) *Provider

NewProvider creates a new configuration provider with the given configuration

func (*Provider) Get

func (p *Provider) Get(key string) (interface{}, error)

Get retrieves a configuration value by key using dot notation (e.g., "container.runtime")

func (*Provider) GetBool

func (p *Provider) GetBool(key string) (bool, error)

GetBool retrieves a boolean configuration value

func (*Provider) GetBoolWithDefault

func (p *Provider) GetBoolWithDefault(key string, defaultValue bool) bool

GetBoolWithDefault retrieves a boolean value with a default fallback

func (*Provider) GetConfigPath

func (p *Provider) GetConfigPath() string

GetConfigPath returns the path to the configuration file

func (*Provider) GetDuration

func (p *Provider) GetDuration(key string) (time.Duration, error)

GetDuration retrieves a duration configuration value

func (*Provider) GetDurationWithDefault

func (p *Provider) GetDurationWithDefault(key string, defaultValue time.Duration) time.Duration

GetDurationWithDefault retrieves a duration value with a default fallback

func (*Provider) GetInt

func (p *Provider) GetInt(key string) (int, error)

GetInt retrieves an integer configuration value

func (*Provider) GetIntWithDefault

func (p *Provider) GetIntWithDefault(key string, defaultValue int) int

GetIntWithDefault retrieves an integer value with a default fallback

func (*Provider) GetString

func (p *Provider) GetString(key string) (string, error)

GetString retrieves a string configuration value

func (*Provider) GetStringMap

func (p *Provider) GetStringMap(key string) (map[string]string, error)

GetStringMap retrieves a string map configuration value

func (*Provider) GetStringSlice

func (p *Provider) GetStringSlice(key string) ([]string, error)

GetStringSlice retrieves a string slice configuration value

func (*Provider) GetStringWithDefault

func (p *Provider) GetStringWithDefault(key, defaultValue string) string

GetStringWithDefault retrieves a string value with a default fallback

func (*Provider) Has

func (p *Provider) Has(key string) bool

Has checks if a configuration key exists

func (*Provider) Reload

func (p *Provider) Reload() error

Reload reloads the configuration from the source file

func (*Provider) Validate

func (p *Provider) Validate() error

Validate validates the entire configuration

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

type ValidationError struct {
	Field   string
	Value   interface{}
	Message string
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL