build: 修改make start为静态部署

This commit is contained in:
肖应宇 2026-04-08 15:04:41 +08:00
parent 25111a9b03
commit fd884bd676
2 changed files with 45 additions and 2 deletions

View File

@ -132,6 +132,7 @@ stop:
@-pkill -f "next start" 2>/dev/null || true
@-pkill -f "next-server" 2>/dev/null || true
@-pkill -f "next-server" 2>/dev/null || true
@-pkill -f "frontend/.next/standalone/server.js" 2>/dev/null || true
@-nginx -c $(PWD)/docker/nginx/nginx.local.conf -p $(PWD) -s quit 2>/dev/null || true
@sleep 1
@-pkill -9 nginx 2>/dev/null || true

View File

@ -38,7 +38,43 @@ else
echo "Python is required to generate BETTER_AUTH_SECRET, but neither python3 nor python was found."
exit 1
fi
FRONTEND_CMD="env BETTER_AUTH_SECRET=$($PYTHON_BIN -c 'import secrets; print(secrets.token_hex(16))') pnpm run preview"
FRONTEND_STANDALONE_DIR="$REPO_ROOT/frontend/.next/standalone"
FRONTEND_STANDALONE_SERVER="$FRONTEND_STANDALONE_DIR/server.js"
FRONTEND_STANDALONE_STATIC_DIR="$FRONTEND_STANDALONE_DIR/.next/static"
FRONTEND_SOURCE_STATIC_DIR="$REPO_ROOT/frontend/.next/static"
FRONTEND_STANDALONE_PUBLIC_DIR="$FRONTEND_STANDALONE_DIR/public"
FRONTEND_SOURCE_PUBLIC_DIR="$REPO_ROOT/frontend/public"
if [ ! -f "$FRONTEND_STANDALONE_SERVER" ]; then
echo "✗ Frontend standalone server not found: $FRONTEND_STANDALONE_SERVER"
echo " make start (prod) now uses prebuilt standalone assets and will not run local build."
echo " Please prepare frontend artifacts first (example):"
echo " pnpm -C frontend build"
exit 1
fi
# Align local runtime layout with deploy-frontend-standalone.sh:
# standalone + .next/static + public under frontend/.next/standalone/
if [ ! -d "$FRONTEND_STANDALONE_STATIC_DIR" ] && [ -d "$FRONTEND_SOURCE_STATIC_DIR" ]; then
mkdir -p "$FRONTEND_STANDALONE_DIR/.next"
cp -R "$FRONTEND_SOURCE_STATIC_DIR" "$FRONTEND_STANDALONE_STATIC_DIR"
fi
if [ ! -d "$FRONTEND_STANDALONE_PUBLIC_DIR" ] && [ -d "$FRONTEND_SOURCE_PUBLIC_DIR" ]; then
cp -R "$FRONTEND_SOURCE_PUBLIC_DIR" "$FRONTEND_STANDALONE_PUBLIC_DIR"
fi
if [ ! -d "$FRONTEND_STANDALONE_STATIC_DIR" ]; then
echo "✗ Missing standalone static assets: $FRONTEND_STANDALONE_STATIC_DIR"
echo " Please ensure .next/static is available for standalone runtime."
exit 1
fi
if [ ! -d "$FRONTEND_STANDALONE_PUBLIC_DIR" ]; then
echo "✗ Missing standalone public assets: $FRONTEND_STANDALONE_PUBLIC_DIR"
echo " Please ensure public/ is available for standalone runtime."
exit 1
fi
FRONTEND_CMD="env BETTER_AUTH_SECRET=$($PYTHON_BIN -c 'import secrets; print(secrets.token_hex(16))') HOSTNAME=0.0.0.0 PORT=3000 node server.js"
fi
# ── Stop existing services ────────────────────────────────────────────────────
@ -48,6 +84,7 @@ pkill -f "langgraph dev" 2>/dev/null || true
pkill -f "uvicorn app.gateway.app:app" 2>/dev/null || true
pkill -f "next dev" 2>/dev/null || true
pkill -f "next-server" 2>/dev/null || true
pkill -f "frontend/.next/standalone/server.js" 2>/dev/null || true
nginx -c "$REPO_ROOT/docker/nginx/nginx.local.conf" -p "$REPO_ROOT" -s quit 2>/dev/null || true
sleep 1
pkill -9 nginx 2>/dev/null || true
@ -110,6 +147,7 @@ cleanup() {
pkill -f "next dev" 2>/dev/null || true
pkill -f "next start" 2>/dev/null || true
pkill -f "next-server" 2>/dev/null || true
pkill -f "frontend/.next/standalone/server.js" 2>/dev/null || true
# Kill nginx using the captured PID first (most reliable),
# then fall back to pkill/killall for any stray nginx workers.
if [ -n "${NGINX_PID:-}" ] && kill -0 "$NGINX_PID" 2>/dev/null; then
@ -181,7 +219,11 @@ echo "Starting Gateway API..."
echo "✓ Gateway API started on localhost:8001"
echo "Starting Frontend..."
(cd frontend && $FRONTEND_CMD > ../logs/frontend.log 2>&1) &
if $DEV_MODE; then
(cd frontend && $FRONTEND_CMD > ../logs/frontend.log 2>&1) &
else
(cd frontend/.next/standalone && $FRONTEND_CMD > ../../../logs/frontend.log 2>&1) &
fi
./scripts/wait-for-port.sh 3000 120 "Frontend" || {
echo " See logs/frontend.log for details"
tail -20 logs/frontend.log