Skip to content

Commit 771a6d5

Browse files
author
daniel840829
committed
add standalone server setting
1 parent 72df1a1 commit 771a6d5

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

Dockerfile

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
#源镜像
21
FROM golang:latest as builder
3-
#作者
42
MAINTAINER daniel840829 "s102033114@gapp.nthu.edu.tw"
5-
#设置工作目录
63
COPY . $GOPATH/src/github.com/daniel840829/gameServer
74
WORKDIR $GOPATH/src/github.com/daniel840829/gameServer
8-
#将服务器的go工程代码加入到docker容器中
9-
105
RUN set -x && go get github.com/golang/dep/cmd/dep && dep ensure -v
11-
126
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /gameServer
13-
14-
157
CMD ["/gameServer"]
16-
17-
#暴露端口
188
EXPOSE 3000 8080 50051
19-
# 最终运行docker的命令
20-
# ENTRYPOINT ["/go/bin/gameServer"]
21-
# ---stage 2
22-
FROM scratch
239

10+
FROM scratch
2411
COPY --from=builder /gameServer .
25-
26-
2712
EXPOSE 3000 8080 50051
28-
2913
CMD ["./gameServer"]

agent/ClientToAgent.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818

1919
"time"
2020

21+
"os"
22+
2123
log "github.com/sirupsen/logrus"
2224
"golang.org/x/net/context"
2325
"google.golang.org/grpc/codes"
@@ -71,8 +73,12 @@ type Agent struct {
7173
GameServer AgentToGameClient
7274
}
7375

74-
func (a *Agent) Init() {
75-
session.ClusterManager.KubeClientSet()
76+
func (a *Agent) Init(ip, agentToGamePort, clientToGamePort string) {
77+
if os.Getenv("DONT_USE_KUBE") == "true" {
78+
session.RoomManager.ConnectGameServer(ip, clientToGamePort, agentToGamePort, "0")
79+
} else {
80+
session.ClusterManager.KubeClientSet()
81+
}
7682
}
7783

7884
func (a *Agent) AquireSessionKey(c context.Context, e *Empty) (*SessionKey, error) {

agent/session/kubermanager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func cleanUp() {
153153
}
154154

155155
func init() {
156+
if os.Getenv("DONT_USE_KUBE") == "true" {
157+
return
158+
}
156159
ClusterManager = &clusterManager{
157160
pods: make(map[string]*v1.Pod),
158161
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func RunAgent() {
102102
s := grpc.NewServer()
103103
msg.RegisterClientToAgentServer(s, agentRpc)
104104
fmt.Println("AgentServer Listen on " + *AgentPort)
105-
agentRpc.Init()
105+
agentRpc.Init("127.0.0.1", *AgentToGamePort, *ClientToGamePort)
106106
s.Serve(listen)
107107
}
108108

setupEnv.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Set up these env var to connect mongodb
2+
export MOG_ADDR=0.0.0.0:27071
3+
export MGO_USER=username
4+
export MGO_PASS=1234
5+
export DONT_USE_KUBE=false

0 commit comments

Comments
 (0)