-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo.go
91 lines (75 loc) · 2.07 KB
/
mongo.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
package services
import (
"fmt"
"os"
"strconv"
"github.com/AlecAivazis/survey/v2"
)
type MongoService struct{}
func (s *MongoService) GetName() string {
return "Mongo"
}
func (s *MongoService) GetDefaultPort() int {
return 27017
}
func (s *MongoService) GetOrganization() string {
return ""
}
func (s *MongoService) GetImageName() string {
return "mongo"
}
func (s *MongoService) GetDefaults() map[string]string {
values := map[string]string{
"volume": "mongo_data",
"port": strconv.Itoa(s.GetDefaultPort()),
"root_user": "admin",
"root_password": "password",
}
// merge base defaults with service defaults
for key, value := range DefaultOptions() {
values[key] = value
}
return values
}
func (s *MongoService) 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_user",
Prompt: &survey.Input{Message: "What will the root user be?", Default: defaults["root_user"]},
Validate: survey.Required,
},
{
Name: "root_password",
Prompt: &survey.Input{Message: "What will the root password be?", Default: defaults["root_password"]},
Validate: survey.Required,
},
}
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 *MongoService) GetDockerCommandArgs(options map[string]string) []string {
return []string{
fmt.Sprintf("--publish=%s:27017", options["port"]),
fmt.Sprintf("--volume=%s:/data/db", options["volume"]),
"-e",
fmt.Sprintf("MONGO_INITDB_ROOT_USERNAME=%s", options["root_user"]),
"-e",
fmt.Sprintf("MONGO_INITDB_ROOT_PASSWORD=%s", options["root_password"]),
}
}