Files
lingji-work-fe/.drone.yml
lidognbin f095e85f0b ci(drone): 优化构建流程和环境配置
- 更新 Node.js 镜像版本,使用22-bullseye-slim
- 添加 pnpm 配置,使用国内镜像源
- 优化构建步骤,增加 pnpm fetch 和离线安装
-简化 YAML 配置,提高可读性
- 添加 pnpm store 缓存卷,提高构建效率
2025-08-14 17:18:39 +08:00

99 lines
3.1 KiB
YAML
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.

kind: pipeline
type: docker
name: build-deploy
clone:
depth: 1
trigger:
event: [ push, custom ]
branch: [ master, test, feature/ldb_build ]
steps:
- name: install & build
image: node:22-bullseye-slim
environment:
# 统一走镜像,避免 npmjs 超时
NPM_CONFIG_REGISTRY: https://registry.npmmirror.com
PNPM_REGISTRY: https://registry.npmmirror.com
# 提高容错
PNPM_FETCH_RETRIES: "5"
PNPM_FETCH_RETRY_MINTIMEOUT: "2000"
PNPM_FETCH_RETRY_MAXTIMEOUT: "60000"
PNPM_FETCH_TIMEOUT: "600000"
CI: "true"
# 固定 pnpm store 到缓存卷
PNPM_STORE_DIR: /cache/pnpm
volumes:
- name: build-output
path: /runner/builds
- name: pnpm-store-cache
path: /cache
commands:
- node -v && npm -v
- corepack enable
- corepack prepare pnpm@8.15.5 --activate
# 关键:先把所有包拉进本地 store不执行 postinstall
- pnpm fetch
# 离线优先安装:命中 store 就不走网络;锁住 lockfile
- pnpm install --frozen-lockfile --prefer-offline
- mkdir -p /runner/builds/${DRONE_REPO_NAME}/${DRONE_BRANCH}
- |
case "${DRONE_BRANCH}" in
feature/ldb_build|test) pnpm run build:test ;;
master) pnpm run build:prod ;;
*) echo "❌ 未配置此分支的构建规则: ${DRONE_BRANCH}"; exit 1 ;;
esac
- rm -rf /runner/builds/${DRONE_REPO_NAME}/${DRONE_BRANCH}/*
- cp -r dist/* /runner/builds/${DRONE_REPO_NAME}/${DRONE_BRANCH}/
- name: deploy to spug
image: curlimages/curl
when:
status: [ success ]
branch: [ feature/ldb_build, test, master ]
environment:
SPUG_DEPLOY_URL:
from_secret: spug_deploy_lingji_work_fe_url
SPUG_DEPLOY_TOKEN:
from_secret: spug_deploy_token
commands:
- |
echo "🚀 部署到 Spug: 分支 ${DRONE_BRANCH}"
curl -X POST "$SPUG_DEPLOY_URL?name=${DRONE_BRANCH}&token=$SPUG_DEPLOY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ref": "refs/heads/'"${DRONE_BRANCH}"'",
"before": "'"${DRONE_COMMIT_BEFORE}"'",
"after": "'"${DRONE_COMMIT_SHA}"'",
"commits": [{"message": "发布'"${DRONE_BRANCH}${DRONE_COMMIT_SHA}"'"}]
}'
- name: notify feishu on failure
image: curlimages/curl
when:
status: [ failure ]
environment:
FEISHU_WEBHOOK:
from_secret: feishu_webhook_url
commands:
- |
curl -X POST "$FEISHU_WEBHOOK" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "text",
"content": { "text": "❌ Drone-CI 执行失败 ❗️\n项目: '${DRONE_REPO_NAME}'\n分支: '${DRONE_BRANCH}'\n提交: '${DRONE_COMMIT_SHA:0:8}'" }
}'
volumes:
- name: build-output
host:
path: /www/dk_project/dk_compose/spug/data/repos/build/drone-runner/builds
- name: pnpm-store-cache
host:
# 建议为 pnpm store 单独准备一个可持久化目录
path: /www/dk_project/dk_compose/spug/cache/pnpm-store