From bd87cdf0e616f2325fbaac474cbe69fc8a2e4c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sun, 29 Mar 2026 19:44:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E4=BF=AE=E5=A4=8D=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E7=8E=AF=E5=A2=83=E5=AE=B9=E5=99=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: 1. Dockerfile.prod目录结构错误 - standalone路径不正确 - static文件路径错误 2. docker-compose.server.yml网络配置问题 - external网络可能不存在 3. 健康检查命令不可用 - alpine镜像缺少wget 修复: 1. Dockerfile.prod - 正确复制standalone目录内容 - 将static文件复制到.next/static/ - 安装curl用于健康检查 2. docker-compose.server.yml - 移除external网络依赖 - 使用curl进行健康检查 3. deploy-production.sh - 使用curl替代wget - 备份包含Dockerfile.prod和docker-compose.server.yml --- Dockerfile.prod | 7 ++++--- docker-compose.server.yml | 8 +------- scripts/deploy-production.sh | 6 +++--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Dockerfile.prod b/Dockerfile.prod index c739cae..f414036 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -7,10 +7,11 @@ ENV PORT=3000 ENV HOSTNAME="0.0.0.0" RUN addgroup --system --gid 1001 nodejs && \ - adduser --system --uid 1001 nextjs + adduser --system --uid 1001 nextjs && \ + apk add --no-cache curl -COPY dist/standalone ./ -COPY dist/static ./dist/static +COPY dist/standalone/novalon-website/ ./ +COPY dist/static/ ./.next/static/ COPY public ./public RUN chown -R nextjs:nodejs /app diff --git a/docker-compose.server.yml b/docker-compose.server.yml index 286c0ee..e9d4703 100644 --- a/docker-compose.server.yml +++ b/docker-compose.server.yml @@ -18,19 +18,13 @@ services: - ./data:/app/data - ./uploads:/app/uploads healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/health"] + test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"] interval: 30s timeout: 10s retries: 3 start_period: 40s - networks: - - novalon-network logging: driver: "json-file" options: max-size: "10m" max-file: "3" - -networks: - novalon-network: - external: true diff --git a/scripts/deploy-production.sh b/scripts/deploy-production.sh index f790f4e..82d77a4 100644 --- a/scripts/deploy-production.sh +++ b/scripts/deploy-production.sh @@ -16,7 +16,7 @@ echo "" echo "=== Step 1: 备份当前版本 ===" mkdir -p $BACKUP_DIR if [ -d "dist" ]; then - tar -czf $BACKUP_DIR/dist_$TIMESTAMP.tar.gz dist public package.json package-lock.json 2>/dev/null || echo "备份完成(部分文件可能不存在)" + tar -czf $BACKUP_DIR/dist_$TIMESTAMP.tar.gz dist public package.json package-lock.json Dockerfile.prod docker-compose.server.yml 2>/dev/null || echo "备份完成(部分文件可能不存在)" echo "✅ 备份已保存到: $BACKUP_DIR/dist_$TIMESTAMP.tar.gz" else echo "⚠️ 没有找到dist目录,跳过备份" @@ -48,7 +48,7 @@ sleep 10 echo "" echo "=== Step 6: 健康检查 ===" for i in {1..30}; do - if wget -q --spider http://localhost:3000/api/health 2>/dev/null; then + if curl -f http://localhost:3000/api/health >/dev/null 2>&1; then echo "✅ 健康检查通过!" echo "" @@ -75,7 +75,7 @@ if [ -f "$BACKUP_DIR/dist_$TIMESTAMP.tar.gz" ]; then docker-compose down docker-compose up -d sleep 10 - if wget -q --spider http://localhost:3000/api/health 2>/dev/null; then + if curl -f http://localhost:3000/api/health >/dev/null 2>&1; then echo "✅ 回滚成功" else echo "❌ 回滚也失败了!"