Browse Source

添加服务端容器化

master
zhangjiyu 4 years ago
parent
commit
0a9e868509
  1. 7
      examples/zinx_client/main.go
  2. 22
      examples/zinx_server/Makefile
  3. 21
      examples/zinx_server/build.sh
  4. 8
      examples/zinx_server/dockerfile
  5. 1
      examples/zinx_server/version

7
examples/zinx_client/main.go

@ -2,10 +2,11 @@ package main
import (
"fmt"
"github.com/aceld/zinx/znet"
"io"
"net"
"time"
"github.com/aceld/zinx/znet"
)
/*
@ -15,7 +16,7 @@ func main() {
conn, err := net.Dial("tcp", "127.0.0.1:8999")
if err != nil {
fmt.Println("client start err, exit!")
fmt.Println("client start err, exit!", err)
return
}
@ -55,7 +56,7 @@ func main() {
return
}
fmt.Println("==> Test Router:[Ping] Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data))
// fmt.Println("==> Test Router:[Ping] Recv Msg: ID=", msg.Id ", len=", msg.DataLen, ", data=", string(msg.Data))
}
time.Sleep(1 * time.Second)

22
examples/zinx_server/Makefile

@ -0,0 +1,22 @@
PROJECT_NAME:=zinx_server
VERSION:=v1
.PHONY: image run build clean
build:
bash build.sh ${PROJECT_NAME}
image:
docker build -t ${PROJECT_NAME}:${VERSION} .
run:
docker run -itd \
-p 8999:8999 \
${PROJECT_NAME}:${VERSION}
clean:
rm -rf ${PROJECT_NAME}

21
examples/zinx_server/build.sh

@ -0,0 +1,21 @@
#!/bin/bash
set -e
APP_NAME=$1
APP_VERSION=v$(cat version)
BUILD_VERSION=$(git log -1 --oneline)
BUILD_TIME=$(date "+%FT%T%z")
GIT_REVISION=$(git rev-parse --short HEAD)
GIT_BRANCH=$(git name-rev --name-only HEAD)
GO_VERSION=$(go version)
go build -ldflags " \
-X 'main.AppName=${APP_NAME}' \
-X 'main.AppVersion=${APP_VERSION}' \
-X 'main.BuildVersion=${BUILD_VERSION//\'/_}' \
-X 'main.BuildTime=${BUILD_TIME}' \
-X 'main.GitRevision=${GIT_REVISION}' \
-X 'main.GitBranch=${GIT_BRANCH}' \
-X 'main.GoVersion=${GO_VERSION}' \
" -o $2 .

8
examples/zinx_server/dockerfile

@ -0,0 +1,8 @@
FROM centos:8
COPY zinx_server /zinx-server
COPY /conf/zinx.json /conf/zinx.json
WORKDIR /
EXPOSE 8999
ENTRYPOINT [ "/zinx-server" ]

1
examples/zinx_server/version

@ -0,0 +1 @@
v 1.0.0
Loading…
Cancel
Save