-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.go
89 lines (72 loc) · 1.95 KB
/
mysql.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
package services
import (
"fmt"
"os"
"strconv"
"github.com/AlecAivazis/survey/v2"
)
type MySqlService struct{}
func (s *MySqlService) GetName() string {
return "Mysql"
}
func (s *MySqlService) GetDefaultPort() int {
return 3306
}
func (s *MySqlService) GetOrganization() string {
return ""
}
func (s *MySqlService) GetImageName() string {
return "mysql"
}
func (s *MySqlService) GetDefaults() map[string]string {
values := map[string]string{
"volume": "mysql_data",
"root_password": "",
"port": strconv.Itoa(s.GetDefaultPort()),
}
// merge base defaults with service defaults
for key, value := range DefaultOptions() {
values[key] = value
}
return values
}
func (s *MySqlService) Prompt() (map[string]string, error) {
defaults := s.GetDefaults()
prompts := []*survey.Question{
{
Name: "volume",
Prompt: &survey.Input{Message: "What is the Docker volume name?", Default: defaults["volume"]},
Validate: survey.Required,
},
{
Name: "root_password",
Prompt: &survey.Input{Message: "What will the root password be? (null by default)", Default: defaults["root_password"]},
},
}
prompts = append(DefaultPrompts(s.GetDefaultPort()), prompts...)
var answers = make(map[string]interface{})
err := survey.Ask(prompts, &answers)
if err != nil {
os.Exit(1)
}
var mapped = make(map[string]string)
// convert all answers into strings and add to mapped
for key, value := range answers {
mapped[key] = value.(string)
}
return mapped, nil
}
func (s *MySqlService) GetDockerCommandArgs(options map[string]string) []string {
allowEmptyPassword := "no"
if options["root_password"] == "" {
allowEmptyPassword = "yes"
}
return []string{
fmt.Sprintf("--publish=%s:3306", options["port"]),
fmt.Sprintf("--volume=%s:/var/lib/mysql", options["volume"]),
"-e",
fmt.Sprintf("MYSQL_ROOT_PASSWORD=%s", options["root_password"]),
"-e",
fmt.Sprintf("MYSQL_ALLOW_EMPTY_PASSWORD=%s", allowEmptyPassword),
}
}