添加脚本
This commit is contained in:
parent
1e02964ec5
commit
6e6b1fa5d2
29
build.sh
29
build.sh
@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get Git commit hash
|
||||
GIT_COMMIT_HASH=$(git rev-parse HEAD)
|
||||
|
||||
# Get Git branch name
|
||||
GIT_BRANCH=$(git branch --show-current)
|
||||
|
||||
# Get build date in YYYYMMDDHHMMSS format
|
||||
BUILD_DATE=$(date +"%Y%m%d%H%M%S")
|
||||
|
||||
# Output linker flags
|
||||
echo "-X main.GitCommitHash=$GIT_COMMIT_HASH"
|
||||
echo "-X main.GitBranch=$GIT_BRANCH"
|
||||
echo "-X main.BuildDate=$BUILD_DATE"
|
||||
|
||||
# Set Go environment variables
|
||||
export GOARCH=amd64
|
||||
export GOOS=linux
|
||||
export CGO_ENABLED=0
|
||||
|
||||
cd server
|
||||
# Build truco
|
||||
cd ../server/gate
|
||||
go build -ldflags "-X main.GitBranch=$GIT_BRANCH -X main.GitCommit=$GIT_COMMIT_HASH -X main.BuildDate=$BUILD_DATE" -o ../../bin/gate
|
||||
|
||||
# Build cacheta
|
||||
#cd ../cacheta
|
||||
#go build -ldflags "-X main.GitBranch=$GIT_BRANCH -X main.GitCommit=$GIT_COMMIT_HASH -X main.BuildDate=$BUILD_DATE" -o ../../bin/cacheta
|
1
go.mod
1
go.mod
@ -28,6 +28,7 @@ require (
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/klauspost/compress v1.18.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -40,6 +40,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
|
84
server/build.sh
Normal file
84
server/build.sh
Normal file
@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 定义文件名、用户名和远程路径
|
||||
FILE=$1
|
||||
|
||||
# Get Git commit hash
|
||||
GIT_COMMIT_HASH=$(git rev-parse HEAD)
|
||||
|
||||
# Get Git branch name
|
||||
GIT_BRANCH=$(git branch --show-current)
|
||||
|
||||
# Get build date in YYYYMMDDHHMMSS format
|
||||
BUILD_DATE=$(date +"%Y%m%d%H%M%S")
|
||||
|
||||
# Output linker flags
|
||||
echo "-X main.GitCommitHash=$GIT_COMMIT_HASH"
|
||||
echo "-X main.GitBranch=$GIT_BRANCH"
|
||||
echo "-X main.BuildDate=$BUILD_DATE"
|
||||
|
||||
# Set Go environment variables
|
||||
export GOARCH=amd64
|
||||
export GOOS=linux
|
||||
export CGO_ENABLED=0
|
||||
|
||||
#sh build.sh chat
|
||||
# 检查是否提供了两个参数
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 {login}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查并创建 bin 目录
|
||||
if [ ! -d "bin" ]; then
|
||||
mkdir -p bin
|
||||
fi
|
||||
|
||||
#构建项目的名字
|
||||
BUILD_DIR=$FILE
|
||||
|
||||
# 删除旧的编译文件
|
||||
rm -f bin/$FILE
|
||||
|
||||
go build -ldflags "-X main.GitBranch=$GIT_BRANCH -X main.GitCommit=$GIT_COMMIT_HASH -X main.BuildDate=$BUILD_DATE" -o bin/$FILE $BUILD_DIR/main.go
|
||||
|
||||
# 检查编译是否成功
|
||||
if [ ! -f "bin/$FILE" ]; then
|
||||
echo "build failed."
|
||||
exit 1
|
||||
else
|
||||
echo "build success."
|
||||
fi
|
||||
|
||||
|
||||
Host="114.132.124.145"
|
||||
Username="ubuntu"
|
||||
Password="@qq20160101"
|
||||
|
||||
RemotePath="/home/ubuntu/game"
|
||||
REMOTE_SCRIPT_PATH="/home/ubuntu/game"
|
||||
LocalFile=bin/$FILE
|
||||
|
||||
# 传输文件到远程主机
|
||||
pscp -batch -pw "$Password" "$LocalFile" "$Username@$Host:$RemotePath"
|
||||
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "文件上传成功"
|
||||
else
|
||||
echo "文件上传失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 远程执行脚本
|
||||
plink -ssh -batch -pw "$Password" "$Username@$Host" "bash $RemotePath"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "远程脚本执行成功"
|
||||
else
|
||||
echo "远程脚本执行失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
94
test/build.sh
Normal file
94
test/build.sh
Normal file
@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 定义文件名、用户名和远程路径
|
||||
FILE=$1
|
||||
|
||||
# Get Git commit hash
|
||||
GIT_COMMIT_HASH=$(git rev-parse HEAD)
|
||||
|
||||
# Get Git branch name
|
||||
GIT_BRANCH=$(git branch --show-current)
|
||||
|
||||
# Get build date in YYYYMMDDHHMMSS format
|
||||
BUILD_DATE=$(date +"%Y%m%d%H%M%S")
|
||||
|
||||
# Output linker flags
|
||||
echo "-X main.GitCommitHash=$GIT_COMMIT_HASH"
|
||||
echo "-X main.GitBranch=$GIT_BRANCH"
|
||||
echo "-X main.BuildDate=$BUILD_DATE"
|
||||
|
||||
# Set Go environment variables
|
||||
export GOARCH=amd64
|
||||
export GOOS=linux
|
||||
export CGO_ENABLED=0
|
||||
|
||||
#sh build.sh chat
|
||||
# 检查是否提供了两个参数
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 {login}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查并创建 bin 目录
|
||||
if [ ! -d "bin" ]; then
|
||||
mkdir -p bin
|
||||
fi
|
||||
|
||||
#构建项目的名字
|
||||
BUILD_DIR=$FILE
|
||||
|
||||
# 删除旧的编译文件
|
||||
rm -f bin/$FILE
|
||||
|
||||
go build -ldflags "-X main.GitBranch=$GIT_BRANCH -X main.GitCommit=$GIT_COMMIT_HASH -X main.BuildDate=$BUILD_DATE" -o bin/$FILE $BUILD_DIR/main.go
|
||||
|
||||
# 检查编译是否成功
|
||||
if [ ! -f "bin/$FILE" ]; then
|
||||
echo "build failed."
|
||||
exit 1
|
||||
else
|
||||
echo "build success."
|
||||
fi
|
||||
|
||||
|
||||
Host="114.132.124.145"
|
||||
Username="ubuntu"
|
||||
Password="qq20160101"
|
||||
|
||||
RemotePath="/home/ubuntu/game"
|
||||
REMOTE_SCRIPT_PATH="/home/ubuntu/game"
|
||||
|
||||
# 传输文件到远程主机
|
||||
# 通过expect自动化密码输入
|
||||
expect -c "
|
||||
spawn scp -o StrictHostKeyChecking=no \"bin/$FILE\" \"$Username@$Host:$RemotePath\"
|
||||
expect \"password:\"
|
||||
send \"$Password\r\"
|
||||
expect eof
|
||||
"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "文件上传成功"
|
||||
else
|
||||
echo "文件上传失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 传输文件到远程主机
|
||||
# 通过expect自动化密码输入
|
||||
expect -c "
|
||||
spawn ssh -o StrictHostKeyChecking=no $Username@$Host \"bash $RemotePath\"
|
||||
expect \"password:\"
|
||||
send \"$Password\r\"
|
||||
expect eof
|
||||
"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "远程脚本执行成功"
|
||||
else
|
||||
echo "远程脚本执行失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user