修复前端 CI/CD:改为在部署服务器上构建镜像
All checks were successful
continuous-integration/drone/push Build is passing
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:
29
.drone.yml
29
.drone.yml
@@ -27,17 +27,23 @@ steps:
|
||||
- ls -lh dist/
|
||||
- echo "✅ 前端构建完成"
|
||||
|
||||
# 步骤3:构建 Docker 镜像
|
||||
- name: 构建Docker镜像
|
||||
image: plugins/docker
|
||||
# 步骤3:传输文件到服务器
|
||||
- name: 传输构建产物
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
repo: martial/frontend
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_COMMIT_SHA:0:8}
|
||||
dockerfile: Dockerfile
|
||||
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:部署到服务器
|
||||
# 步骤4:在服务器上构建镜像并部署
|
||||
- name: 部署到生产环境
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
@@ -47,8 +53,9 @@ steps:
|
||||
from_secret: ssh_key
|
||||
port: 22
|
||||
script:
|
||||
- cd /app/martial/frontend-build
|
||||
- docker build -t martial/frontend:latest .
|
||||
- cd /app/martial
|
||||
- docker-compose pull frontend
|
||||
- docker-compose up -d frontend
|
||||
- docker ps | grep martial-frontend
|
||||
- echo "✅ 前端部署完成"
|
||||
@@ -58,5 +65,5 @@ steps:
|
||||
image: curlimages/curl:latest
|
||||
commands:
|
||||
- sleep 5
|
||||
- curl -f http://154.30.6.21:2888 || exit 1
|
||||
- curl -f http://154.30.6.21/ || exit 1
|
||||
- echo "✅ 前端访问正常"
|
||||
|
||||
Reference in New Issue
Block a user