config

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandConfigEnvVars

func ExpandConfigEnvVars(cfg *Config, envFileVars map[string]string, reg *SecretRegistry) error

ExpandConfigEnvVars expands $VAR references throughout the config in-place: global env, service env, docker env, docker image, docker registry_auth, cluster registries.

func ExpandEnvVars

func ExpandEnvVars(s string, envFileVars map[string]string, registry *SecretRegistry) (string, bool, error)

ExpandEnvVars expands $VAR, ${VAR}, and $$ in s using the provided lookup order: envFileVars first, then os.Getenv. Returns the expanded string and whether any secret (non-literal) value was substituted.

func InterpolateAddonValues added in v0.39.0

func InterpolateAddonValues(addons map[string]AddonConfig, vars *TemplateVars) error

InterpolateAddonValues resolves {{ }} templates in every helm addon's `values`. Addons commonly reference cluster vars (e.g. "image.tag" = "{{ cluster.image.NAME.tag }}"). Addons install during the cluster phase, before the main InterpolateConfig pass runs, so the orchestrator calls this separately at that point — once the cluster registry and image tags are known. Values is map[string]any, so string leaves are interpolated recursively (through nested maps/slices); the map is mutated in place.

func InterpolateConfig

func InterpolateConfig(cfg *Config, vars *TemplateVars) error

InterpolateConfig resolves {{ }} expressions in all interpolatable string fields of the config. It runs after port allocation so all template vars are available. Only services in `only` are interpolated; pass nil to interpolate everything.

func InterpolateMap

func InterpolateMap(m map[string]string, vars *TemplateVars) error

InterpolateMap interpolates all values in a string map in-place.

func InterpolateSlice

func InterpolateSlice(s []string, vars *TemplateVars) ([]string, error)

InterpolateSlice interpolates each string in a slice.

func InterpolateString

func InterpolateString(s string, vars *TemplateVars) (string, error)

InterpolateString replaces all {{ path.to.var }} expressions in s using vars. Returns an error listing all unresolved variables.

func Load

func Load(path string) (*Config, *SecretRegistry, error)

Load reads, parses, and validates a devrig config file (TOML or YAML). It does not perform {{ }} template interpolation — that happens later after ports are resolved. It does expand $VAR references from .env files.

func ParseEnvFile

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

ParseEnvFile parses a .env file into a map. Supports KEY=VALUE, KEY="VALUE", and KEY='VALUE' lines. Lines starting with # or blank lines are ignored.

func Resolve

func Resolve(path string) (string, error)

Resolve finds the config file to use. If path is provided it is verified to exist. Otherwise it walks up the directory tree from the current working directory until it finds one of the candidate filenames.

func Validate

func Validate(cfg *Config) error

Validate checks the config for structural errors: missing dependencies, dependency cycles, port conflicts, empty required fields, invalid values.

Types

type AddonConfig

type AddonConfig struct {
	Type        string            `toml:"type"         yaml:"type"`
	Chart       string            `toml:"chart"        yaml:"chart"`        // helm
	Repo        *string           `toml:"repo"         yaml:"repo"`         // helm
	Namespace   string            `toml:"namespace"    yaml:"namespace"`    // helm/manifest/kustomize
	Version     *string           `toml:"version"      yaml:"version"`      // helm
	Values      map[string]any    `toml:"values"       yaml:"values"`       // helm
	ValuesFiles []string          `toml:"values_files" yaml:"values_files"` // helm
	Wait        bool              `toml:"wait"         yaml:"wait"`         // helm
	Timeout     string            `toml:"timeout"      yaml:"timeout"`      // helm
	SkipCRDs    bool              `toml:"skip_crds"    yaml:"skip_crds"`    // helm
	Path        string            `toml:"path"         yaml:"path"`         // manifest/kustomize
	PortForward map[string]string `toml:"port_forward" yaml:"port_forward"` // all
	DependsOn   []string          `toml:"depends_on"   yaml:"depends_on"`   // all
}

AddonConfig is a tagged-union addon (helm/manifest/kustomize). The Type field determines which other fields are relevant.

func (*AddonConfig) ParsedPortForwards

