-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.go
79 lines (66 loc) · 1.9 KB
/
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
package containers
import "io"
/**************** Image Options ****************/
// ImageOption is a function to set configuration to the Image object.
type ImageOption func(*Image) error
// Build returns an ImageOption to build a tarball of a Dockerfile
func Build(tarball io.Reader) ImageOption {
return func(i *Image) error {
i.buildTarball = tarball
return nil
}
}
/**************** Container Options ****************/
// ContainerOption is a function to set configuration to the Container object.
type ContainerOption func(*Container) error
// WorkDir sets the working directory of the container, where calls will be made.
func WorkDir(workDir string) ContainerOption {
return func(c *Container) error {
c.workDir = workDir
return nil
}
}
// Shell sets the shell-form of RUN, CMD, ENTRYPOINT
func Shell(cmd []string) ContainerOption {
return func(c *Container) error {
c.shell = cmd
return nil
}
}
// Command sets the commands to be run by the container after being built.
func Command(cmd []string) ContainerOption {
return func(c *Container) error {
c.cmd = cmd
return nil
}
}
// Volume sets local directories to be volumed in the container.
func Volume(sourcePath, containerPath string) ContainerOption {
return func(c *Container) error {
c.volumes = append(c.volumes, volume{
source: sourcePath,
target: containerPath,
},
)
return nil
}
}
// Variable sets an environment variable in the container.
func Variable(key, value string) ContainerOption {
return func(c *Container) error {
c.env = append(c.env, toEnvFormat(key, value))
return nil
}
}
// Variables sets multiple environment variables in the container.
func Variables(vars map[string]string) ContainerOption {
return func(c *Container) error {
for key, value := range vars {
c.env = append(c.env, toEnvFormat(key, value))
}
return nil
}
}
func toEnvFormat(key, value string) string {
return key + "=" + value
}