-
Notifications
You must be signed in to change notification settings - Fork 25
/
imgconfig.go
71 lines (57 loc) · 1.26 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
62
63
64
65
66
67
68
69
70
71
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...)
if len(i.Volumes) > 0 {
if cfg.Volumes == nil {
cfg.Volumes = make(map[string]struct{}, len(i.Volumes))
}
for k, v := range i.Volumes {
cfg.Volumes[k] = v
}
}
if len(i.Labels) > 0 {
if cfg.Labels == nil {
cfg.Labels = make(map[string]string, len(i.Labels))
}
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
}