52 lines
968 B
Go
52 lines
968 B
Go
|
package commands
|
||
|
|
||
|
import (
|
||
|
"gopkg.in/yaml.v3"
|
||
|
"io/ioutil"
|
||
|
)
|
||
|
|
||
|
type RunnerConfiguration struct {
|
||
|
Labels map[string]string `yaml:"labels"`
|
||
|
}
|
||
|
|
||
|
type ContainerConfiguration struct {
|
||
|
Driver string `yaml:"driver"`
|
||
|
}
|
||
|
|
||
|
type Configuration struct {
|
||
|
Containers ContainerConfiguration `yaml:"containers"`
|
||
|
Runner RunnerConfiguration `yaml:"runner"`
|
||
|
}
|
||
|
|
||
|
func applyConfigDefaults(config Configuration) Configuration {
|
||
|
defaults := Configuration{
|
||
|
Containers: ContainerConfiguration{
|
||
|
Driver: "podman",
|
||
|
},
|
||
|
}
|
||
|
|
||
|
if config.Containers.Driver == "" {
|
||
|
config.Containers.Driver = defaults.Containers.Driver
|
||
|
}
|
||
|
|
||
|
return config
|
||
|
}
|
||
|
|
||
|
func NewConfigFromFile(configPath string) (*Configuration, error) {
|
||
|
configRaw, err := ioutil.ReadFile(configPath)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
var config Configuration
|
||
|
|
||
|
if yamlError := yaml.Unmarshal(configRaw, &config); yamlError != nil {
|
||
|
return nil, yamlError
|
||
|
}
|
||
|
|
||
|
config = applyConfigDefaults(config)
|
||
|
|
||
|
return &config, nil
|
||
|
}
|