-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathoption.go
68 lines (59 loc) · 1.44 KB
/
option.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
package docker
import (
"fmt"
"strings"
"go.uber.org/multierr"
)
// RunOptions is used to pass options to ContainerRunWithOptions
type (
RunOptions struct {
ImageName string
ImageTag string
Hostname string
ContainerName string
PortPublishes []PortPublish
Volumes Volumes
RestartAlways bool
RunParams []string
}
Volume struct {
HostPath string
ContainerPath string
}
Volumes []Volume
PortPublish struct {
HostPort uint
ContainerPort uint
}
)
func (opts *RunOptions) Validate() error {
var errs []error
if strings.TrimSpace(opts.ImageName) == "" {
errs = append(errs, fmt.Errorf("image name is required"))
}
if strings.TrimSpace(opts.ImageTag) == "" {
errs = append(errs, fmt.Errorf("image tag is required"))
}
if strings.TrimSpace(opts.ContainerName) == "" {
errs = append(errs, fmt.Errorf("container name is required"))
}
for _, volume := range opts.Volumes {
if volume.HostPath == "" {
errs = append(errs, fmt.Errorf("HostPath can not be empty"))
}
if volume.ContainerPath == "" {
errs = append(errs, fmt.Errorf("ContainerPath can not be empty"))
}
}
return multierr.Combine(errs...)
}
func CombineImageNameAndTag(imageName, tag string) string {
return imageName + ":" + tag
}
func (volumes Volumes) ExtractHostPaths() []string {
hostPaths := make([]string, len(volumes))
for i, volume := range volumes {
hostPaths[i] = volume.HostPath
}
return hostPaths
}