Pull-based GitOps-style Docker Compose deployer: polls a (private) Git repo, detects changed stacks and reconciles only the affected
at main 44 lines 824 B view raw
1package core 2 3import ( 4 "fmt" 5 "os" 6 7 "gopkg.in/yaml.v3" 8) 9 10type Config struct { 11 RepoURL string `yaml:"repo_url"` 12 RepoPath string `yaml:"repo_path"` 13 Branch string `yaml:"branch"` 14 Concurrency int `yaml:"concurrency"` 15} 16 17func LoadConfig(path string) (*Config, error) { 18 data, err := os.ReadFile(path) 19 if err != nil { 20 return nil, fmt.Errorf("failed to read config file: %w", err) 21 } 22 23 var cfg Config 24 if err := yaml.Unmarshal(data, &cfg); err != nil { 25 return nil, fmt.Errorf("failed to parse config: %w", err) 26 } 27 28 if cfg.RepoPath == "" { 29 return nil, fmt.Errorf("repo_path is required in config") 30 } 31 32 if cfg.Branch == "" { 33 cfg.Branch = detectCurrentBranch(cfg.RepoPath) 34 if cfg.Branch == "" { 35 cfg.Branch = "main" 36 } 37 } 38 39 if cfg.Concurrency <= 0 { 40 cfg.Concurrency = 3 41 } 42 43 return &cfg, nil 44}