-
Notifications
You must be signed in to change notification settings - Fork 298
/
docker_compose_target.go
139 lines (107 loc) · 3.52 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package model
import (
"fmt"
"github.com/tilt-dev/tilt/internal/sliceutils"
)
type DockerComposeTarget struct {
Name TargetName
ConfigPaths []string
// The docker context, like in DockerBuild
buildPath string
YAMLRaw []byte // for diff'ing when config files change
DfRaw []byte // for diff'ing when config files change
// TODO(nick): It might eventually make sense to represent
// Tiltfile as a separate nodes in the build graph, rather
// than duplicating it in each DockerComposeTarget.
tiltFilename string
dockerignores []Dockerignore
repos []LocalGitRepo
// These directories and their children will not trigger file change events
ignoredLocalDirectories []string
dependencyIDs []TargetID
publishedPorts []int
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 {
return t.dependencyIDs
}
func (t DockerComposeTarget) LocalPaths() []string {
if t.buildPath == "" {
return []string{}
}
return []string{t.buildPath}
}
func (t DockerComposeTarget) PublishedPorts() []int {
return append([]int{}, t.publishedPorts...)
}
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) WithBuildPath(buildPath string) DockerComposeTarget {
t.buildPath = buildPath
return t
}
func (t DockerComposeTarget) WithDependencyIDs(ids []TargetID) DockerComposeTarget {
t.dependencyIDs = DedupeTargetIDs(ids)
return t
}
func (t DockerComposeTarget) WithRepos(repos []LocalGitRepo) DockerComposeTarget {
t.repos = append(append([]LocalGitRepo{}, t.repos...), repos...)
return t
}
func (t DockerComposeTarget) WithDockerignores(dockerignores []Dockerignore) DockerComposeTarget {
t.dockerignores = append(append([]Dockerignore{}, t.dockerignores...), dockerignores...)
return t
}
func (t DockerComposeTarget) Dockerignores() []Dockerignore {
return append([]Dockerignore{}, t.dockerignores...)
}
func (t DockerComposeTarget) LocalRepos() []LocalGitRepo {
return t.repos
}
func (t DockerComposeTarget) IgnoredLocalDirectories() []string {
return t.ignoredLocalDirectories
}
func (t DockerComposeTarget) TiltFilename() string {
return t.tiltFilename
}
func (t DockerComposeTarget) WithTiltFilename(f string) DockerComposeTarget {
t.tiltFilename = f
return t
}
func (t DockerComposeTarget) WithIgnoredLocalDirectories(dirs []string) DockerComposeTarget {
t.ignoredLocalDirectories = dirs
return t
}
// TODO(nick): This method should be deleted. We should just de-dupe and sort LocalPaths once
// when we create it, rather than have a duplicate method that does the "right" thing.
func (t DockerComposeTarget) Dependencies() []string {
return sliceutils.DedupedAndSorted(t.LocalPaths())
}
func (dc DockerComposeTarget) Validate() error {
if dc.ID().Empty() {
return fmt.Errorf("[Validate] DockerCompose resource missing name:\n%s", dc.YAMLRaw)
}
if len(dc.ConfigPaths) == 0 {
return fmt.Errorf("[Validate] DockerCompose resource %s missing config path", dc.Name)
}
return nil
}
var _ TargetSpec = DockerComposeTarget{}