forked from d2iq-archive/cake-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
67 lines (57 loc) · 1.44 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"testing"
"gopkg.in/yaml.v2"
)
type ImageConfig struct {
Id string
Parent string
Repository string
Name string
TagSuffix string `yaml:"tag_suffix"`
Template string
ExtraFiles []string `yaml:"extra_files"`
Properties map[string]string
}
func (image ImageConfig) String() string {
out, err := json.Marshal(image)
if err != nil {
log.Fatalf("Failed to marshall image config to JSON: %v", err)
}
return fmt.Sprintf("ImageConfig%s", out)
}
type AuthConfig struct {
DockerRegistryUrl string
Username string
Password string
}
type BuildConfig struct {
AuthConfig AuthConfig
BaseDir string
ReleaseTag string
OutputFile string
Images []ImageConfig `yaml:"build"`
}
func (config BuildConfig) validate() error {
for _, image := range config.Images {
if len(image.Id) == 0 || len(image.Repository) == 0 || len(image.Name) == 0 || len(image.Template) == 0 {
return fmt.Errorf("Image ID, repository, name, or template is not specified for the following definition: " + image.String())
}
}
return nil
}
func (config *BuildConfig) loadConfigFromFile(fileName string) error {
configFile, err := ioutil.ReadFile(fileName)
if err != nil {
return fmt.Errorf("error reading config file: %v", err)
}
err = yaml.Unmarshal([]byte(configFile), &config)
if err != nil {
return fmt.Errorf("cannot unmarshal data: %v", err)
}
return nil
}