-
Notifications
You must be signed in to change notification settings - Fork 6
/
yaml_config.go
48 lines (41 loc) · 1.19 KB
/
yaml_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package aceptadora
import (
"fmt"
"io"
"os"
"gopkg.in/yaml.v3"
)
// YAML defines the aceptadora yaml config
// This enumerates the services aceptadora can run, their images, volumes to be mounted, ports to be mapped, and env configs
type YAML struct {
Services map[string]Service `yaml:"services"`
}
// Service describes a service aceptadora can run
type Service struct {
Image string `yaml:"image"`
Network string `yaml:"network"`
Binds []string `yaml:"binds"`
Command []string `yaml:"command"`
EnvFile []string `yaml:"env_file"`
Ports []string `yaml:"ports"`
IgnoreLogs bool `yaml:"ignore_logs"`
}
// LoadYAML reads the aceptadora.yml config, expanding the env var references to their values.
func LoadYAML(filename string) (YAML, error) {
cfg := YAML{}
file, err := os.Open(filename)
if err != nil {
return cfg, fmt.Errorf("can't open file: %w", err)
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
return cfg, fmt.Errorf("can't read file: %w", err)
}
// expand environment variables
data = []byte(os.ExpandEnv(string(data)))
if err := yaml.Unmarshal(data, &cfg); err != nil {
return cfg, fmt.Errorf("can't read yaml: %w", err)
}
return cfg, nil
}