forked from tchen0123/supergiant
/
server.go
172 lines (158 loc) · 4.06 KB
/
server.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
166
167
168
169
170
171
172
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/supergiant/supergiant/pkg/core"
"github.com/supergiant/supergiant/pkg/provider/aws"
"github.com/supergiant/supergiant/pkg/provider/digitalocean"
"github.com/supergiant/supergiant/pkg/provider/gce"
"github.com/supergiant/supergiant/pkg/provider/kubernetes"
"github.com/supergiant/supergiant/pkg/provider/openstack"
"github.com/supergiant/supergiant/pkg/provider/packet"
"github.com/supergiant/supergiant/pkg/server"
"github.com/urfave/cli"
)
var version = "unversioned"
func main() {
c := &core.Core{
Version: version,
}
app := cli.NewApp()
app.Name = "supergiant-server"
app.Usage = "Supergiant server " + version
app.Version = version
app.Action = func(ctx *cli.Context) {
// TODO should check for missing setting here to show cli help
c.Initialize()
// See relevant NOTE in core.go
c.AWSProvider = func(creds map[string]string) core.Provider {
return &aws.Provider{
Core: c,
EC2: aws.EC2,
IAM: aws.IAM,
ELB: aws.ELB,
S3: aws.S3,
EFS: aws.EFS,
}
}
c.DOProvider = func(creds map[string]string) core.Provider {
return &digitalocean.Provider{
Core: c,
Client: digitalocean.Client,
}
}
c.OSProvider = func(creds map[string]string) core.Provider {
return &openstack.Provider{
Core: c,
Client: openstack.Client,
}
}
c.GCEProvider = func(creds map[string]string) core.Provider {
return &gce.Provider{
Core: c,
Client: gce.Client,
}
}
c.PACKProvider = func(creds map[string]string) core.Provider {
return &packet.Provider{
Core: c,
Client: packet.Client,
}
}
c.K8SProvider = &kubernetes.Provider{Core: c}
// We do this here, and not in core, so that we can ensure the file closes on exit.
if c.LogPath != "" {
file, err := os.OpenFile(c.LogPath, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
panic(err)
}
defer file.Close()
path, err := filepath.Abs(c.LogPath)
if err != nil {
panic(err)
}
fmt.Println("Writing log to " + path)
c.Log.Out = file
}
srv, err := server.New(c)
if err != nil {
panic(err)
}
srv.Start()
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "sqlite-file",
Usage: "SQLite3 database (.db) file",
Destination: &c.SQLiteFile,
},
cli.StringFlag{
Name: "psql-host",
Usage: "PostgreSQL host",
Destination: &c.PsqlHost,
},
cli.StringFlag{
Name: "psql-db",
Usage: "PostgreSQL database name",
Destination: &c.PsqlDb,
},
cli.StringFlag{
Name: "psql-user",
Usage: "PostgreSQL database user",
Destination: &c.PsqlUser,
},
cli.StringFlag{
Name: "psql-pass",
Usage: "PostgreSQL database password",
Destination: &c.PsqlPass,
},
cli.StringFlag{
Name: "publish-host",
Usage: "Host that can be used to connect to this Supergiant server remotely",
Destination: &c.PublishHost,
},
cli.StringFlag{
Name: "http-port",
Usage: "HTTP port for the web interfaces",
Destination: &c.HTTPPort,
},
cli.BoolFlag{
Name: "ui-enabled",
Usage: "Enabled UI",
Destination: &c.UIEnabled,
},
cli.StringFlag{
Name: "https-port",
Usage: "HTTPS (SSL) port for the web interfaces",
Destination: &c.HTTPSPort,
},
cli.StringFlag{
Name: "ssl-cert-file",
Usage: "SSL certificate file",
Destination: &c.SSLCertFile,
},
cli.StringFlag{
Name: "ssl-key-file",
Usage: "SSL key file",
Destination: &c.SSLKeyFile,
},
cli.StringFlag{
Name: "log-file",
Usage: "Log output filepath",
Destination: &c.LogPath,
},
cli.StringFlag{
Name: "log-level",
Usage: "Log level",
Destination: &c.LogLevel,
// Value: <--- NOTE just cuz you always forget you can set defaults
},
cli.StringFlag{
Name: "config-file",
Usage: "JSON config filepath (command line arguments will override the values set here)",
Destination: &c.ConfigFilePath,
},
}
app.Run(os.Args)
}