-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_options.go
98 lines (84 loc) · 1.83 KB
/
build_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
package docker
import (
"context"
"io"
"github.com/rai-project/uuid"
)
type BuildOptions struct {
id string
cache bool
dockerFilePath string
tags []string
labels map[string]string
args map[string]string
archiveReader io.Reader
quiet bool
context context.Context
}
type BuildOption func(*BuildOptions)
func BuildId(id string) BuildOption {
return func(opts *BuildOptions) {
opts.id = id
}
}
func BuildCache(cache bool) BuildOption {
return func(opts *BuildOptions) {
opts.cache = cache
}
}
func BuildLabels(labels map[string]string) BuildOption {
return func(opts *BuildOptions) {
for k, v := range labels {
opts.labels[k] = v
}
}
}
func BuildTags(tags []string) BuildOption {
return func(opts *BuildOptions) {
opts.tags = append(opts.tags, tags...)
}
}
func BuildArguments(args map[string]string) BuildOption {
return func(opts *BuildOptions) {
for k, v := range args {
opts.args[k] = v
}
}
}
func BuildArchiveReader(reader io.Reader) BuildOption {
return func(opts *BuildOptions) {
opts.archiveReader = reader
}
}
func BuildDockerFilePath(path string) BuildOption {
return func(opts *BuildOptions) {
opts.dockerFilePath = path
}
}
func BuildQuiet(quiet bool) BuildOption {
return func(opts *BuildOptions) {
opts.quiet = quiet
}
}
func BuildContext(ctx context.Context) BuildOption {
return func(opts *BuildOptions) {
opts.context = ctx
}
}
func NewBuildOptions(opts ...BuildOption) *BuildOptions {
res := &BuildOptions{
id: uuid.NewV4(),
cache: true,
dockerFilePath: "",
tags: []string{},
labels: map[string]string{},
args: map[string]string{},
archiveReader: nil,
quiet: false,
context: nil,
}
for _, o := range opts {
o(res)
}
return res
}