/
deploy_info.go
201 lines (156 loc) · 4.96 KB
/
deploy_info.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package model
import (
"fmt"
"reflect"
"strconv"
"time"
"k8s.io/apimachinery/pkg/labels"
"github.com/windmilleng/tilt/internal/sliceutils"
"github.com/windmilleng/tilt/internal/yaml"
)
type DeployID int64 // Unix ns after epoch -- uniquely identify a deploy
func NewDeployID() DeployID {
return DeployID(time.Now().UnixNano())
}
func (dID DeployID) String() string { return strconv.Itoa(int(dID)) }
func (dID DeployID) Empty() bool { return dID == 0 }
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
}
// 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) 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
}
type K8sTarget struct {
Name TargetName
YAML string
PortForwards []PortForward
// labels for pods that we should watch and associate with this resource
ExtraPodSelectors []labels.Selector
// Each K8s entity should have a display name for user interfaces
// that balances brevity and uniqueness
DisplayNames []string
dependencyIDs []TargetID
}
func (k8s K8sTarget) Empty() bool { return reflect.DeepEqual(k8s, K8sTarget{}) }
func (k8s K8sTarget) DependencyIDs() []TargetID {
return k8s.dependencyIDs
}
func (k8s K8sTarget) Validate() error {
if k8s.ID().Empty() {
return fmt.Errorf("[Validate] K8s resources missing name:\n%s", k8s.YAML)
}
if k8s.YAML == "" {
return fmt.Errorf("[Validate] K8s resources %q missing YAML", k8s.Name)
}
return nil
}
func (k8s K8sTarget) ID() TargetID {
return TargetID{
Type: TargetTypeK8s,
Name: k8s.Name,
}
}
func (k8s K8sTarget) WithDependencyIDs(ids []TargetID) K8sTarget {
k8s.dependencyIDs = DedupeTargetIDs(ids)
return k8s
}
func (k8s K8sTarget) AppendYAML(y string) K8sTarget {
if k8s.YAML == "" {
k8s.YAML = y
} else {
k8s.YAML = yaml.ConcatYAML(k8s.YAML, y)
}
return k8s
}
var _ TargetSpec = K8sTarget{}
var _ TargetSpec = DockerComposeTarget{}