-
Notifications
You must be signed in to change notification settings - Fork 23
/
imgconfig.go
61 lines (47 loc) · 1.02 KB
/
imgconfig.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
package dalec
func BuildImageConfig(spec *Spec, targetKey string, img *DockerImageSpec) error {
cfg := img.Config
if err := MergeImageConfig(&cfg, MergeSpecImage(spec, targetKey)); err != nil {
return err
}
img.Config = cfg
return nil
}
func GetBaseOutputImage(spec *Spec, target string) string {
i := spec.Targets[target].Image
if i == nil || i.Base == "" {
return ""
}
return i.Base
}
func MergeSpecImage(spec *Spec, targetKey string) *ImageConfig {
var cfg ImageConfig
if spec.Image != nil {
cfg = *spec.Image
}
if i := spec.Targets[targetKey].Image; i != nil {
if i.Entrypoint != "" {
cfg.Entrypoint = i.Entrypoint
}
if i.Cmd != "" {
cfg.Cmd = i.Cmd
}
cfg.Env = append(cfg.Env, i.Env...)
for k, v := range i.Volumes {
cfg.Volumes[k] = v
}
for k, v := range i.Labels {
cfg.Labels[k] = v
}
if i.WorkingDir != "" {
cfg.WorkingDir = i.WorkingDir
}
if i.StopSignal != "" {
cfg.StopSignal = i.StopSignal
}
if i.Base != "" {
cfg.Base = i.Base
}
}
return &cfg
}