config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEnvFile

func LoadEnvFile(path string) (map[string]string, error)

LoadEnvFile reads a .env file and returns a map of environment variables Supports: - KEY=value format - Comments (lines starting with #) - Empty lines - Single and double quoted values - Variable expansion ${VAR} syntax

func MergeEnvVars

func MergeEnvVars(explicitEnv map[string]string, envFileVars map[string]string) map[string]string

MergeEnvVars merges environment variables from multiple sources Priority (highest to lowest): 1. Explicit env vars from config (service.Env) 2. Variables from envFile (service.EnvFile) 3. System environment variables (already expanded via ${VAR} syntax)

func ValidateConfig

func ValidateConfig(cfg *Config) error

ValidateConfig validates the configuration

Types

type BackupConfig

type BackupConfig struct {
	Schedule string `yaml:"schedule"` // cron format (e.g., "0 2 * * *")
	Retain   int    `yaml:"retain"`   // days to retain backups
}

BackupConfig defines per-service backup settings

type CacheConfig

type CacheConfig struct {
	Enabled   bool   `yaml:"enabled,omitempty"`   // Enable build caching (default: true)
	Type      string `yaml:"type,omitempty"`      // "local" (default), "registry"
	Retention string `yaml:"retention,omitempty"` // Cache retention period (e.g., "7d")
}

CacheConfig defines build caching settings

type Config

type Config struct {
	Project      ProjectConfig                `yaml:"project"`
	Deployment   *DeploymentConfig            `yaml:"deployment,omitempty"`
	Servers      map[string]ServerConfig      `yaml:"servers"`
	Environments map[string]EnvironmentConfig `yaml:"environments"`
}

Config represents the main configuration structure

func LoadConfig

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

LoadConfig loads the configuration from a YAML file

func (*Config) GetDefaultEnvironment

func (c *Config) GetDefaultEnvironment() string

GetDefaultEnvironment returns the default environment name Returns "production" if it exists, otherwise the first environment

func (*Config) GetDeploymentStrategy

func (c *Config) GetDeploymentStrategy() string

GetDeploymentStrategy returns the deployment strategy (parallel or sequential)

func (*Config) GetEnvironment

func (c *Config) GetEnvironment(name string) (*EnvironmentConfig, error)

GetEnvironment retrieves a specific environment configuration If name is empty, returns the default environment

func (*Config) GetEnvironmentServers

func (c *Config) GetEnvironmentServers(envName string) ([]string, error)

GetEnvironmentServers returns the list of servers for an environment

func (*Config) GetFullImageName

func (c *Config) GetFullImageName(serviceName string, envName string) string

GetFullImageName returns the full image name with registry and environment tag

func (*Config) GetManagerServer

func (c *Config) GetManagerServer(envName string) (string, error)

GetManagerServer returns the manager server for a given environment

func (*Config) GetMaxConcurrentBuilds

func (c *Config) GetMaxConcurrentBuilds() int

GetMaxConcurrentBuilds returns the max concurrent builds configuration

func (*Config) GetMaxConcurrentDeploys

func (c *Config) GetMaxConcurrentDeploys() int

GetMaxConcurrentDeploys returns the max concurrent deploys configuration

func (*Config) GetRegistryURL

func (c *Config) GetRegistryURL() string

GetRegistryURL returns the auto-configured local registry URL Returns empty string for single-server deployments (no registry needed)

func (*Config) GetService

func (c *Config) GetService(envName string, serviceName string) (*ServiceConfig, error)

GetService returns a specific service from an environment

func (*Config) GetServices

func (c *Config) GetServices(envName string) (map[string]ServiceConfig, error)

GetServices returns services for a specific environment

func (*Config) IsCacheEnabled

func (c *Config) IsCacheEnabled() bool

IsCacheEnabled returns true if build caching is enabled

func (*Config) IsMultiServer

func (c *Config) IsMultiServer() bool

IsMultiServer returns true if more than one server is configured

func (*Config) IsParallelDeployment

func (c *Config) IsParallelDeployment() bool

IsParallelDeployment returns true if parallel deployment is enabled

type DeployConfig

type DeployConfig struct {
	Strategy       string `yaml:"strategy"` // blue-green or rolling
	MaxUnavailable int    `yaml:"maxUnavailable,omitempty"`
}

DeployConfig defines deployment strategy

type DeploymentConfig

type DeploymentConfig struct {
	Strategy string          `yaml:"strategy,omitempty"` // "parallel" or "sequential" (default: sequential)
	Parallel *ParallelConfig `yaml:"parallel,omitempty"`
	Cache    *CacheConfig    `yaml:"cache,omitempty"`
}

DeploymentConfig defines deployment optimization settings

type EnvironmentConfig

type EnvironmentConfig struct {
	Servers        []string                 `yaml:"servers"`                  // List of server names to use
	ServerSelector *ServerSelector          `yaml:"serverSelector,omitempty"` // Label-based server selection
	Labels         map[string]string        `yaml:"labels,omitempty"`         // Environment labels for Docker nodes
	Services       map[string]ServiceConfig `yaml:"services"`                 // Services to deploy in this environment
}

EnvironmentConfig defines an environment (production, staging, etc.)

type HealthCheckConfig

type HealthCheckConfig struct {
	Path        string `yaml:"path"`
	Interval    string `yaml:"interval"`
	Timeout     string `yaml:"timeout"`
	Retries     int    `yaml:"retries"`
	StartPeriod string `yaml:"startPeriod,omitempty"` // Grace period before starting checks
}

HealthCheckConfig defines health check settings

type HooksConfig

type HooksConfig struct {
	PreBuild   []string `yaml:"preBuild,omitempty"`   // Before building Docker image
	PostBuild  []string `yaml:"postBuild,omitempty"`  // After building Docker image
	PreDeploy  []string `yaml:"preDeploy,omitempty"`  // Before deploying service to swarm
	PostDeploy []string `yaml:"postDeploy,omitempty"` // After deploying service to swarm
	PostStart  []string `yaml:"postStart,omitempty"`  // After service is running (can use docker exec)
}

HooksConfig defines per-service pre/post deployment hooks

type LoadBalancerConfig

type LoadBalancerConfig struct {
	Strategy    string                  `yaml:"strategy"` // round_robin, least_conn, ip_hash, random
	HealthCheck LoadBalancerHealthCheck `yaml:"healthCheck,omitempty"`
}

LoadBalancerConfig defines load balancing settings

type LoadBalancerHealthCheck

type LoadBalancerHealthCheck struct {
	Enabled  bool   `yaml:"enabled"`
	Path     string `yaml:"path"`
	Interval string `yaml:"interval"`
}

LoadBalancerHealthCheck defines load balancer health check settings

type MonitoringConfig

type MonitoringConfig struct {
	Enabled   bool   `yaml:"enabled"`             // Enable monitoring for this service
	Interval  string `yaml:"interval,omitempty"`  // Check interval (e.g., "60s")
	Webhook   string `yaml:"webhook,omitempty"`   // Webhook URL for alerts
	CheckType string `yaml:"checkType,omitempty"` // "http" or "container" (default: auto-detect)
}

MonitoringConfig defines per-service monitoring settings

type ParallelConfig

type ParallelConfig struct {
	MaxConcurrentBuilds  int    `yaml:"maxConcurrentBuilds,omitempty"`  // Default: 4
	MaxConcurrentDeploys int    `yaml:"maxConcurrentDeploys,omitempty"` // Default: 4
	Strategy             string `yaml:"strategy,omitempty"`             // "dependency-aware" (default), "resource-aware", "round-robin"
}

ParallelConfig defines parallel deployment settings

type PlacementConfig

type PlacementConfig struct {
	Strategy    string   `yaml:"strategy,omitempty"`    // "spread", "pinned", "any"
	Servers     []string `yaml:"servers,omitempty"`     // Pin to specific servers (for "pinned" strategy)
	Constraints []string `yaml:"constraints,omitempty"` // Docker Swarm constraints (e.g., "node.labels.type==high-memory")
	Preferences []string `yaml:"preferences,omitempty"` // Docker Swarm placement preferences (e.g., "spread=node.labels.region")
}

PlacementConfig defines where service replicas should run

type ProjectConfig

type ProjectConfig struct {
	Name    string `yaml:"name"`
	Version string `yaml:"version"`
}

ProjectConfig defines project metadata

type ProxyConfig

type ProxyConfig struct {
	Domains []string  `yaml:"domains"`
	Email   string    `yaml:"email,omitempty"` // Email for Let's Encrypt
	TLS     TLSConfig `yaml:"tls,omitempty"`
}

ProxyConfig defines per-service Traefik reverse proxy settings

type SecretConfig

type SecretConfig struct {
	Name   string `yaml:"name"`             // Secret name (e.g., "db_password")
	Source string `yaml:"source,omitempty"` // Source: "env:VAR" or "file:path" (default: env:NAME)
	Target string `yaml:"target,omitempty"` // Target path in container (default: /run/secrets/{name})
}

SecretConfig defines a Docker secret

type ServerConfig

type ServerConfig struct {
	Host   string            `yaml:"host"`
	User   string            `yaml:"user"`
	Port   int               `yaml:"port,omitempty"`
	SSHKey string            `yaml:"sshKey,omitempty"`
	Role   string            `yaml:"role,omitempty"`   // "manager" or "worker" (auto-detect if not specified)
	Labels map[string]string `yaml:"labels,omitempty"` // Custom labels for server selection
}

ServerConfig defines server connection details

type ServerSelector

type ServerSelector struct {
	Labels map[string]string `yaml:"labels,omitempty"` // Match servers with these labels
	Any    bool              `yaml:"any,omitempty"`    // Select any available server
}

ServerSelector defines label-based server selection

type ServiceConfig

type ServiceConfig struct {
	// Build or Image (mutually exclusive)
	Build string `yaml:"build,omitempty"` // Path to build context (auto-detects Dockerfile)
	Image string `yaml:"image,omitempty"` // Pre-built image (for postgres, redis, etc)

	// Basic settings
	Port     int               `yaml:"port,omitempty"`
	Command  string            `yaml:"command,omitempty"`
	Replicas int               `yaml:"replicas,omitempty"` // Default: 1
	Restart  string            `yaml:"restart,omitempty"`  // Docker restart policy (always, unless-stopped, on-failure, no)
	Env      map[string]string `yaml:"env,omitempty"`
	EnvFile  string            `yaml:"envFile,omitempty"` // Path to .env file (e.g., .env.production)

	// Secrets: Can be either string array (new Tako secrets) or SecretConfig array (Docker Swarm secrets)
	// String format: ["DATABASE_URL", "JWT_SECRET"] or ["VAR_NAME:SECRET_KEY"]
	// SecretConfig format: [{name: "db_pass", source: "env:DB_PASSWORD"}]
	Secrets       []string       `yaml:"secrets,omitempty"`       // Tako secrets from .tako/secrets files
	DockerSecrets []SecretConfig `yaml:"dockerSecrets,omitempty"` // Docker Swarm secrets (for backward compatibility)
	Volumes       []string       `yaml:"volumes,omitempty"`

	// Service type flags
	Persistent bool `yaml:"persistent,omitempty"` // Don't remove on redeploy (databases, caches)

	// Per-service proxy settings (if present, service is exposed publicly)
	Proxy *ProxyConfig `yaml:"proxy,omitempty"`

	// Load balancing (for multi-replica services)
	LoadBalancer LoadBalancerConfig `yaml:"loadBalancer,omitempty"`

	// Health checks
	HealthCheck HealthCheckConfig `yaml:"healthCheck,omitempty"`

	// Deployment strategy
	Deploy DeployConfig `yaml:"deploy,omitempty"`

	// Per-service hooks
	Hooks *HooksConfig `yaml:"hooks,omitempty"`

	// Per-service backup
	Backup *BackupConfig `yaml:"backup,omitempty"`

	// Per-service monitoring
	Monitoring *MonitoringConfig `yaml:"monitoring,omitempty"`

	// Cross-project networking
	Export  bool     `yaml:"export,omitempty"`  // Export this service to other projects
	Imports []string `yaml:"imports,omitempty"` // Import services from other projects (format: "project.service")

	// Placement configuration (for Swarm multi-server deployments)
	Placement *PlacementConfig `yaml:"placement,omitempty"` // Where to run service replicas

	// Service dependencies (controls deployment order)
	DependsOn []string `yaml:"dependsOn,omitempty"` // List of service names this service depends on
}

ServiceConfig defines service deployment settings

func (*ServiceConfig) GetServiceType

func (s *ServiceConfig) GetServiceType() string

GetServiceType returns the auto-detected service type

func (*ServiceConfig) IsInternal

func (s *ServiceConfig) IsInternal() bool

IsInternal returns true if service is internal-only

func (*ServiceConfig) IsPublic

func (s *ServiceConfig) IsPublic() bool

IsPublic returns true if service should be exposed publicly

func (*ServiceConfig) IsWorker

func (s *ServiceConfig) IsWorker() bool

IsWorker returns true if service is a background worker

type TLSConfig

type TLSConfig struct {
	Provider string `yaml:"provider,omitempty"` // letsencrypt, zerossl (default: letsencrypt)
	Staging  bool   `yaml:"staging,omitempty"`
}

TLSConfig defines TLS settings

Jump to

Keyboard shortcuts

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