func (a *AddonConfig) ParsedPortForwards() []struct {
	Local  uint16
	Target string
}

ParsedPortForwards returns (localPort, target) pairs from the port_forward map.

func (*AddonConfig) UnmarshalTOML

func (a *AddonConfig) UnmarshalTOML(v any) error

func (*AddonConfig) UnmarshalYAML

func (a *AddonConfig) UnmarshalYAML(value *yaml.Node) error

type ClusterConfig

type ClusterConfig struct {
	Name       *string                        `toml:"name"       yaml:"name"`
	Agents     uint32                         `toml:"agents"     yaml:"agents"`
	Ports      []string                       `toml:"ports"      yaml:"ports"`
	Volumes    []string                       `toml:"volumes"    yaml:"volumes"`
	Registry   bool                           `toml:"registry"   yaml:"registry"`
	Images     map[string]ClusterImageConfig  `toml:"image"      yaml:"image"`
	Deploy     map[string]ClusterDeployConfig `toml:"deploy"     yaml:"deploy"`
	Addons     map[string]AddonConfig         `toml:"addons"     yaml:"addons"`
	Logs       *ClusterLogsConfig             `toml:"logs"       yaml:"logs"`
	Registries []ClusterRegistryAuth          `toml:"registries" yaml:"registries"`
	K3SArgs    []string                       `toml:"k3s_args"   yaml:"k3s_args"`
}

func (*ClusterConfig) UnmarshalTOML

func (c *ClusterConfig) UnmarshalTOML(v any) error

func (*ClusterConfig) UnmarshalYAML

func (c *ClusterConfig) UnmarshalYAML(value *yaml.Node) error

type ClusterDeployConfig

type ClusterDeployConfig struct {
	Context      string            `toml:"context"       yaml:"context"`
	Dockerfile   string            `toml:"dockerfile"    yaml:"dockerfile"`
	Manifests    string            `toml:"manifests"     yaml:"manifests"`
	Watch        bool              `toml:"watch"         yaml:"watch"`
	DependsOn    []string          `toml:"depends_on"    yaml:"depends_on"`
	BuildSecrets map[string]string `toml:"build_secrets" yaml:"build_secrets"`
}

func (*ClusterDeployConfig) UnmarshalTOML

func (c *ClusterDeployConfig) UnmarshalTOML(v any) error

func (*ClusterDeployConfig) UnmarshalYAML

func (c *ClusterDeployConfig) UnmarshalYAML(value *yaml.Node) error

type ClusterImageConfig

type ClusterImageConfig struct {
	Context      string            `toml:"context"       yaml:"context"`
	Dockerfile   string            `toml:"dockerfile"    yaml:"dockerfile"`
	Watch        bool              `toml:"watch"         yaml:"watch"`
	DependsOn    []string          `toml:"depends_on"    yaml:"depends_on"`
	BuildSecrets map[string]string `toml:"build_secrets" yaml:"build_secrets"`
	BuildArgs    map[string]string `toml:"build_args"    yaml:"build_args"`
}

func (*ClusterImageConfig) UnmarshalTOML

func (c *ClusterImageConfig) UnmarshalTOML(v any) error

func (*ClusterImageConfig) UnmarshalYAML

func (c *ClusterImageConfig) UnmarshalYAML(value *yaml.Node) error

type ClusterLogsConfig

type ClusterLogsConfig struct {
	Enabled           bool            `toml:"enabled"            yaml:"enabled"`
	Collector         bool            `toml:"collector"          yaml:"collector"`
	Namespaces        NamespaceFilter `toml:"namespaces"         yaml:"namespaces"`
	ExcludeNamespaces []string        `toml:"exclude_namespaces" yaml:"exclude_namespaces"`
	ExcludePods       []string        `toml:"exclude_pods"       yaml:"exclude_pods"`
}

func (*ClusterLogsConfig) UnmarshalTOML

func (l *ClusterLogsConfig) UnmarshalTOML(v any) error

func (*ClusterLogsConfig) UnmarshalYAML

func (l *ClusterLogsConfig) UnmarshalYAML(value *yaml.Node) error

