ci(.drone.yml): 优化 Node.js 项目部署流程
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
- 重构了 Drone CI/CD 配置文件,将单一的 build-project 步骤拆分为 setup、build 和 deploy 三个独立步骤 - 引入了国内镜像源(npmmirror)以加速包管理 - 优化了 pnpm 的安装和使用流程 - 增加了测试步骤和环境变量配置 - 更新了触发
This commit is contained in:
parent
dbf6b424cb
commit
7dd10168e0
79
.drone.yml
79
.drone.yml
@ -1,42 +1,61 @@
|
|||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: deploy
|
name: nodejs-deploy
|
||||||
#
|
|
||||||
volumes:
|
# 使用国内镜像加速
|
||||||
|
volumes:
|
||||||
- name: node_modules
|
- name: node_modules
|
||||||
host:
|
host:
|
||||||
path: /usr/local/blackend/node_modules
|
path: /usr/local/blackend/node_modules
|
||||||
- name: web_build_dir
|
- name: pnpm_cache
|
||||||
host:
|
host:
|
||||||
path: /opt/1panel/apps/openresty/openresty/www/sites/120.48.5.80/automated
|
path: /usr/local/blackend/pnpm_cache
|
||||||
- name: yarn_cache
|
|
||||||
host:
|
|
||||||
path: /usr/local/blackend/yarn_cache
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build-project
|
- name: setup
|
||||||
image: node:22-alpine
|
image: node:22-alpine
|
||||||
depends_on: [clone]
|
depends_on: [clone]
|
||||||
mirror: https://docker.1panelproxy.com
|
volumes:
|
||||||
volumes:
|
|
||||||
- name: node_modules
|
- name: node_modules
|
||||||
path: /drone/src/node_modules
|
path: /drone/src/node_modules
|
||||||
- name: web_build_dir
|
- name: pnpm_cache
|
||||||
path: /drone/src/dist
|
path: /root/.local/share/pnpm/store
|
||||||
- name: yarn_cache
|
commands:
|
||||||
path: /usr/local/share/.cache/yarn/v6
|
# 配置镜像源
|
||||||
commands:
|
- npm config set registry https://registry.npmmirror.com
|
||||||
# - npm config set registry https://registry.npm.taobao.org
|
|
||||||
- npm install -g pnpm
|
|
||||||
- pnpm config set registry https://registry.npmmirror.com
|
- pnpm config set registry https://registry.npmmirror.com
|
||||||
- pnpm install
|
# 安装pnpm
|
||||||
- pnpm build
|
- npm install -g pnpm
|
||||||
#- npm cache clean --force
|
# 安装依赖
|
||||||
# - npm install
|
- pnpm install --frozen-lockfile
|
||||||
# - npm run build:prod
|
|
||||||
|
- name: build
|
||||||
|
image: node:22-alpine
|
||||||
|
depends_on: [setup]
|
||||||
|
volumes:
|
||||||
|
- name: node_modules
|
||||||
|
path: /drone/src/node_modules
|
||||||
|
commands:
|
||||||
|
# 构建项目
|
||||||
|
- pnpm run build
|
||||||
|
# 运行测试
|
||||||
|
- pnpm test
|
||||||
|
|
||||||
|
- name: deploy
|
||||||
|
image: node:22-alpine
|
||||||
|
depends_on: [build]
|
||||||
|
commands:
|
||||||
|
# 启动服务
|
||||||
|
- pnpm start
|
||||||
|
environment:
|
||||||
|
NODE_ENV: production
|
||||||
|
PORT: 8001
|
||||||
|
|
||||||
|
# 触发条件
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- main
|
- main
|
||||||
|
- develop
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
|
- pull_request
|
Loading…
Reference in New Issue
Block a user