-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
96 lines (82 loc) · 2.24 KB
/
services.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
package dockerCompose
import "fmt"
type Service struct {
Image string `yaml:"image"`
Environment []string `yaml:"environment"`
Ports []string `yaml:"ports"`
Command string `yaml:"command"`
Volumes []string `yaml:"volumes"`
ContainerName string `yaml:"container_name"`
Networks []string `yaml:"networks"`
WorkingDir string `yaml:"working_dir"`
DependsOn []string `yaml:"depends_on"`
Tty bool `yaml:"tty"`
StdinOpen bool `yaml:"stdin_open"`
}
func GenerateService() *Service {
return &Service{
Image: "",
Environment: []string{},
Ports: []string{},
Command: "",
Volumes: []string{},
ContainerName: "",
Networks: []string{},
WorkingDir: "",
DependsOn: []string{},
Tty: true,
StdinOpen: false,
}
}
func (that *Service) SetImage(image string) *Service {
that.Image = image
return that
}
func (that *Service) AddEnvironment(env string) *Service {
that.Environment = append(that.Environment, env)
return that
}
func (that *Service) AddEnvironments(envs []string) *Service {
for i := range envs {
that.AddEnvironment(envs[i])
}
return that
}
func (that *Service) AddPort(from uint, to uint) *Service {
that.Ports = append(that.Ports, fmt.Sprintf("\"%d:%d\"", from, to))
return that
}
func (that *Service) AddPorts(from []uint, to []uint) *Service {
for i := range from {
that.AddPort(from[i], to[i])
}
return that
}
func (that *Service) SetCommand(command string) *Service {
that.Command = command
return that
}
func (that *Service) AddVolume(from string, to string) *Service {
that.Volumes = append(that.Volumes, fmt.Sprintf("%s:%s", from, to))
return that
}
func (that *Service) AddVolumes(from []string, to []string) *Service {
for i := range from {
that.AddVolume(from[i], to[i])
}
return that
}
func (that *Service) SetContainerName(name string) *Service {
that.ContainerName = name
return that
}
func (that *Service) AddNetwork(from string, to string) *Service {
that.Networks = append(that.Networks, fmt.Sprintf("%s:%s", from, to))
return that
}
func (that *Service) AddNetworks(from []string, to []string) *Service {
for i := range from {
that.AddNetwork(from[i], to[i])
}
return that
}