-
Notifications
You must be signed in to change notification settings - Fork 0
/
expose.go
100 lines (83 loc) · 2.26 KB
/
expose.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
97
98
99
100
package services
import (
"fmt"
"os"
"strconv"
"github.com/AlecAivazis/survey/v2"
)
type ExposeService struct{}
func (s *ExposeService) GetName() string {
return "Expose"
}
func (s *ExposeService) GetDefaultPort() int {
return 8080
}
func (s *ExposeService) GetOrganization() string {
return "beyondcodegmbh"
}
func (s *ExposeService) GetImageName() string {
return "expose-server"
}
func (s *ExposeService) GetDefaults() map[string]string {
values := map[string]string{
"volume": "expose_data",
"port": strconv.Itoa(s.GetDefaultPort()),
"domain": "example.com",
"username": "admin",
"password": "password",
}
// merge base defaults with service defaults
for key, value := range DefaultOptions() {
values[key] = value
}
return values
}
func (s *ExposeService) Prompt() (map[string]string, error) {
defaults := s.GetDefaults()
prompts := []*survey.Question{
{
Name: "domain",
Prompt: &survey.Input{Message: "What is the domain?", Default: defaults["domain"]},
Validate: survey.Required,
},
{
Name: "volume",
Prompt: &survey.Input{Message: "What is the Docker volume name?", Default: defaults["volume"]},
Validate: survey.Required,
},
{
Name: "username",
Prompt: &survey.Input{Message: "What is the username?", Default: defaults["username"]},
Validate: survey.Required,
},
{
Name: "password",
Prompt: &survey.Input{Message: "What is the password?", Default: defaults["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 *ExposeService) GetDockerCommandArgs(options map[string]string) []string {
return []string{
fmt.Sprintf("--publish=%s:8080", options["port"]),
fmt.Sprintf("--volume=%s:/root/.express", options["volume"]),
"-e",
fmt.Sprintf("\"username=%s\"", options["username"]),
"-e",
fmt.Sprintf("\"password=%s\"", options["password"]),
"-e",
fmt.Sprintf("\"domain=%s\"", options["domain"]),
}
}