continuous-integration/drone/push Build is failing
问题: - Dockerfile 中 npm install 时未复制 .npmrc 文件 - 使用 --registry 参数覆盖了 .npmrc 中的私有 registry 配置 - 导致无法下载 @saber scope 的私有包,报 E401 认证错误 解决方案: - Dockerfile: 在 npm install 前复制 .npmrc 文件 - Dockerfile: 移除 --registry 参数,使用 .npmrc 中的配置 - .drone.yml: 同样移除 --registry 参数 现在 npm 会正确使用: - @saber 包 -> https://center.javablade.com (私有 registry) - 其他包 -> npm 默认源 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
1.4 KiB
YAML
63 lines
1.4 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:构建 Docker 镜像
|
|
- name: 构建Docker镜像
|
|
image: plugins/docker
|
|
settings:
|
|
repo: martial/frontend
|
|
tags:
|
|
- latest
|
|
- ${DRONE_COMMIT_SHA:0:8}
|
|
dockerfile: Dockerfile
|
|
|
|
# 步骤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
|
|
- docker-compose pull frontend
|
|
- 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:2888 || exit 1
|
|
- echo "✅ 前端访问正常"
|