Files
bl/.cnb.yml
xinian b7e21a4038 1
2026-01-28 00:31:35 +08:00

143 lines
5.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

main:
push:
- runner:
# 指定在 amd64 架构构建节点上执行
tags: cnb:arch:amd64
cpus: 1
- stages:
# ========== 同步到GitHub ==========
- name: sync to github
image: tencentcom/git-sync
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
settings:
target_url: https://github.com/72wo/blazing.git
auth_type: https
username: ${GIT_USERNAME}
password: ${GIT_ACCESS_TOKEN}
# ========== 生成版本号作为前置步骤 ==========
- name: set version
image: golang:1.25
commands:
- VERSION="v$(git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")"
- mkdir -p .build-info
- echo "BUILD_VERSION=${VERSION}" >> .build-info/.env
- echo "构建版本号:${VERSION}"
# ========== 缓存Go依赖 ==========
- name: cache go modules
image: meltwater/drone-cache:latest
settings:
restore: true
mount:
- /go/pkg/mod
- /root/.cache/go-build
cache_key: '{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ checksum "go.mod" }}'
# ========== 编译Logic服务 ==========
- name: build logic
image: golang:1.25
environment:
CGO_ENABLED: 0
GO111MODULE: on
GOSUMDB: off
commands:
- VERSION="v$(git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")"
- BUILD_VERSION="${VERSION}"
- mkdir -p build
- BIN_NAME="logic_${BUILD_VERSION}"
- go mod download -x
- go build -v -p=4 -trimpath -buildvcs=false -ldflags "-s -w -buildid= -extldflags '-static'" -o ./build/${BIN_NAME} ./logic
- ls -lh ./build/
- echo "BUILD_VERSION=${BUILD_VERSION}" >> .build-info/.env
- cat .build-info/.env
# ========== 编译Login服务 ==========
- name: build login
image: golang:1.25
environment:
CGO_ENABLED: 0
GO111MODULE: on
GOSUMDB: off
commands:
- VERSION="v$(git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")"
- BUILD_VERSION="${VERSION}"
- cd login
- mkdir -p build
- BIN_NAME="login_${BUILD_VERSION:-unknown}"
- go mod download -x
- go build -v -p=4 -trimpath -buildvcs=false -ldflags "-s -w -buildid= -extldflags '-static'" -o ./build/${BIN_NAME} .
- ls -lh ./build/
- mv ./build/${BIN_NAME} ../build/
- cd ..
- ls -lh ./build/
# ========== 重建缓存 ==========
- name: rebuild cache
image: meltwater/drone-cache:latest
settings:
rebuild: true
mount:
- /go/pkg/mod
- /root/.cache/go-build
cache_key: '{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ checksum "go.mod" }}'
# ========== SCP推送Login和Logic到指定服务器 ==========
- name: deploy to login server
image: appleboy/drone-scp:1.6.2
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
settings:
host: ${LOGIN_SERVER_HOST}
username: ${LOGIN_SERVER_USER}
password: ${LOGIN_SERVER_PASSWORD}
port: ${LOGIN_SERVER_PORT}
source:
- ./build/login_*
- ./build/logic_*
target: /opt/
strip_components: 2
# ========== SSH启动Login服务并上传Logic到Public ==========
- name: start login and move logic
image: appleboy/drone-ssh:1.6.2
imports: https://cnb.cool/blzing/key/-/blob/main/githubkey.yml
settings:
host: ${LOGIN_SERVER_HOST}
username: ${LOGIN_SERVER_USER}
password: ${LOGIN_SERVER_PASSWORD}
port: ${LOGIN_SERVER_PORT}
script:
- cd /opt/login
- |
# 获取最新的login二进制文件
BIN_NAME=$(ls -t login_v* | head -1)
if [ -z "$BIN_NAME" ]; then
echo "❌ 未找到可执行的login文件"
exit 1
fi
- echo "📦 启动Login服务 | Binary: ${BIN_NAME}"
- |
# 停止旧的screen会话
session_name="login"
session=$(screen -ls | grep -o "[0-9]*\.${session_name}")
if [[ ! -z "$session" ]]; then
screen -X -S "$session_name" stuff "^C"
sleep 2
screen -X -S "$session_name" quit
echo "Info: Stopped login app."
fi
- sleep 1
- |
# 启动新进程
screen -dmS ${session_name} ./${BIN_NAME}
- echo "✅ Login服务启动成功 | Screen: ${session_name}"
- |
# 移动logic产物到public目录
LOGIC_BIN=$(ls -t /opt/logic_v* | head -1)
if [ -n "$LOGIC_BIN" ]; then
mkdir -p /opt/login/public
mv ${LOGIC_BIN} /opt/login/public/
echo "✅ Logic产物已移动到 /opt/login/public/ | 文件: $(basename ${LOGIC_BIN})"
else
echo "⚠️ 未找到Logic产物"
fi