Some checks failed
continuous-integration/drone/push Build is failing
问题: - Drone CI 只会 clone 当前仓库,不会自动获取 martial-tool - 导致编译框架依赖步骤失败 解决方案: - 添加步骤0:使用 alpine/git 镜像克隆 martial-tool 代码 - 将框架代码 clone 到 /drone/martial-tool - 编译步骤使用正确的路径 /drone/martial-tool 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
112 lines
2.8 KiB
YAML
112 lines
2.8 KiB
YAML
kind: pipeline
|
||
type: docker
|
||
name: 武术系统后端自动部署
|
||
|
||
# 只在 main 分支触发
|
||
trigger:
|
||
branch:
|
||
- main
|
||
event:
|
||
- push
|
||
|
||
steps:
|
||
# 步骤0:克隆 BladeX 框架代码
|
||
- name: 克隆框架代码
|
||
image: alpine/git
|
||
commands:
|
||
- echo "克隆 BladeX 框架代码..."
|
||
- cd /drone
|
||
- git clone https://git.waypeak.work/martial/martial-tool.git
|
||
- ls -la /drone/martial-tool
|
||
- echo "✅ 框架代码克隆完成"
|
||
|
||
# 步骤1:编译 BladeX 框架
|
||
- name: 编译框架依赖
|
||
image: maven:3.9-eclipse-temurin-17
|
||
commands:
|
||
- echo "开始编译 BladeX 框架..."
|
||
- cd /drone/martial-tool
|
||
- mvn clean install -DskipTests -q
|
||
- echo "✅ BladeX 框架编译完成"
|
||
|
||
# 步骤2:编译后端项目
|
||
- name: 编译后端项目
|
||
image: maven:3.9-eclipse-temurin-17
|
||
commands:
|
||
- echo "开始编译后端项目..."
|
||
- mvn clean package -DskipTests -Dmaven.test.skip=true
|
||
- ls -lh target/blade-api.jar
|
||
- echo "✅ 后端项目编译完成"
|
||
|
||
# 步骤3:构建 Docker 镜像
|
||
- name: 构建Docker镜像
|
||
image: plugins/docker
|
||
settings:
|
||
registry: registry.cn-hangzhou.aliyuncs.com # 可选:使用阿里云镜像仓库
|
||
repo: martial/backend
|
||
tags:
|
||
- latest
|
||
- ${DRONE_COMMIT_SHA:0:8}
|
||
dockerfile: Dockerfile
|
||
# username: # 如果需要推送到私有仓库
|
||
# from_secret: docker_username
|
||
# password:
|
||
# from_secret: docker_password
|
||
|
||
# 步骤4:部署到服务器
|
||
- name: 部署到生产环境
|
||
image: appleboy/drone-ssh
|
||
settings:
|
||
host: 154.30.6.21 # 部署服务器地址
|
||
username: root
|
||
key:
|
||
from_secret: ssh_key # 需要在 Drone 中配置 SSH 私钥
|
||
port: 22
|
||
script:
|
||
- cd /app/martial
|
||
- docker-compose pull backend
|
||
- docker-compose up -d backend
|
||
- docker ps | grep martial-backend
|
||
- echo "✅ 后端部署完成"
|
||
|
||
# 步骤5:健康检查
|
||
- name: 健康检查
|
||
image: curlimages/curl:latest
|
||
commands:
|
||
- sleep 15 # 等待服务启动
|
||
- curl -f http://154.30.6.21:8123/actuator/health || exit 1
|
||
- echo "✅ 健康检查通过"
|
||
|
||
# 构建通知(可选)
|
||
---
|
||
kind: pipeline
|
||
type: docker
|
||
name: 构建通知
|
||
|
||
trigger:
|
||
branch:
|
||
- main
|
||
status:
|
||
- success
|
||
- failure
|
||
|
||
steps:
|
||
- name: 发送通知
|
||
image: drillster/drone-email
|
||
settings:
|
||
host: smtp.qq.com # 邮件服务器
|
||
port: 465
|
||
from: your-email@qq.com
|
||
recipients:
|
||
- your-email@qq.com
|
||
username:
|
||
from_secret: email_username
|
||
password:
|
||
from_secret: email_password
|
||
when:
|
||
status:
|
||
- failure # 只在失败时发送邮件
|
||
|
||
depends_on:
|
||
- 武术系统后端自动部署
|