/
build_stapel_stage_options.go
187 lines (154 loc) · 5.3 KB
/
build_stapel_stage_options.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
package container_backend
import (
"fmt"
"io"
)
type BuildStapelStageOptionsInterface interface {
SetBaseImage(baseImage string) BuildStapelStageOptionsInterface
AddLabels(labels map[string]string) BuildStapelStageOptionsInterface
AddVolumes(volumes []string) BuildStapelStageOptionsInterface
AddExpose(expose []string) BuildStapelStageOptionsInterface
AddEnvs(envs map[string]string) BuildStapelStageOptionsInterface
SetCmd(cmd []string) BuildStapelStageOptionsInterface
SetEntrypoint(entrypoint []string) BuildStapelStageOptionsInterface
SetUser(user string) BuildStapelStageOptionsInterface
SetWorkdir(workdir string) BuildStapelStageOptionsInterface
SetHealthcheck(healthcheck string) BuildStapelStageOptionsInterface
AddBuildVolumes(volumes ...string) BuildStapelStageOptionsInterface
AddCommands(commands ...string) BuildStapelStageOptionsInterface
AddDataArchive(archive io.ReadCloser, archiveType ArchiveType, to string) BuildStapelStageOptionsInterface
RemoveData(removeType RemoveType, paths []string, keepParentDirs []string) BuildStapelStageOptionsInterface
AddDependencyImport(imageName, fromPath, toPath string, includePaths, excludePaths []string, owner, group string) BuildStapelStageOptionsInterface
}
type BuildStapelStageOptions struct {
BaseImage string
Labels []string
Volumes []string
Expose []string
Envs map[string]string
Cmd []string
Entrypoint []string
User string
Workdir string
Healthcheck string
BuildVolumes []string
Commands []string
DataArchiveSpecs []DataArchiveSpec
RemoveDataSpecs []RemoveDataSpec
DependencyImportSpecs []DependencyImportSpec
}
type ArchiveType int
//go:generate stringer -type=ArchiveType
const (
FileArchive ArchiveType = iota
DirectoryArchive
)
type DataArchiveSpec struct {
Archive io.ReadCloser
Type ArchiveType
To string
}
type RemoveType int
//go:generate stringer -type=RemoveType
const (
RemoveExactPath RemoveType = iota
RemoveExactPathWithEmptyParentDirs
RemoveInsidePath
)
type RemoveDataSpec struct {
Type RemoveType
Paths []string
KeepParentDirs []string
}
type DependencyImportSpec struct {
ImageName string
FromPath string
ToPath string
IncludePaths []string
ExcludePaths []string
Owner string
Group string
}
func (opts *BuildStapelStageOptions) SetBaseImage(baseImage string) BuildStapelStageOptionsInterface {
opts.BaseImage = baseImage
return opts
}
func (opts *BuildStapelStageOptions) AddLabels(labels map[string]string) BuildStapelStageOptionsInterface {
for k, v := range labels {
opts.Labels = append(opts.Labels, fmt.Sprintf("%s=%s", k, v))
}
return opts
}
func (opts *BuildStapelStageOptions) AddVolumes(volumes []string) BuildStapelStageOptionsInterface {
opts.Volumes = append(opts.Volumes, volumes...)
return opts
}
func (opts *BuildStapelStageOptions) AddExpose(expose []string) BuildStapelStageOptionsInterface {
opts.Expose = append(opts.Expose, expose...)
return opts
}
func (opts *BuildStapelStageOptions) AddEnvs(envs map[string]string) BuildStapelStageOptionsInterface {
if opts.Envs == nil {
opts.Envs = map[string]string{}
}
for k, v := range envs {
opts.Envs[k] = v
}
return opts
}
func (opts *BuildStapelStageOptions) SetCmd(cmd []string) BuildStapelStageOptionsInterface {
opts.Cmd = cmd
return opts
}
func (opts *BuildStapelStageOptions) SetEntrypoint(entrypoint []string) BuildStapelStageOptionsInterface {
opts.Entrypoint = entrypoint
return opts
}
func (opts *BuildStapelStageOptions) SetUser(user string) BuildStapelStageOptionsInterface {
opts.User = user
return opts
}
func (opts *BuildStapelStageOptions) SetWorkdir(workdir string) BuildStapelStageOptionsInterface {
opts.Workdir = workdir
return opts
}
func (opts *BuildStapelStageOptions) SetHealthcheck(healthcheck string) BuildStapelStageOptionsInterface {
opts.Healthcheck = healthcheck
return opts
}
func (opts *BuildStapelStageOptions) AddBuildVolumes(volumes ...string) BuildStapelStageOptionsInterface {
opts.BuildVolumes = append(opts.BuildVolumes, volumes...)
return opts
}
func (opts *BuildStapelStageOptions) AddCommands(commands ...string) BuildStapelStageOptionsInterface {
opts.Commands = append(opts.Commands, commands...)
return opts
}
func (opts *BuildStapelStageOptions) AddDataArchive(archive io.ReadCloser, archiveType ArchiveType, to string) BuildStapelStageOptionsInterface {
opts.DataArchiveSpecs = append(opts.DataArchiveSpecs, DataArchiveSpec{
Archive: archive,
Type: archiveType,
To: to,
})
return opts
}
func (opts *BuildStapelStageOptions) RemoveData(removeType RemoveType, paths []string, keepParentDirs []string) BuildStapelStageOptionsInterface {
opts.RemoveDataSpecs = append(opts.RemoveDataSpecs, RemoveDataSpec{
Type: removeType,
Paths: paths,
KeepParentDirs: keepParentDirs,
})
return opts
}
func (opts *BuildStapelStageOptions) AddDependencyImport(imageName, fromPath, toPath string, includePaths, excludePaths []string, owner, group string) BuildStapelStageOptionsInterface {
opts.DependencyImportSpecs = append(opts.DependencyImportSpecs, DependencyImportSpec{
ImageName: imageName,
FromPath: fromPath,
ToPath: toPath,
IncludePaths: includePaths,
ExcludePaths: excludePaths,
Owner: owner,
Group: group,
})
return opts
}