1
This commit is contained in:
76
.cnb.yml
76
.cnb.yml
@@ -8,6 +8,7 @@ main:
|
|||||||
# ========== 同步到GitHub ==========
|
# ========== 同步到GitHub ==========
|
||||||
- name: sync to github
|
- name: sync to github
|
||||||
image: tencentcom/git-sync
|
image: tencentcom/git-sync
|
||||||
|
cpus: 1
|
||||||
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
|
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
|
||||||
settings:
|
settings:
|
||||||
target_url: https://github.com/72wo/blazing.git
|
target_url: https://github.com/72wo/blazing.git
|
||||||
@@ -17,74 +18,92 @@ main:
|
|||||||
|
|
||||||
# ========== 生成版本号(作为前置步骤) ==========
|
# ========== 生成版本号(作为前置步骤) ==========
|
||||||
- name: set version
|
- name: set version
|
||||||
image: golang:1.25
|
image: golang:1.23
|
||||||
|
cpus: 1
|
||||||
commands:
|
commands:
|
||||||
- VERSION="v$(git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")"
|
- VERSION="v$(git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")"
|
||||||
- mkdir -p .build-info
|
- mkdir -p .build-info
|
||||||
- echo "BUILD_VERSION=${VERSION}" >> .build-info/.env
|
- echo "BUILD_VERSION=${VERSION}" >> .build-info/.env
|
||||||
- echo "构建版本号:${VERSION}"
|
- echo "构建版本号:${VERSION}"
|
||||||
|
depends_on:
|
||||||
|
- sync to github
|
||||||
|
|
||||||
# ========== 缓存Go依赖 ==========
|
# ========== 缓存Go依赖 ==========
|
||||||
- name: cache go modules
|
- name: cache go modules
|
||||||
image: meltwater/drone-cache:latest
|
image: meltwater/drone-cache:latest
|
||||||
|
cpus: 1
|
||||||
settings:
|
settings:
|
||||||
restore: true
|
restore: true
|
||||||
mount:
|
mount:
|
||||||
- /go/pkg/mod
|
- /go/pkg/mod
|
||||||
- /root/.cache/go-build
|
- /root/.cache/go-build
|
||||||
cache_key: '{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ checksum "go.mod" }}'
|
cache_key: '{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ checksum "go.mod" }}-{{ checksum "login/go.mod" }}'
|
||||||
|
depends_on:
|
||||||
|
- sync to github
|
||||||
|
|
||||||
# ========== 编译Logic服务 ==========
|
# ========== 编译Logic服务 ==========
|
||||||
- name: build logic
|
- name: build logic
|
||||||
image: golang:1.25
|
image: golang:1.23
|
||||||
|
cpus: 1
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
GO111MODULE: on
|
||||||
GOSUMDB: off
|
GOSUMDB: off
|
||||||
commands:
|
commands:
|
||||||
- VERSION="v$(git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")"
|
- source .build-info/.env && BUILD_VERSION="${BUILD_VERSION}"
|
||||||
- BUILD_VERSION="${VERSION}"
|
|
||||||
- mkdir -p build
|
- mkdir -p build
|
||||||
- BIN_NAME="logic_${BUILD_VERSION}"
|
- BIN_NAME="logic_${BUILD_VERSION}"
|
||||||
- go mod download -x
|
- go mod download -x
|
||||||
- go build -v -p=4 -trimpath -buildvcs=false -ldflags "-s -w -buildid= -extldflags '-static'" -o ./build/${BIN_NAME} ./logic
|
- go build -v -p=1 -trimpath -buildvcs=false -ldflags "-s -w -buildid= -extldflags '-static'" -o ./build/${BIN_NAME} ./logic
|
||||||
|
- chmod +x ./build/${BIN_NAME}
|
||||||
- ls -lh ./build/
|
- ls -lh ./build/
|
||||||
- echo "BUILD_VERSION=${BUILD_VERSION}" >> .build-info/.env
|
- file ./build/${BIN_NAME}
|
||||||
- cat .build-info/.env
|
depends_on:
|
||||||
|
- cache go modules
|
||||||
|
- set version
|
||||||
|
|
||||||
# ========== 编译Login服务 ==========
|
# ========== 编译Login服务 ==========
|
||||||
- name: build login
|
- name: build login
|
||||||
image: golang:1.25
|
image: golang:1.23
|
||||||
|
cpus: 1
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
GO111MODULE: on
|
||||||
GOSUMDB: off
|
GOSUMDB: off
|
||||||
commands:
|
commands:
|
||||||
- VERSION="v$(git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")"
|
- source .build-info/.env && BUILD_VERSION="${BUILD_VERSION}"
|
||||||
- BUILD_VERSION="${VERSION}"
|
|
||||||
- cd login
|
- cd login
|
||||||
- mkdir -p build
|
- mkdir -p build
|
||||||
- BIN_NAME="login_${BUILD_VERSION:-unknown}"
|
- BIN_NAME="login_${BUILD_VERSION}"
|
||||||
- go mod download -x
|
- go mod download -x
|
||||||
- go build -v -p=4 -trimpath -buildvcs=false -ldflags "-s -w -buildid= -extldflags '-static'" -o ./build/${BIN_NAME} .
|
- go build -v -p=1 -trimpath -buildvcs=false -ldflags "-s -w -buildid= -extldflags '-static'" -o ./build/${BIN_NAME} .
|
||||||
|
- chmod +x ./build/${BIN_NAME}
|
||||||
- ls -lh ./build/
|
- ls -lh ./build/
|
||||||
- mv ./build/${BIN_NAME} ../build/
|
- mv ./build/${BIN_NAME} ../build/
|
||||||
- cd ..
|
- cd ..
|
||||||
- ls -lh ./build/
|
- ls -lh ./build/
|
||||||
|
depends_on:
|
||||||
|
- cache go modules
|
||||||
|
- set version
|
||||||
|
|
||||||
# ========== 重建缓存 ==========
|
# ========== 重建缓存 ==========
|
||||||
- name: rebuild cache
|
- name: rebuild cache
|
||||||
image: meltwater/drone-cache:latest
|
image: meltwater/drone-cache:latest
|
||||||
|
cpus: 1
|
||||||
settings:
|
settings:
|
||||||
rebuild: true
|
rebuild: true
|
||||||
mount:
|
mount:
|
||||||
- /go/pkg/mod
|
- /go/pkg/mod
|
||||||
- /root/.cache/go-build
|
- /root/.cache/go-build
|
||||||
cache_key: '{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ checksum "go.mod" }}'
|
cache_key: '{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ checksum "go.mod" }}-{{ checksum "login/go.mod" }}'
|
||||||
|
depends_on:
|
||||||
|
- build logic
|
||||||
|
- build login
|
||||||
|
|
||||||
# ========== SCP推送Login和Logic到指定服务器 ==========
|
# ========== SCP推送Login和Logic到指定服务器 ==========
|
||||||
- name: deploy to login server
|
- name: deploy to login server
|
||||||
image: appleboy/drone-scp:1.6.2
|
image: appleboy/drone-scp:1.6.2
|
||||||
|
cpus: 1
|
||||||
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
|
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
|
||||||
settings:
|
settings:
|
||||||
host: ${LOGIN_SERVER_HOST}
|
host: ${LOGIN_SERVER_HOST}
|
||||||
@@ -94,12 +113,15 @@ main:
|
|||||||
source:
|
source:
|
||||||
- ./build/login_*
|
- ./build/login_*
|
||||||
- ./build/logic_*
|
- ./build/logic_*
|
||||||
target: /opt/
|
target: /opt/login/
|
||||||
strip_components: 2
|
strip_components: 1
|
||||||
|
depends_on:
|
||||||
|
- rebuild cache
|
||||||
|
|
||||||
# ========== SSH启动Login服务并上传Logic到Public ==========
|
# ========== SSH启动Login服务并上传Logic到Public ==========
|
||||||
- name: start login and move logic
|
- name: start login and move logic
|
||||||
image: appleboy/drone-ssh:1.6.2
|
image: appleboy/drone-ssh:1.6.2
|
||||||
|
cpus: 1
|
||||||
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
|
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
|
||||||
settings:
|
settings:
|
||||||
host: ${LOGIN_SERVER_HOST}
|
host: ${LOGIN_SERVER_HOST}
|
||||||
@@ -110,7 +132,7 @@ main:
|
|||||||
- cd /opt/login
|
- cd /opt/login
|
||||||
- |
|
- |
|
||||||
# 获取最新的login二进制文件
|
# 获取最新的login二进制文件
|
||||||
BIN_NAME=$(ls -t login_v* | head -1)
|
BIN_NAME=$(ls -t login_v* 2>/dev/null | head -1)
|
||||||
if [ -z "$BIN_NAME" ]; then
|
if [ -z "$BIN_NAME" ]; then
|
||||||
echo "❌ 未找到可执行的login文件"
|
echo "❌ 未找到可执行的login文件"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -119,11 +141,10 @@ main:
|
|||||||
- |
|
- |
|
||||||
# 停止旧的screen会话
|
# 停止旧的screen会话
|
||||||
session_name="login"
|
session_name="login"
|
||||||
session=$(screen -ls | grep -o "[0-9]*\.${session_name}")
|
session=$(screen -ls 2>/dev/null | grep -o "[0-9]*\.${session_name}" || true)
|
||||||
if [[ ! -z "$session" ]]; then
|
if [[ ! -z "$session" ]]; then
|
||||||
screen -X -S "$session_name" stuff "^C"
|
screen -X -S "$session_name" quit 2>/dev/null || true
|
||||||
sleep 2
|
sleep 1
|
||||||
screen -X -S "$session_name" quit
|
|
||||||
echo "Info: Stopped login app."
|
echo "Info: Stopped login app."
|
||||||
fi
|
fi
|
||||||
- sleep 1
|
- sleep 1
|
||||||
@@ -131,9 +152,18 @@ main:
|
|||||||
# 启动新进程
|
# 启动新进程
|
||||||
screen -dmS ${session_name} ./${BIN_NAME}
|
screen -dmS ${session_name} ./${BIN_NAME}
|
||||||
- echo "✅ Login服务启动成功 | Screen: ${session_name}"
|
- echo "✅ Login服务启动成功 | Screen: ${session_name}"
|
||||||
|
- |
|
||||||
|
# 等待服务启动并进行健康检查
|
||||||
|
sleep 3
|
||||||
|
if screen -list 2>/dev/null | grep -q "${session_name}"; then
|
||||||
|
echo "✅ 服务健康检查通过 | Screen: ${session_name}"
|
||||||
|
else
|
||||||
|
echo "❌ 服务健康检查失败 | Screen: ${session_name} 不存在"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
- |
|
- |
|
||||||
# 移动logic产物到public目录
|
# 移动logic产物到public目录
|
||||||
LOGIC_BIN=$(ls -t /opt/logic_v* | head -1)
|
LOGIC_BIN=$(ls -t logic_v* 2>/dev/null | head -1)
|
||||||
if [ -n "$LOGIC_BIN" ]; then
|
if [ -n "$LOGIC_BIN" ]; then
|
||||||
mkdir -p /opt/login/public
|
mkdir -p /opt/login/public
|
||||||
mv ${LOGIC_BIN} /opt/login/public/
|
mv ${LOGIC_BIN} /opt/login/public/
|
||||||
@@ -141,3 +171,5 @@ main:
|
|||||||
else
|
else
|
||||||
echo "⚠️ 未找到Logic产物"
|
echo "⚠️ 未找到Logic产物"
|
||||||
fi
|
fi
|
||||||
|
depends_on:
|
||||||
|
- deploy to login server
|
||||||
Reference in New Issue
Block a user