修复前端 CI/CD:改为在部署服务器上构建镜像
All checks were successful
continuous-integration/drone/push Build is passing

问题:
- 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>
This commit is contained in:
n72595987@gmail.com
2025-11-29 18:04:56 +08:00
parent 36116e0973
commit 890218199b

View File

@@ -27,17 +27,23 @@ steps:
- ls -lh dist/ - ls -lh dist/
- echo "✅ 前端构建完成" - echo "✅ 前端构建完成"
# 步骤3构建 Docker 镜像 # 步骤3传输文件到服务器
- name: 构建Docker镜像 - name: 传输构建产物
image: plugins/docker image: appleboy/drone-scp
settings: settings:
repo: martial/frontend host: 154.30.6.21
tags: username: root
- latest key:
- ${DRONE_COMMIT_SHA:0:8} from_secret: ssh_key
dockerfile: Dockerfile port: 22
target: /app/martial/frontend-build
source:
- dist/*
- Dockerfile
- nginx.conf
strip_components: 0
# 步骤4部署到服务器 # 步骤4在服务器上构建镜像并部署
- name: 部署到生产环境 - name: 部署到生产环境
image: appleboy/drone-ssh image: appleboy/drone-ssh
settings: settings:
@@ -47,8 +53,9 @@ steps:
from_secret: ssh_key from_secret: ssh_key
port: 22 port: 22
script: script:
- cd /app/martial/frontend-build
- docker build -t martial/frontend:latest .
- cd /app/martial - cd /app/martial
- docker-compose pull frontend
- docker-compose up -d frontend - docker-compose up -d frontend
- docker ps | grep martial-frontend - docker ps | grep martial-frontend
- echo "✅ 前端部署完成" - echo "✅ 前端部署完成"
@@ -58,5 +65,5 @@ steps:
image: curlimages/curl:latest image: curlimages/curl:latest
commands: commands:
- sleep 5 - sleep 5
- curl -f http://154.30.6.21:2888 || exit 1 - curl -f http://154.30.6.21/ || exit 1
- echo "✅ 前端访问正常" - echo "✅ 前端访问正常"