fix(deploy): 修复生产环境容器启动失败问题
ci/woodpecker/push/woodpecker Pipeline failed

问题:
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
This commit is contained in:
张翔
2026-03-29 19:44:43 +08:00
parent afc462c46c
commit bd87cdf0e6
3 changed files with 8 additions and 13 deletions
+4 -3
View File
@@ -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
+1 -7
View File
@@ -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
+3 -3
View File
@@ -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 "❌ 回滚也失败了!"