-
Notifications
You must be signed in to change notification settings - Fork 288
/
docker_info.go
177 lines (143 loc) · 3.99 KB
/
docker_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
package model
import (
"fmt"
"path/filepath"
"sort"
"github.com/docker/distribution/reference"
"github.com/windmilleng/tilt/internal/sliceutils"
)
type ImageTarget struct {
Ref reference.Named
BuildDetails BuildDetails
cachePaths []string
// TODO(nick): It might eventually make sense to represent
// Tiltfile as a separate nodes in the build graph, rather
// than duplicating it in each ImageTarget.
tiltFilename string
dockerignores []Dockerignore
repos []LocalGitRepo
}
func (i ImageTarget) ID() TargetID {
name := TargetName("")
if i.Ref != nil {
name = TargetName(i.Ref.String())
}
return TargetID{
Type: TargetTypeImage,
Name: name,
}
}
func (i ImageTarget) Validate() error {
if i.Ref == nil {
return fmt.Errorf("[Validate] Image target missing image ref: %+v", i.BuildDetails)
}
switch bd := i.BuildDetails.(type) {
case StaticBuild:
if bd.BuildPath == "" {
return fmt.Errorf("[Validate] Image %q missing build path", i.Ref)
}
case FastBuild:
if bd.BaseDockerfile == "" {
return fmt.Errorf("[Validate] Image %q missing base dockerfile", i.Ref)
}
for _, mnt := range bd.Mounts {
if !filepath.IsAbs(mnt.LocalPath) {
return fmt.Errorf(
"[Validate] Image %q: mount must be an absolute path (got: %s)", i.Ref, mnt.LocalPath)
}
}
default:
return fmt.Errorf("[Validate] Image %q has neither StaticBuildInfo nor FastBuildInfo", i.Ref)
}
return nil
}
type BuildDetails interface {
buildDetails()
}
func (i ImageTarget) StaticBuildInfo() StaticBuild {
ret, _ := i.BuildDetails.(StaticBuild)
return ret
}
func (i ImageTarget) IsStaticBuild() bool {
_, ok := i.BuildDetails.(StaticBuild)
return ok
}
func (i ImageTarget) FastBuildInfo() FastBuild {
ret, _ := i.BuildDetails.(FastBuild)
return ret
}
func (i ImageTarget) IsFastBuild() bool {
_, ok := i.BuildDetails.(FastBuild)
return ok
}
func (i ImageTarget) WithBuildDetails(details BuildDetails) ImageTarget {
i.BuildDetails = details
return i
}
func (i ImageTarget) WithCachePaths(paths []string) ImageTarget {
i.cachePaths = append(append([]string{}, i.cachePaths...), paths...)
sort.Strings(i.cachePaths)
return i
}
func (i ImageTarget) CachePaths() []string {
return i.cachePaths
}
func (i ImageTarget) WithRepos(repos []LocalGitRepo) ImageTarget {
i.repos = append(append([]LocalGitRepo{}, i.repos...), repos...)
return i
}
func (i ImageTarget) WithDockerignores(dockerignores []Dockerignore) ImageTarget {
i.dockerignores = append(append([]Dockerignore{}, i.dockerignores...), dockerignores...)
return i
}
func (i ImageTarget) Dockerignores() []Dockerignore {
return append([]Dockerignore{}, i.dockerignores...)
}
func (i ImageTarget) LocalPaths() []string {
switch bd := i.BuildDetails.(type) {
case StaticBuild:
return []string{bd.BuildPath}
case FastBuild:
result := make([]string, len(bd.Mounts))
for i, mount := range bd.Mounts {
result[i] = mount.LocalPath
}
return result
}
return nil
}
func (i ImageTarget) LocalRepos() []LocalGitRepo {
return i.repos
}
func (i ImageTarget) IgnoredLocalDirectories() []string {
return nil
}
func (i ImageTarget) TiltFilename() string {
return i.tiltFilename
}
func (i ImageTarget) WithTiltFilename(f string) ImageTarget {
i.tiltFilename = f
return i
}
// 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 (i ImageTarget) Dependencies() []string {
return sliceutils.DedupedAndSorted(i.LocalPaths())
}
type StaticBuild struct {
Dockerfile string
BuildPath string // the absolute path to the files
BuildArgs DockerBuildArgs
}
func (StaticBuild) buildDetails() {}
type FastBuild struct {
BaseDockerfile string
Mounts []Mount
Steps []Step
Entrypoint Cmd
// A HotReload container image knows how to automatically
// reload any changes in the container. No need to restart it.
HotReload bool
}
func (FastBuild) buildDetails() {}
var _ TargetSpec = ImageTarget{}