-
Notifications
You must be signed in to change notification settings - Fork 5
/
actions.go
162 lines (143 loc) · 3.6 KB
/
actions.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
package main
import (
"errors"
"os"
"strings"
"github.com/sirupsen/logrus"
"github.com/spaceuptech/galaxy/cmd"
"github.com/spaceuptech/galaxy/model"
"github.com/spaceuptech/galaxy/proxy"
"github.com/spaceuptech/galaxy/runner"
"github.com/spaceuptech/galaxy/runner/driver"
"github.com/spaceuptech/galaxy/runner/services"
"github.com/spaceuptech/galaxy/server"
"github.com/spaceuptech/galaxy/utils/auth"
"github.com/urfave/cli"
)
func actionRunner(c *cli.Context) error {
// Get runner config flags
port := c.String("port")
proxyPort := c.String("proxy-port")
loglevel := c.String("log-level")
// Get jwt config
jwtAlgo := auth.JWTAlgorithm(c.String("jwt-algo"))
jwtSecret := c.String("jwt-secret")
jwtProxySecret := c.String("jwt-proxy-secret")
// Get driver config
driverType := c.String("driver")
driverConfig := c.String("driver-config")
outsideCluster := c.Bool("outside-cluster")
// Set the log level
setLogLevel(loglevel)
// Create a new runner object
r, err := runner.New(&runner.Config{
Port: port,
ProxyPort: proxyPort,
Auth: &auth.Config{
Mode: auth.Runner,
JWTAlgorithm: jwtAlgo,
Secret: jwtSecret,
ProxySecret: jwtProxySecret,
},
Driver: &driver.Config{
DriverType: model.DriverType(driverType),
ConfigFilePath: driverConfig,
IsInCluster: !outsideCluster,
},
Providers: &services.Config{
DOToken: c.String("do-token"),
Region: c.String("region"),
Providers: c.StringSlice("providers"),
},
})
if err != nil {
logrus.Errorf("Failed to start runner - %s", err.Error())
os.Exit(-1)
}
return r.Start()
}
func actionProxy(c *cli.Context) error {
// Get all flags
addr := c.String("addr")
token := c.String("token")
loglevel := c.String("log-level")
// Set the log level
setLogLevel(loglevel)
// Throw an error if invalid token provided
if len(strings.Split(token, ".")) != 3 {
return errors.New("invalid token provided")
}
// Start the proxy
p := proxy.New(addr, token)
return p.Start()
}
func actionServer(c *cli.Context) error {
// Get server config flags
port := c.String("port")
loglevel := c.String("log-level")
// Set the log level
setLogLevel(loglevel)
s := server.New(&server.Config{Port: port})
return s.Start()
}
func setLogLevel(loglevel string) {
switch loglevel {
case loglevelDebug:
logrus.SetLevel(logrus.DebugLevel)
case loglevelInfo:
logrus.SetLevel(logrus.InfoLevel)
case logLevelError:
logrus.SetLevel(logrus.ErrorLevel)
default:
logrus.Errorf("Invalid log level (%s) provided", loglevel)
logrus.Infoln("Defaulting to `info` level")
logrus.SetLevel(logrus.InfoLevel)
}
}
func actionStartCode(c *cli.Context) error {
envID := c.String("env")
service, loginResp, err := cmd.CodeStart(envID)
if err != nil {
return err
}
actionCodeStruct := &model.ActionCode{
Service: service,
IsDeploy: false,
}
if err := cmd.RunDockerFile(actionCodeStruct, loginResp); err != nil {
return err
}
return nil
}
func actionBuildCode(c *cli.Context) error {
envID := c.String("env")
service, loginResp, err := cmd.CodeStart(envID)
if err != nil {
return err
}
actionCodeStruct := &model.ActionCode{
Service: service,
IsDeploy: true,
}
if err := cmd.RunDockerFile(actionCodeStruct, loginResp); err != nil {
return err
}
return nil
}
func actionLogin(c *cli.Context) error {
userName := c.String("username")
key := c.String("key")
local := c.Bool("local")
tempurl := c.String("url")
url := "url1"
if local {
url = "ur2"
}
if tempurl != "default url" {
url = tempurl
}
if err := cmd.LoginStart(userName, key, url, local); err != nil {
return err
}
return nil
}