Files
martial-master/.drone.yml
n72595987@gmail.com 667c11b474
Some checks failed
continuous-integration/drone/push Build is failing
修复后端 CI/CD:改为在部署服务器上构建镜像
问题:
- plugins/docker 尝试推送镜像到远程 registry
- 需要配置认证且增加网络传输时间

解决方案:
- 移除 plugins/docker 步骤
- 添加 drone-scp 步骤传输构建产物(blade-api.jar、Dockerfile)
- 在部署服务器上执行 docker build
- 直接使用本地镜像启动容器

优势:
- 不需要配置 Docker registry 认证
- 不需要推送和拉取大型镜像,部署更快
- JAR 文件小(约 50-100MB),传输速度快
- 镜像只存在于部署服务器本地,更安全

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 18:05:07 +08:00

107 lines
2.5 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: 武术系统后端自动部署
# 只在 main 分支触发
trigger:
branch:
- main
event:
- push
steps:
# 步骤1克隆并编译 BladeX 框架
- name: 编译框架依赖
image: maven:3.9-eclipse-temurin-17
commands:
- echo "克隆 BladeX 框架代码..."
- cd /drone/src/..
- git clone https://git.waypeak.work/martial/martial-tool.git || echo "已存在,跳过克隆"
- ls -la
- echo "开始编译 BladeX 框架..."
- cd 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传输构建产物
- name: 传输构建产物
image: appleboy/drone-scp
settings:
host: 154.30.6.21
username: root
key:
from_secret: ssh_key
port: 22
target: /app/martial/backend-build
source:
- target/blade-api.jar
- Dockerfile
strip_components: 0
# 步骤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/backend-build
- docker build -t martial/backend:latest .
- cd /app/martial
- 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:
- 武术系统后端自动部署