/
main.go
126 lines (119 loc) · 2.71 KB
/
main.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
package main
import (
"io/ioutil"
"os"
"github.com/BurntSushi/toml"
"github.com/marwan-at-work/baghdad"
"gopkg.in/urfave/cli.v2"
)
func main() {
app := &cli.App{
Name: "baghdad",
Usage: "automate your swarm",
Commands: []*cli.Command{
{
Name: "secret",
Usage: "manage project secrets",
Subcommands: []*cli.Command{
{
Name: "create",
Usage: "deploy a secret to the swarm i.e. baghdad secret create <secret-name> <path-to-file>",
Action: secretCreate,
},
},
},
{
Name: "register",
Usage: "register your credentials to be used for subsequent commands",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "server",
Usage: "Baghdad API's URL",
},
},
Action: register,
},
{
Name: "logs",
Usage: "listen to your application build/app logs",
Action: getLogs,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "service",
Usage: "get logs for a specific service",
Aliases: []string{"s"},
},
&cli.StringFlag{
Name: "env",
Usage: "specify environment to which the service belongs",
Aliases: []string{"e"},
},
},
},
{
Name: "generate",
Usage: "generate configs to stdout",
Subcommands: []*cli.Command{
{
Name: "stack",
Action: getStack,
Usage: "generate deployable stack compose file",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tag",
Aliases: []string{"t"},
Usage: "specify the tag that applies to each baghdad.toml service",
},
&cli.StringFlag{
Name: "env",
Aliases: []string{"e"},
Usage: "specify the environment pipeline",
},
&cli.StringFlag{
Name: "host",
Usage: "specify the host domain name",
},
},
},
},
},
{
Name: "deploy",
Usage: "deploy a project to your cluster",
Action: deploy,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tag",
Usage: "the build tag of the repository - required",
Aliases: []string{"T"},
},
&cli.StringFlag{
Name: "env",
Usage: "the environment you want to deploy to",
Aliases: []string{"E"},
},
&cli.StringFlag{
Name: "branch",
Usage: "the branch you want to deploy from",
Aliases: []string{"B"},
},
&cli.StringFlag{
Name: "owner",
Usage: "the github username",
Aliases: []string{"O"},
},
},
},
},
}
app.Run(os.Args)
}
func getBaghdad() (b baghdad.Baghdad, err error) {
p, err := ioutil.ReadFile("./baghdad.toml")
if err != nil {
return
}
b = baghdad.Baghdad{}
err = toml.Unmarshal(p, &b)
return
}