@@ -15,10 +15,11 @@ import (
15
15
)
16
16
17
17
var (
18
- appName string
19
- composePath string
20
- outputPath string
21
- dockerHostConn string
18
+ appName string
19
+ composePath string
20
+ outputPath string
21
+ dockerHostConn string
22
+ interactiveBash bool
22
23
)
23
24
24
25
const bashTemplate = `#!/bin/bash
@@ -28,6 +29,38 @@ if /usr/bin/docker {{.DockerHostConnCmdArg}} ps -a | grep --quiet {{.Service.Nam
28
29
/usr/bin/docker {{.DockerHostConnCmdArg}} rm -f {{.Service.Name}}_1
29
30
fi
30
31
32
+ {{if .InteractiveBash}}
33
+ while [ "$#" -gt 0 ]; do case "$1" in
34
+ --interactive-bash) interactivebash="true"; shift 1;;
35
+ *) shift;;
36
+ esac
37
+ done
38
+
39
+ if [[ $interactivebash == "true" ]]; then
40
+ /usr/bin/docker {{.DockerHostConnCmdArg}} run \
41
+ {{if .Service.Privileged}}--privileged=true {{end}} \
42
+ -ti \
43
+ --name {{.Service.Name}}_1 \
44
+ {{if .Service.HostName}}--hostname={{.Service.HostName}} {{end}} \
45
+ {{range .Service.Volumes}}-v {{.}} {{end}} \
46
+ {{range .Service.Links}}--link {{.}} {{end}} \
47
+ {{range $key, $value := .Service.Environment}}-e {{$key}}="{{$value}}" {{end}} \
48
+ {{range .Service.Ports}}-p {{.}} {{end}} \
49
+ {{.Service.Image}} bash
50
+ else
51
+ /usr/bin/docker {{.DockerHostConnCmdArg}} run \
52
+ {{if .Service.Privileged}}--privileged=true {{end}} \
53
+ --restart=always \
54
+ -d \
55
+ --name {{.Service.Name}}_1 \
56
+ {{if .Service.HostName}}--hostname={{.Service.HostName}} {{end}} \
57
+ {{range .Service.Volumes}}-v {{.}} {{end}} \
58
+ {{range .Service.Links}}--link {{.}} {{end}} \
59
+ {{range $key, $value := .Service.Environment}}-e {{$key}}="{{$value}}" {{end}} \
60
+ {{range .Service.Ports}}-p {{.}} {{end}} \
61
+ {{.Service.Image}} {{.Service.Command}}
62
+ fi
63
+ {{else}}
31
64
/usr/bin/docker {{.DockerHostConnCmdArg}} run \
32
65
{{if .Service.Privileged}}--privileged=true {{end}} \
33
66
--restart=always \
38
71
{{range .Service.Links}}--link {{.}} {{end}} \
39
72
{{range $key, $value := .Service.Environment}}-e {{$key}}="{{$value}}" {{end}} \
40
73
{{range .Service.Ports}}-p {{.}} {{end}} \
41
- {{.Service.Image}} {{.Service.Command}}
74
+ {{.Service.Image}} {{.Service.Command}}
75
+ {{end}}
42
76
`
43
77
44
78
// ScriptDataTemplate contains the whole data configuration used to fill the script
45
79
type ScriptDataTemplate struct {
46
80
AppName string
47
81
DockerHostConnCmdArg string
82
+ InteractiveBash bool
48
83
Service Service
49
84
}
50
85
@@ -100,7 +135,11 @@ func removeBlankLinkes(path string) {
100
135
101
136
func buildScriptDataTemplate (serviceName string , service Service ) ScriptDataTemplate {
102
137
// common data template for all services from the same app
103
- data := ScriptDataTemplate {AppName : appName }
138
+ data := ScriptDataTemplate {
139
+ AppName : appName ,
140
+ InteractiveBash : interactiveBash ,
141
+ }
142
+
104
143
if dockerHostConn != "" {
105
144
data .DockerHostConnCmdArg = "--host=" + dockerHostConn
106
145
}
@@ -140,6 +179,7 @@ func main() {
140
179
flag .StringVar (& composePath , "yml" , "docker-compose.yml" , "compose file path" )
141
180
flag .StringVar (& outputPath , "output" , "." , "output directory" )
142
181
flag .StringVar (& dockerHostConn , "docker-host" , "" , "docker host connection" )
182
+ flag .BoolVar (& interactiveBash , "interactive-bash" , false , "include option to run the generated script with interactive bash" )
143
183
144
184
flag .Parse ()
145
185
0 commit comments