/
container.go
71 lines (57 loc) · 1.76 KB
/
container.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
package aws
import (
"encoding/json"
"fmt"
)
type ContainerDefinition struct {
Name string `json:"name"`
Image string `json:"image"`
PortMappings []ContainerPortMapping `json:"portMappings"`
Environment []ContainerEnvVar `json:"environment"`
LogConfiguration *ContainerLogConfig `json:"logConfiguration"`
DockerLabels map[string]string `json:"dockerLabels"`
LinuxParameters *ContainerLinuxParameters `json:"linuxParameters,omitempty"`
}
func (d *ContainerDefinition) Validate() error {
if d.Name == "" {
return fmt.Errorf("missing ContainerDefinition.Name")
}
if d.Image == "" {
return fmt.Errorf("missing ContainerDefinition.Image")
}
if d.PortMappings == nil {
d.PortMappings = []ContainerPortMapping{}
}
if d.Environment == nil {
d.Environment = []ContainerEnvVar{}
}
if d.LogConfiguration == nil {
return fmt.Errorf("missing ContainerDefinition.LogConfiguration")
}
return nil
}
func (d *ContainerDefinition) String() string {
data, _ := json.Marshal(d)
return "[" + string(data) + "]"
}
type ContainerLinuxParameters struct {
Capabilities ContainerLinuxCapabilities `json:"capabilities"`
}
type ContainerLinuxCapabilities struct {
Add []string `json:"add"`
Drop []string `json:"drop"`
}
type ContainerEnvVar struct {
Name string `json:"name"`
Value string `json:"value"`
}
type ContainerPortMapping struct {
ContainerPort int `json:"containerPort"`
HostPort int `json:"hostPort"`
Protocol string `json:"protocol"`
}
type ContainerLogConfig struct {
LogDriver string `json:"logDriver"`
SecretOptions interface{} `json:"secretOptions"`
Options map[string]interface{} `json:"options"`
}