1
This commit is contained in:
54
.cnb.yml
54
.cnb.yml
@@ -1,11 +1,61 @@
|
||||
main:
|
||||
push:
|
||||
- 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}
|
||||
password: ${GIT_ACCESS_TOKEN}
|
||||
|
||||
# ========== 生成版本号 ==========
|
||||
- name: set version
|
||||
image: golang:1.25
|
||||
commands:
|
||||
- VERSION="v$(git rev-parse --short=8 HEAD)"
|
||||
- echo "BUILD_VERSION=${VERSION}"
|
||||
|
||||
# ========== 编译Logic服务 ==========
|
||||
- name: build logic
|
||||
image: golang:1.25
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
GO111MODULE: on
|
||||
GOSUMDB: off
|
||||
commands:
|
||||
- mkdir -p build
|
||||
- BIN_NAME="logic_${BUILD_VERSION}"
|
||||
- go build -v -p=4 -trimpath -buildvcs=false -ldflags "-s -w -buildid= -extldflags '-static'" -o ./build/${BIN_NAME} ./logic
|
||||
- ls -lh ./build/
|
||||
|
||||
# ========== 拉取部署配置 ==========
|
||||
- name: fetch deploy config
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk add --no-cache curl jq
|
||||
- for i in 1 2 3; do curl -sSL --connect-timeout 10 --max-time 30 "https://你的JSON配置地址.com/deploy.json" -o /tmp/deploy-config.json && break || sleep 2; done
|
||||
- JSON_TYPE=$(jq -r 'type' /tmp/deploy-config.json 2>/dev/null || echo "invalid")
|
||||
- |
|
||||
if [ "$JSON_TYPE" = "array" ]; then
|
||||
REMOTE_HOSTS=$(jq -r '.[].loginaddr' /tmp/deploy-config.json | tr '\n' ',' | sed 's/,$//')
|
||||
REMOTE_USERS=$(jq -r '.[].user' /tmp/deploy-config.json | tr '\n' ',' | sed 's/,$//')
|
||||
REMOTE_PASSWORDS=$(jq -r '.[].password' /tmp/deploy-config.json | tr '\n' ',' | sed 's/,$//')
|
||||
elif [ "$JSON_TYPE" = "object" ]; then
|
||||
REMOTE_HOSTS=$(jq -r '.loginaddr' /tmp/deploy-config.json)
|
||||
REMOTE_USERS=$(jq -r '.user' /tmp/deploy-config.json)
|
||||
REMOTE_PASSWORDS=$(jq -r '.password' /tmp/deploy-config.json)
|
||||
fi
|
||||
|
||||
# ========== SCP推送产物到服务器 ==========
|
||||
- name: scp to servers
|
||||
image: appleboy/drone-scp:1.6.2
|
||||
settings:
|
||||
host: ${REMOTE_HOSTS}
|
||||
username: ${REMOTE_USERS}
|
||||
password: ${REMOTE_PASSWORDS}
|
||||
source: ./build/logic_${BUILD_VERSION}
|
||||
target: /opt/logic/
|
||||
strip_components: 1
|
||||
skip_verify: true
|
||||
Reference in New Issue
Block a user