Files
martial-web/.drone.yml
T
n72595987@gmail.comandClaude 890218199b
continuous-integration/drone/push Build is passing
修复前端 CI/CD:改为在部署服务器上构建镜像
问题:
- plugins/docker 尝试推送镜像到 Docker Hub
- 没有配置认证导致 'denied: requested access to resource is denied'

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

优势:
- 不需要配置 Docker Hub 认证
- 不需要推送和拉取镜像,更快
- 镜像只存在于部署服务器本地
- 修正健康检查 URL 为 http://154.30.6.21/

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

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

70 lines
1.6 KiB
YAML

kind: pipeline
type: docker
name: 武术系统前端自动部署
# 只在 main 分支触发
trigger:
branch:
- main
event:
- push
steps:
# 步骤1:安装依赖
- name: 安装依赖
image: node:18-alpine
commands:
- echo "开始安装 npm 依赖..."
- npm install
- echo "✅ 依赖安装完成"
# 步骤2:构建生产版本
- name: 构建前端项目
image: node:18-alpine
commands:
- echo "开始构建前端项目..."
- npm run build
- ls -lh dist/
- 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/frontend-build
source:
- dist/*
- Dockerfile
- nginx.conf
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/frontend-build
- docker build -t martial/frontend:latest .
- cd /app/martial
- 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/ || exit 1
- echo "✅ 前端访问正常"