2026-01-29 02:04:01 +00:00
|
|
|
package devops
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
2026-02-16 00:30:41 +00:00
|
|
|
"forge.lthn.ai/core/cli/pkg/config"
|
|
|
|
|
"forge.lthn.ai/core/cli/pkg/io"
|
2026-01-29 02:04:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Config holds global devops configuration from ~/.core/config.yaml.
|
|
|
|
|
type Config struct {
|
2026-02-05 10:26:44 +00:00
|
|
|
Version int `yaml:"version" mapstructure:"version"`
|
|
|
|
|
Images ImagesConfig `yaml:"images" mapstructure:"images"`
|
2026-01-29 02:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ImagesConfig holds image source configuration.
|
|
|
|
|
type ImagesConfig struct {
|
2026-02-05 10:26:44 +00:00
|
|
|
Source string `yaml:"source" mapstructure:"source"` // auto, github, registry, cdn
|
|
|
|
|
GitHub GitHubConfig `yaml:"github,omitempty" mapstructure:"github,omitempty"`
|
|
|
|
|
Registry RegistryConfig `yaml:"registry,omitempty" mapstructure:"registry,omitempty"`
|
|
|
|
|
CDN CDNConfig `yaml:"cdn,omitempty" mapstructure:"cdn,omitempty"`
|
2026-01-29 02:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GitHubConfig holds GitHub Releases configuration.
|
|
|
|
|
type GitHubConfig struct {
|
2026-02-05 10:26:44 +00:00
|
|
|
Repo string `yaml:"repo" mapstructure:"repo"` // owner/repo format
|
2026-01-29 02:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RegistryConfig holds container registry configuration.
|
|
|
|
|
type RegistryConfig struct {
|
2026-02-05 10:26:44 +00:00
|
|
|
Image string `yaml:"image" mapstructure:"image"` // e.g., ghcr.io/host-uk/core-devops
|
2026-01-29 02:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CDNConfig holds CDN/S3 configuration.
|
|
|
|
|
type CDNConfig struct {
|
2026-02-05 10:26:44 +00:00
|
|
|
URL string `yaml:"url" mapstructure:"url"` // base URL for downloads
|
2026-01-29 02:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DefaultConfig returns sensible defaults.
|
|
|
|
|
func DefaultConfig() *Config {
|
|
|
|
|
return &Config{
|
|
|
|
|
Version: 1,
|
|
|
|
|
Images: ImagesConfig{
|
|
|
|
|
Source: "auto",
|
|
|
|
|
GitHub: GitHubConfig{
|
|
|
|
|
Repo: "host-uk/core-images",
|
|
|
|
|
},
|
|
|
|
|
Registry: RegistryConfig{
|
|
|
|
|
Image: "ghcr.io/host-uk/core-devops",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ConfigPath returns the path to the config file.
|
|
|
|
|
func ConfigPath() (string, error) {
|
|
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return filepath.Join(home, ".core", "config.yaml"), nil
|
|
|
|
|
}
|
|
|
|
|
|
Migrate pkg/devops to Medium abstraction (#293)
* chore(io): migrate pkg/devops to Medium abstraction
This commit migrates the pkg/devops package to use the io.Medium abstraction instead of direct calls to io.Local or the os package.
Changes:
- Updated DevOps, ImageManager, and Manifest structs to hold an io.Medium.
- Updated New, NewImageManager, and LoadConfig to accept an io.Medium.
- Updated ImageSource interface and its implementations (GitHubSource, CDNSource) to accept io.Medium in Download method.
- Refactored internal helper functions (hasFile, hasPackageScript, etc.) to use io.Medium.
- Updated all unit tests and CLI entry points to pass the appropriate io.Medium.
This migration improves the testability and flexibility of the devops package by allowing for different storage backends.
* chore(io): migrate pkg/devops to Medium abstraction
This commit completes the migration of the pkg/devops package to the io.Medium abstraction.
Changes:
- Refactored DevOps, ImageManager, and Manifest structs to use io.Medium for storage operations.
- Updated New, NewImageManager, and LoadConfig to accept an io.Medium.
- Updated ImageSource interface and its implementations (GitHubSource, CDNSource) to accept io.Medium in Download method.
- Refactored internal helper functions (hasFile, hasPackageScript, etc.) to use io.Medium.
- Updated all unit tests and CLI entry points to pass the appropriate io.Medium.
- Fixed formatting issues in test files.
This migration enables easier testing and supports alternative storage backends.
2026-02-04 14:58:03 +00:00
|
|
|
// LoadConfig loads configuration from ~/.core/config.yaml using the provided medium.
|
2026-01-29 02:04:01 +00:00
|
|
|
// Returns default config if file doesn't exist.
|
Migrate pkg/devops to Medium abstraction (#293)
* chore(io): migrate pkg/devops to Medium abstraction
This commit migrates the pkg/devops package to use the io.Medium abstraction instead of direct calls to io.Local or the os package.
Changes:
- Updated DevOps, ImageManager, and Manifest structs to hold an io.Medium.
- Updated New, NewImageManager, and LoadConfig to accept an io.Medium.
- Updated ImageSource interface and its implementations (GitHubSource, CDNSource) to accept io.Medium in Download method.
- Refactored internal helper functions (hasFile, hasPackageScript, etc.) to use io.Medium.
- Updated all unit tests and CLI entry points to pass the appropriate io.Medium.
This migration improves the testability and flexibility of the devops package by allowing for different storage backends.
* chore(io): migrate pkg/devops to Medium abstraction
This commit completes the migration of the pkg/devops package to the io.Medium abstraction.
Changes:
- Refactored DevOps, ImageManager, and Manifest structs to use io.Medium for storage operations.
- Updated New, NewImageManager, and LoadConfig to accept an io.Medium.
- Updated ImageSource interface and its implementations (GitHubSource, CDNSource) to accept io.Medium in Download method.
- Refactored internal helper functions (hasFile, hasPackageScript, etc.) to use io.Medium.
- Updated all unit tests and CLI entry points to pass the appropriate io.Medium.
- Fixed formatting issues in test files.
This migration enables easier testing and supports alternative storage backends.
2026-02-04 14:58:03 +00:00
|
|
|
func LoadConfig(m io.Medium) (*Config, error) {
|
2026-01-29 02:04:01 +00:00
|
|
|
configPath, err := ConfigPath()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return DefaultConfig(), nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 10:26:44 +00:00
|
|
|
cfg := DefaultConfig()
|
|
|
|
|
|
|
|
|
|
if !m.IsFile(configPath) {
|
|
|
|
|
return cfg, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use centralized config service
|
|
|
|
|
c, err := config.New(config.WithMedium(m), config.WithPath(configPath))
|
2026-01-29 02:04:01 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 10:26:44 +00:00
|
|
|
if err := c.Get("", cfg); err != nil {
|
2026-01-29 02:04:01 +00:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cfg, nil
|
|
|
|
|
}
|