-
Notifications
You must be signed in to change notification settings - Fork 290
/
docker_compose_target.go
98 lines (76 loc) · 2.15 KB
/
docker_compose_target.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package model
import (
"fmt"
"github.com/tilt-dev/tilt/internal/sliceutils"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
)
type DockerComposeTarget struct {
Spec v1alpha1.DockerComposeServiceSpec
Name TargetName
ServiceYAML string // for diff'ing when config files change
publishedPorts []int
inferLinks struct {
IsSet bool
Value bool
}
Links []Link
}
// TODO(nick): This is a temporary hack until we figure out how we want
// to pass these IDs to the docker-compose UX.
func (t DockerComposeTarget) ManifestName() ManifestName {
return ManifestName(t.Name)
}
func (t DockerComposeTarget) Empty() bool { return t.ID().Empty() }
func (t DockerComposeTarget) ID() TargetID {
return TargetID{
Type: TargetTypeDockerCompose,
Name: t.Name,
}
}
func (t DockerComposeTarget) DependencyIDs() []TargetID {
result := make([]TargetID, 0, len(t.Spec.ImageMaps))
for _, im := range t.Spec.ImageMaps {
result = append(result, TargetID{
Type: TargetTypeImage,
Name: TargetName(im),
})
}
return result
}
func (t DockerComposeTarget) PublishedPorts() []int {
return append([]int{}, t.publishedPorts...)
}
func (t DockerComposeTarget) InferLinks() bool {
if t.inferLinks.IsSet {
return t.inferLinks.Value
} else {
return true
}
}
func (t DockerComposeTarget) WithInferLinks(inferLinks bool) DockerComposeTarget {
t.inferLinks.IsSet = true
t.inferLinks.Value = inferLinks
return t
}
func (t DockerComposeTarget) WithLinks(links []Link) DockerComposeTarget {
t.Links = links
return t
}
func (t DockerComposeTarget) WithPublishedPorts(ports []int) DockerComposeTarget {
t.publishedPorts = ports
return t
}
func (t DockerComposeTarget) WithImageMapDeps(names []string) DockerComposeTarget {
t.Spec.ImageMaps = sliceutils.Dedupe(names)
return t
}
func (dc DockerComposeTarget) Validate() error {
if dc.ID().Empty() {
return fmt.Errorf("[Validate] DockerCompose resource missing name:\n%s", dc.ServiceYAML)
}
if len(dc.Spec.Project.ConfigPaths) == 0 && dc.Spec.Project.YAML == "" {
return fmt.Errorf("[Validate] DockerCompose resource %s missing config path", dc.Spec.Service)
}
return nil
}
var _ TargetSpec = DockerComposeTarget{}