type ClusterRegistryAuth

type ClusterRegistryAuth struct {
	URL      string `toml:"url"      yaml:"url"`
	Username string `toml:"username" yaml:"username"`
	Password string `toml:"password" yaml:"password"`
}

type ComposeConfig

type ComposeConfig struct {
	File        string                 `toml:"file"         yaml:"file"`
	Services    []string               `toml:"services"     yaml:"services"`
	EnvFile     *string                `toml:"env_file"     yaml:"env_file"`
	ReadyChecks map[string]*ReadyCheck `toml:"ready_checks" yaml:"ready_checks"`
}

type Config

type Config struct {
	Project   ProjectConfig            `toml:"project"   yaml:"project"`
	Services  map[string]ServiceConfig `toml:"services"  yaml:"services"`
	Docker    map[string]DockerConfig  `toml:"docker"    yaml:"docker"`
	Compose   *ComposeConfig           `toml:"compose"   yaml:"compose"`
	Cluster   *ClusterConfig           `toml:"cluster"   yaml:"cluster"`
	Dashboard *DashboardConfig         `toml:"dashboard" yaml:"dashboard"`
	OIDC      *OIDCConfig              `toml:"oidc"      yaml:"oidc"`
	Env       map[string]string        `toml:"env"       yaml:"env"`
	Network   *NetworkConfig           `toml:"network"   yaml:"network"`
	Links     map[string]string        `toml:"links"     yaml:"links"`
	Tools     *ToolsConfig             `toml:"tools"     yaml:"tools"`
}

Config is the top-level devrig.toml / devrig.yaml structure.

type DashboardConfig

type DashboardConfig struct {
	Port    Port        `toml:"port"    yaml:"port"`
	Enabled *bool       `toml:"enabled" yaml:"enabled"`
	OTel    *OTelConfig `toml:"otel"    yaml:"otel"`
}

func (*DashboardConfig) UnmarshalTOML

func (d *DashboardConfig) UnmarshalTOML(v any) error

func (*DashboardConfig) UnmarshalYAML

func (d *DashboardConfig) UnmarshalYAML(value *yaml.Node) error

type DockerConfig

type DockerConfig struct {
	Image         string            `toml:"image"          yaml:"image"`
	Port          *Port             `toml:"port"           yaml:"port"`
	ContainerPort *uint16           `toml:"container_port" yaml:"container_port"`
	Protocol      *string           `toml:"protocol"       yaml:"protocol"`
	Ports         map[string]Port   `toml:"ports"          yaml:"ports"`
	Env           map[string]string `toml:"env"            yaml:"env"`
	Volumes       []string          `toml:"volumes"        yaml:"volumes"`
	Command       *StringOrList     `toml:"command"        yaml:"command"`
	Entrypoint    *StringOrList     `toml:"entrypoint"     yaml:"entrypoint"`
	ReadyCheck    *ReadyCheck       `toml:"ready_check"    yaml:"ready_check"`
	Init          []string          `toml:"init"           yaml:"init"`
	DependsOn     []string          `toml:"depends_on"     yaml:"depends_on"`
	RegistryAuth  *RegistryAuth     `toml:"registry_auth"  yaml:"registry_auth"`
}

type NamespaceFilter

type NamespaceFilter struct {
	All  bool
	List []string
}

NamespaceFilter is either the string "all" or a list of namespace names.

func (*NamespaceFilter) UnmarshalTOML

func (n *NamespaceFilter) UnmarshalTOML(v any) error

func (*NamespaceFilter) UnmarshalYAML

func (n *NamespaceFilter) UnmarshalYAML(value *yaml.Node) error

type NetworkConfig

type NetworkConfig struct {
	Name *string `toml:"name" yaml:"name"`
}

type OIDCClientConfig

type OIDCClientConfig struct {
	Public       bool     `toml:"public"        yaml:"public"`
	RedirectURIs []string `toml:"redirect_uris" yaml:"redirect_uris"`
	ClientSecret *string  `toml:"client_secret" yaml:"client_secret"`
	ClientName   *string  `toml:"client_name"   yaml:"client_name"`
	GrantTypes   []string `toml:"grant_types"   yaml:"grant_types"`
	Scopes       []string `toml:"scopes"        yaml:"scopes"`
}

