Add a new "builder" capability to trigger Nix builds on a dedicated build host via NATS messaging. This allows pre-building NixOS configurations before deployment. New components: - Builder mode: subscribes to build.<repo>.* subjects, executes nix build - Build CLI command: triggers builds with progress tracking - MCP build tool: available with --enable-builds flag - Builder metrics: tracks build success/failure per repo and host - NixOS module: services.homelab-deploy.builder The builder uses a YAML config file to define allowed repositories with their URLs and default branches. Builds can target all hosts or specific hosts, with real-time progress updates. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package builder
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// RepoConfig holds configuration for a single repository.
|
|
type RepoConfig struct {
|
|
URL string `yaml:"url"`
|
|
DefaultBranch string `yaml:"default_branch"`
|
|
}
|
|
|
|
// Config holds the builder configuration.
|
|
type Config struct {
|
|
Repos map[string]RepoConfig `yaml:"repos"`
|
|
}
|
|
|
|
// LoadConfig loads configuration from a YAML file.
|
|
func LoadConfig(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read config file: %w", err)
|
|
}
|
|
|
|
var cfg Config
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
|
}
|
|
|
|
if err := cfg.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
// Validate checks that the configuration is valid.
|
|
func (c *Config) Validate() error {
|
|
if len(c.Repos) == 0 {
|
|
return fmt.Errorf("no repos configured")
|
|
}
|
|
|
|
for name, repo := range c.Repos {
|
|
if repo.URL == "" {
|
|
return fmt.Errorf("repo %q: url is required", name)
|
|
}
|
|
if repo.DefaultBranch == "" {
|
|
return fmt.Errorf("repo %q: default_branch is required", name)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetRepo returns the configuration for a repository, or an error if not found.
|
|
func (c *Config) GetRepo(name string) (*RepoConfig, error) {
|
|
repo, ok := c.Repos[name]
|
|
if !ok {
|
|
return nil, fmt.Errorf("repo %q not found in configuration", name)
|
|
}
|
|
return &repo, nil
|
|
}
|