Skip to content

Commit 5c9e602

Browse files
committed
Merge branch 'v0.10.0' into ee-v0.10.0
2 parents 5aefde9 + 0f466c4 commit 5c9e602

File tree

4 files changed

+84
-53
lines changed

4 files changed

+84
-53
lines changed

Diff for: Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ COPY space-cloud .
99
RUN set -ex \
1010
&& apk add --no-cache ca-certificates wget \
1111
&& chmod +x space-cloud
12-
1312
ENV PROD=false
1413
ENV PATH="/space-cloud:${PATH}"
1514

1615
# ports for the http and https servers
17-
EXPOSE 4242 4244
18-
EXPOSE 4343 4245
16+
EXPOSE 4122 4124
17+
EXPOSE 4126 4128
1918

2019
# ports for nats
2120
EXPOSE 4222 4248

Diff for: main.go

+14-33
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,6 @@ import (
1313
)
1414

1515
var essentialFlags = []cli.Flag{
16-
cli.StringFlag{
17-
Name: "port",
18-
Value: "8080",
19-
Usage: "Start HTTP server on port `PORT`",
20-
},
21-
cli.StringFlag{
22-
Name: "grpc-port",
23-
Value: "8081",
24-
Usage: "Start grpc on port `GRPC_PORT`",
25-
},
26-
cli.IntFlag{
27-
Name: "nats-port",
28-
Value: 4222,
29-
Usage: "Start nats on port `NATS_PORT`",
30-
},
31-
cli.IntFlag{
32-
Name: "cluster-port",
33-
Value: 4248,
34-
Usage: "Start nats on port `NATS_PORT`",
35-
},
3616
cli.StringFlag{
3717
Name: "config",
3818
Value: "config.yaml",
@@ -112,11 +92,7 @@ func main() {
11292

11393
func actionRun(c *cli.Context) error {
11494
// Load cli flags
115-
port := c.String("port")
116-
grpcPort := c.String("grpc-port")
11795
configPath := c.String("config")
118-
natsPort := c.Int("nats-port")
119-
clusterPort := c.Int("cluster-port")
12096
isProd := c.Bool("prod")
12197
disableMetrics := c.Bool("disable-metrics")
12298
disableNats := c.Bool("disable-nats")
@@ -131,13 +107,6 @@ func actionRun(c *cli.Context) error {
131107
// Project and env cannot be changed once space cloud has started
132108
s := server.New(isProd)
133109

134-
if !disableNats {
135-
err := s.RunNatsServer(seeds, natsPort, clusterPort)
136-
if err != nil {
137-
return err
138-
}
139-
}
140-
141110
// Load the configFile from path if provided
142111
conf, err := config.LoadConfigFromFile(configPath)
143112
if err != nil {
@@ -173,7 +142,16 @@ func actionRun(c *cli.Context) error {
173142
}
174143

175144
s.Routes(profiler, staticPath)
176-
return s.Start(port, grpcPort, seeds)
145+
146+
// Start nats if not disabled
147+
if !disableNats {
148+
err := s.RunNatsServer(seeds, utils.PortNatsServer, utils.PortNatsCluster)
149+
if err != nil {
150+
return err
151+
}
152+
}
153+
154+
return s.Start(seeds)
177155
}
178156

179157
func actionInit(*cli.Context) error {
@@ -184,18 +162,21 @@ func initMissionContol(version string) (string, error) {
184162
homeDir := utils.UserHomeDir()
185163
uiPath := homeDir + "/.space-cloud/mission-control-v" + version
186164
if _, err := os.Stat(uiPath); os.IsNotExist(err) {
165+
fmt.Println("Could not find mission control")
187166
if _, err := os.Stat(homeDir + "/space-cloud"); os.IsNotExist(err) {
188167
os.Mkdir(homeDir+"/.space-cloud", os.ModePerm)
189168
}
190-
fmt.Println("Downloading Mission Control UI...")
169+
fmt.Println("Downloading...")
191170
err := utils.DownloadFileFromURL("https://spaceuptech.com/downloads/mission-control/mission-control-v"+version+".zip", uiPath+".zip")
192171
if err != nil {
193172
return "", err
194173
}
174+
fmt.Println("Extracting...")
195175
err = utils.Unzip(uiPath+".zip", uiPath)
196176
if err != nil {
197177
return "", err
198178
}
179+
fmt.Println("Done...")
199180
err = os.Remove(uiPath + ".zip")
200181
if err != nil {
201182
return "", err

Diff for: utils/constants.go

+26
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,29 @@ const (
190190

191191
// TypeRegisterRequest is the space cloud register request
192192
const TypeRegisterRequest string = "register"
193+
194+
const (
195+
// PortHTTP is the port used for the http server
196+
PortHTTP string = "4122"
197+
198+
// PortGRPC is the port used for the grpc server
199+
PortGRPC string = "4124"
200+
201+
// PortHTTPSecure is the port used for the http server with tls
202+
PortHTTPSecure string = "4126"
203+
204+
// PortGRPCSecure is the port used for the grpc server with tls
205+
PortGRPCSecure string = "4128"
206+
207+
// PortNatsServer is the port used for nats
208+
PortNatsServer int = 4222
209+
210+
// PortNatsCluster is the port used by nats for clustering
211+
PortNatsCluster int = 4248
212+
213+
// PortGossip is used for the membership protocol
214+
PortGossip string = "4232"
215+
216+
// PortRaft is used internally by raft
217+
PortRaft string = "4234"
218+
)

Diff for: utils/server/server.go

+42-17
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ func New(isProd bool) *Server {
5555
}
5656

5757
// Start begins the server operations
58-
func (s *Server) Start(port, grpcPort, seeds string) error {
59-
60-
go s.initGRPCServer(grpcPort)
58+
func (s *Server) Start(seeds string) error {
59+
// Start gRPC server in a separate goroutine
60+
go s.initGRPCServer()
6161

6262
// Start the sync manager
6363
if seeds == "" {
6464
seeds = "127.0.0.1"
6565
}
6666
array := strings.Split(seeds, ",")
67-
if err := s.syncMan.Start(s.nodeID, s.configFilePath, "4232", "4234", array); err != nil {
67+
if err := s.syncMan.Start(s.nodeID, s.configFilePath, utils.PortGossip, utils.PortRaft, array); err != nil {
6868
return err
6969
}
7070

@@ -81,14 +81,24 @@ func (s *Server) Start(port, grpcPort, seeds string) error {
8181

8282
handler := corsObj.Handler(s.router)
8383

84-
fmt.Println("Starting HTTP Server on port: " + port)
84+
fmt.Println("Starting http server on port: " + utils.PortHTTP)
8585

86-
fmt.Println("Space Cloud is running on the specified ports :D")
8786
if s.ssl != nil && s.ssl.Enabled {
88-
return http.ListenAndServeTLS(":"+port, s.ssl.Crt, s.ssl.Key, handler)
87+
fmt.Println("Starting https server on port: " + utils.PortHTTPSecure)
88+
go func() {
89+
90+
if err := http.ListenAndServeTLS(":"+utils.PortHTTPSecure, s.ssl.Crt, s.ssl.Key, handler); err != nil {
91+
fmt.Println("Error starting https server:", err)
92+
}
93+
}()
8994
}
9095

91-
return http.ListenAndServe(":"+port, handler)
96+
fmt.Println()
97+
fmt.Println("\t Hosting mission control on http://localhost:" + utils.PortHTTP + "/mission-control/")
98+
fmt.Println()
99+
100+
fmt.Println("Space cloud is running on the specified ports :D")
101+
return http.ListenAndServe(":"+utils.PortHTTP, handler)
92102
}
93103

94104
// SetConfig sets the config
@@ -99,27 +109,42 @@ func (s *Server) SetConfig(c *config.Config) {
99109
s.deploy.SetConfig(&c.Deploy)
100110
}
101111

102-
func (s *Server) initGRPCServer(port string) {
103-
lis, err := net.Listen("tcp", ":"+port)
104-
if err != nil {
105-
log.Fatal("Failed to listen:", err)
106-
}
112+
func (s *Server) initGRPCServer() {
107113

108-
options := []grpc.ServerOption{}
109114
if s.ssl != nil && s.ssl.Enabled {
115+
lis, err := net.Listen("tcp", ":"+utils.PortGRPCSecure)
116+
if err != nil {
117+
log.Fatal("Failed to listen:", err)
118+
}
110119
creds, err := credentials.NewServerTLSFromFile(s.ssl.Crt, s.ssl.Key)
111120
if err != nil {
112121
log.Fatalln("Error: ", err)
113122
}
114-
options = append(options, grpc.Creds(creds))
123+
options := []grpc.ServerOption{grpc.Creds(creds)}
124+
125+
grpcServer := grpc.NewServer(options...)
126+
proto.RegisterSpaceCloudServer(grpcServer, s)
127+
128+
fmt.Println("Starting grpc secure server on port: " + utils.PortGRPCSecure)
129+
go func() {
130+
if err := grpcServer.Serve(lis); err != nil {
131+
log.Fatal("Error starting grpc secure server:", err)
132+
}
133+
}()
134+
}
135+
136+
lis, err := net.Listen("tcp", ":"+utils.PortGRPC)
137+
if err != nil {
138+
log.Fatal("Failed to listen:", err)
115139
}
116140

141+
options := []grpc.ServerOption{}
117142
grpcServer := grpc.NewServer(options...)
118143
proto.RegisterSpaceCloudServer(grpcServer, s)
119144

120-
fmt.Println("Starting gRPC Server on port: " + port)
145+
fmt.Println("Starting grpc server on port: " + utils.PortGRPC)
121146
if err := grpcServer.Serve(lis); err != nil {
122-
log.Fatal("failed to serve:", err)
147+
log.Fatal("Error starting grpc server:", err)
123148
}
124149
}
125150

0 commit comments

Comments
 (0)