type OIDCConfig

type OIDCConfig struct {
	Port     Port                        `toml:"port"     yaml:"port"`
	Issuer   *string                     `toml:"issuer"   yaml:"issuer"`
	Realm    string                      `toml:"realm"    yaml:"realm"`
	Audience *string                     `toml:"audience" yaml:"audience"`
	Users    []OIDCUserConfig            `toml:"users"    yaml:"users"`
	Clients  map[string]OIDCClientConfig `toml:"clients"  yaml:"clients"`
}

func (*OIDCConfig) UnmarshalTOML

func (o *OIDCConfig) UnmarshalTOML(v any) error

func (*OIDCConfig) UnmarshalYAML

func (o *OIDCConfig) UnmarshalYAML(value *yaml.Node) error

type OIDCUserConfig

type OIDCUserConfig struct {
	Email    string  `toml:"email"    yaml:"email"`
	Password string  `toml:"password" yaml:"password"`
	Name     *string `toml:"name"     yaml:"name"`
	Role     *string `toml:"role"     yaml:"role"`
}

type OTelConfig

type OTelConfig struct {
	GRPCPort     Port   `toml:"grpc_port"     yaml:"grpc_port"`
	HTTPPort     Port   `toml:"http_port"     yaml:"http_port"`
	TraceBuffer  int    `toml:"trace_buffer"  yaml:"trace_buffer"`
	MetricBuffer int    `toml:"metric_buffer" yaml:"metric_buffer"`
	LogBuffer    int    `toml:"log_buffer"    yaml:"log_buffer"`
	Retention    string `toml:"retention"     yaml:"retention"`
}

func DefaultOTelConfig

func DefaultOTelConfig() *OTelConfig

DefaultOTelConfig returns the OTel settings used when [dashboard.otel] is absent: standard OTLP ports, 1h retention, default buffer sizes.

func (*OTelConfig) UnmarshalTOML

func (o *OTelConfig) UnmarshalTOML(v any) error

func (*OTelConfig) UnmarshalYAML

func (o *OTelConfig) UnmarshalYAML(value *yaml.Node) error

type Port

type Port struct {
	Value uint16
	Auto  bool
}

Port is either a fixed port number (Value > 0) or "auto" (Auto == true). The zero value is invalid; use FixedPort or AutoPort to construct.

func AutoPort

func AutoPort() Port

func FixedPort

func FixedPort(p uint16) Port

func (Port) AsFixed

func (p Port) AsFixed() uint16

func (Port) IsAuto

func (p Port) IsAuto() bool

func (Port) IsZero

func (p Port) IsZero() bool

func (*Port) UnmarshalTOML

func (p *Port) UnmarshalTOML(v any) error

func (*Port) UnmarshalYAML

func (p *Port) UnmarshalYAML(value *yaml.Node) error

type ProjectConfig

type ProjectConfig struct {
	Name    string  `toml:"name"     yaml:"name"`
	EnvFile *string `toml:"env_file" yaml:"env_file"`
}

type ReadyCheck

type ReadyCheck struct {
	Type    string  `toml:"type"    yaml:"type"`
	Command string  `toml:"command" yaml:"command"` // cmd
	Expect  *string `toml:"expect"  yaml:"expect"`  // cmd
	URL     string  `toml:"url"     yaml:"url"`     // http
	Match   string  `toml:"match"   yaml:"match"`   // log
	Timeout *uint64 `toml:"timeout" yaml:"timeout"` // all
}

ReadyCheck is a tagged-union health check. The Type field selects the variant.

func (*ReadyCheck) TimeoutSecs

func (r *ReadyCheck) TimeoutSecs() uint64

TimeoutSecs returns the configured timeout or the variant default.

type RegistryAuth

type RegistryAuth struct {
	Username string `toml:"username" yaml:"username"`
	Password string `toml:"password" yaml:"password"`
}

type RestartConfig

