添加 Drone CI/CD 前端自动化部署配置
Some checks failed
continuous-integration/drone/push Build encountered an error
Some checks failed
continuous-integration/drone/push Build encountered an error
1. 新增 .drone.yml 配置文件 - 自动安装 npm 依赖 - 自动构建生产版本 - 构建 Docker 镜像 - 自动部署到生产服务器 - 健康检查验证部署成功 2. 新增 Dockerfile - 多阶段构建:Node 编译 + Nginx 运行 - 优化镜像体积,使用 alpine 基础镜像 - 配置静态资源缓存 - 添加健康检查 3. 新增 nginx.conf - 配置前端路由支持(Vue Router history 模式) - 代理 API 请求到后端服务 - 优化 Gzip 压缩和静态资源缓存 - 支持 BladeX 系统模块路径代理 现在推送代码后,前端会自动部署到生产环境! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
71
.drone.yml
Normal file
71
.drone.yml
Normal file
@@ -0,0 +1,71 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: 武术系统前端自动部署
|
||||
|
||||
# 只在 main 分支触发
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
- push
|
||||
|
||||
steps:
|
||||
# 步骤1:安装依赖
|
||||
- name: 安装依赖
|
||||
image: node:18-alpine
|
||||
volumes:
|
||||
- name: npm-cache
|
||||
path: /root/.npm
|
||||
commands:
|
||||
- echo "开始安装 npm 依赖..."
|
||||
- npm install --registry=https://registry.npmmirror.com
|
||||
- echo "✅ 依赖安装完成"
|
||||
|
||||
# 步骤2:构建生产版本
|
||||
- name: 构建前端项目
|
||||
image: node:18-alpine
|
||||
commands:
|
||||
- echo "开始构建前端项目..."
|
||||
- npm run build
|
||||
- ls -lh dist/
|
||||
- echo "✅ 前端构建完成"
|
||||
|
||||
# 步骤3:构建 Docker 镜像
|
||||
- name: 构建Docker镜像
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: martial/frontend
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_COMMIT_SHA:0:8}
|
||||
dockerfile: Dockerfile
|
||||
|
||||
# 步骤4:部署到服务器
|
||||
- name: 部署到生产环境
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host: 154.30.6.21
|
||||
username: root
|
||||
key:
|
||||
from_secret: ssh_key
|
||||
port: 22
|
||||
script:
|
||||
- cd /app/martial
|
||||
- docker-compose pull frontend
|
||||
- docker-compose up -d frontend
|
||||
- docker ps | grep martial-frontend
|
||||
- echo "✅ 前端部署完成"
|
||||
|
||||
# 步骤5:健康检查
|
||||
- name: 健康检查
|
||||
image: curlimages/curl:latest
|
||||
commands:
|
||||
- sleep 5
|
||||
- curl -f http://154.30.6.21:2888 || exit 1
|
||||
- echo "✅ 前端访问正常"
|
||||
|
||||
# 挂载卷(缓存 npm 依赖)
|
||||
volumes:
|
||||
- name: npm-cache
|
||||
host:
|
||||
path: /data/drone-cache/npm
|
||||
Reference in New Issue
Block a user