forked from stelligent/mu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
165 lines (150 loc) · 4.07 KB
/
app.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package cli
import (
"fmt"
"io/ioutil"
"os"
"github.com/stelligent/mu/common"
"github.com/stelligent/mu/provider/aws"
"github.com/urfave/cli"
)
// NewApp creates a new CLI app
func NewApp() *cli.App {
context := common.NewContext()
app := cli.NewApp()
app.Name = "mu"
app.Usage = "Microservice Platform on AWS"
app.Version = common.GetVersion()
app.EnableBashCompletion = true
app.Commands = []cli.Command{
*newInitCommand(context),
*newValidateCommand(context),
*newEnvironmentsCommand(context),
*newServicesCommand(context),
*newDatabasesCommand(context),
*newPipelinesCommand(context),
*newCatalogCommand(context),
*newPurgeCommand(context),
}
app.Before = func(c *cli.Context) error {
// setup logging
if c.Bool("verbose") {
common.SetupLogging(2)
} else if c.Bool("silent") {
common.SetupLogging(0)
} else {
common.SetupLogging(1)
}
// initialize context
err := context.InitializeContext()
if err != nil {
return err
}
log.Debugf("version:%v", common.GetVersion())
// TODO: support initializing context from other cloud providers?
log.Debugf("dryrun:%v path:%v", c.Bool("dryrun"), c.String("dryrun-output"))
dryrunPath := ""
if c.Bool("dryrun") {
dryrunPath = c.String("dryrun-output")
}
err = aws.InitializeContext(context, c.String("profile"), c.String("assume-role"), c.String("region"), dryrunPath, c.Bool("skip-version-check"), c.String("proxy"), c.Bool("allow-data-loss"))
if err != nil {
return err
}
err = context.InitializeConfigFromFile(c.String("config"))
if c.Args().First() != "init" {
if err != nil {
log.Warningf("Unable to load mu config: %v", err)
}
if err = context.Config.Validate(); err != nil {
log.Errorf("Invalid Config: %v", err)
return nil
}
}
context.Config.DryRun = c.Bool("dryrun")
// Allow overriding the `DisableIAM` in config via `--disable-iam` or `-I`
if c.Bool("disable-iam") {
context.Config.DisableIAM = true
}
if c.Bool("silent") {
context.DockerOut = ioutil.Discard
} else {
context.DockerOut = os.Stdout
}
// Get the namespace for the stack creation. This will prefix the stack names
// The order of precedence is command-line arg, env variable then config file
nameSpace := c.String("namespace")
if nameSpace != "" {
log.Debug("Using namespace \"%s\"", nameSpace)
context.Config.Namespace = nameSpace
} else {
nameSpace = os.Getenv("MU_NAMESPACE")
if nameSpace != "" {
log.Debug("Using namespace \"%s\"", nameSpace)
context.Config.Namespace = nameSpace
}
}
if context.Config.Namespace == "" {
log.Debug("Using namespace \"mu\"")
context.Config.Namespace = "mu"
}
// initialize extensions
return context.InitializeExtensions()
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "path to config file",
Value: "mu.yml",
},
cli.StringFlag{
Name: "region, r",
Usage: "AWS Region to use",
},
cli.StringFlag{
Name: "assume-role, a",
Usage: "ARN of IAM role to assume",
},
cli.StringFlag{
Name: "profile, p",
Usage: "AWS config profile to use",
},
cli.StringFlag{
Name: "namespace, n",
Usage: "Namespace to use as a prefix for stacks",
},
cli.BoolFlag{
Name: "silent, s",
Usage: "silent mode, errors only",
},
cli.BoolFlag{
Name: "verbose, V",
Usage: "increase level of log verbosity",
},
cli.BoolFlag{
Name: "dryrun, d",
Usage: "generate the cloudformation templates without upserting stacks",
},
cli.StringFlag{
Name: "dryrun-output, O",
Usage: "output directory for dryrun",
Value: fmt.Sprintf("%s/mu-dryrun", os.TempDir()),
},
cli.BoolFlag{
Name: "disable-iam, I",
Usage: "disable the automatic creation of IAM resources",
},
cli.BoolFlag{
Name: "skip-version-check, F",
Usage: "disable the checking of stack major numbers before updating",
},
cli.StringFlag{
Name: "proxy, P",
Usage: "Proxy to route AWS requests through",
},
cli.BoolFlag{
Name: "allow-data-loss",
Usage: "temporarily allow delete or replace on RDS or KMS resources",
},
}
return app
}