type RestartConfig struct {
	Policy             string `toml:"policy"               yaml:"policy"`
	MaxRestarts        uint32 `toml:"max_restarts"         yaml:"max_restarts"`
	StartupMaxRestarts uint32 `toml:"startup_max_restarts" yaml:"startup_max_restarts"`
	StartupGraceMs     uint64 `toml:"startup_grace_ms"     yaml:"startup_grace_ms"`
	InitialDelayMs     uint64 `toml:"initial_delay_ms"     yaml:"initial_delay_ms"`
	MaxDelayMs         uint64 `toml:"max_delay_ms"         yaml:"max_delay_ms"`
}

func (*RestartConfig) UnmarshalTOML

func (r *RestartConfig) UnmarshalTOML(v any) error

func (*RestartConfig) UnmarshalYAML

func (r *RestartConfig) UnmarshalYAML(value *yaml.Node) error

type SecretRegistry

type SecretRegistry struct {
	// contains filtered or unexported fields
}

SecretRegistry tracks expanded secret values so they can be masked in output.

func (*SecretRegistry) ContainsSecret

func (r *SecretRegistry) ContainsSecret(s string) bool

func (*SecretRegistry) Mask

func (r *SecretRegistry) Mask(s string) string

func (*SecretRegistry) Track

func (r *SecretRegistry) Track(value string)

type ServiceConfig

type ServiceConfig struct {
	Path      *string           `toml:"path"       yaml:"path"`
	Command   string            `toml:"command"    yaml:"command"`
	Port      *Port             `toml:"port"       yaml:"port"`
	Protocol  *string           `toml:"protocol"   yaml:"protocol"`
	Env       map[string]string `toml:"env"        yaml:"env"`
	EnvFile   *string           `toml:"env_file"   yaml:"env_file"`
	DependsOn []string          `toml:"depends_on" yaml:"depends_on"`
	Restart   *RestartConfig    `toml:"restart"    yaml:"restart"`
}

type StringOrList

type StringOrList []string

StringOrList is a string or []string in TOML/YAML.

func (*StringOrList) UnmarshalTOML

func (s *StringOrList) UnmarshalTOML(v any) error

func (*StringOrList) UnmarshalYAML

func (s *StringOrList) UnmarshalYAML(value *yaml.Node) error

type TemplateVars

type TemplateVars struct {
	ProjectName string
	// services.NAME.port
	ServicePorts map[string]uint16
	// docker.NAME.port (primary port)
	DockerPorts map[string]uint16
	// docker.NAME.ports.PORTNAME (named ports)
	DockerNamedPorts map[string]map[string]uint16
	// compose.NAME.port
	ComposePorts map[string]uint16
	// dashboard.*
	DashboardPort *uint16
	OTelGRPCPort  *uint16
	OTelHTTPPort  *uint16
	// otel.* (for in-cluster services to reach the host OTEL collector)
	OTelEndpointHTTP *string // host.k3d.internal:4318
	OTelEndpointGRPC *string // host.k3d.internal:4317
	// oidc.*
	OIDCPort   *uint16
	OIDCIssuer *string
	// cluster.*
	ClusterName         *string
	ClusterRegistry     *string
	ClusterRegistryHost *string
	ClusterKubeconfig   *string
	// cluster.image.NAME.tag
	ClusterImageTags map[string]string
}

TemplateVars holds all resolved values available for {{ }} interpolation. Values are populated across the orchestrator startup phases.

type ToolsConfig added in v0.34.0

type ToolsConfig struct {
	// Prefer is "vendored" (default — devrig-managed, pinned copies) or
	// "system" (whatever is on the user's PATH).
	Prefer string `toml:"prefer" yaml:"prefer"`
	// Per-tool explicit executable path overrides.
	Kubectl string `toml:"kubectl" yaml:"kubectl"`
	Helm    string `toml:"helm"    yaml:"helm"`
	K3d     string `toml:"k3d"     yaml:"k3d"`
}

ToolsConfig controls how devrig resolves the external CLIs its cluster features depend on (k3d, kubectl, helm). See docs/prd/managed-tool-deps.md.

type ValidationError

type ValidationError struct {
	Errors []string
}

ValidationError collects multiple validation problems from a single config.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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