chore(deploy): 完善 lotteryfront 单机部署流程
Some checks failed
lotteryfront CI / build (push) Has been cancelled

This commit is contained in:
2026-07-07 15:32:03 +08:00
parent 396b3c47de
commit a86e8a2c67
4 changed files with 28 additions and 5 deletions

View File

@@ -3,8 +3,8 @@
* 玩家端lotteryfront宝塔 PM2 配置 * 玩家端lotteryfront宝塔 PM2 配置
* *
* 部署步骤(在服务器项目目录执行): * 部署步骤(在服务器项目目录执行):
* 1. 复制 .env.example .env按线上域名填写见下方 env 说明) * 1. 本地 npm run build打包 .next/standalone + .next/static + public 上传服务器
* 2. npm ci && npm run build * 2. 服务器:复制 .env.example 为 .env按线上域名填写见下方 env 说明)
* 3. 修改下方 cwd 为服务器上的实际路径 * 3. 修改下方 cwd 为服务器上的实际路径
* 4. pm2 start ecosystem.config.cjs * 4. pm2 start ecosystem.config.cjs
* 5. pm2 save && pm2 startup # 开机自启(按 PM2 提示执行) * 5. pm2 save && pm2 startup # 开机自启(按 PM2 提示执行)
@@ -23,8 +23,7 @@ module.exports = {
{ {
name: "lotteryfront", name: "lotteryfront",
cwd: APP_CWD, cwd: APP_CWD,
script: "node_modules/next/dist/bin/next", script: ".next/standalone/server.js",
args: "start -p 3800 -H 127.0.0.1",
interpreter: "node", interpreter: "node",
exec_mode: "fork", exec_mode: "fork",
instances: 1, instances: 1,
@@ -38,6 +37,7 @@ module.exports = {
env: { env: {
NODE_ENV: "production", NODE_ENV: "production",
HOSTNAME: "0.0.0.0",
PORT: "3800", PORT: "3800",
}, },

View File

@@ -6,10 +6,12 @@ import { parseAllowedDevOrigins } from "./src/lib/next-dev-origins";
const allowedDevOrigins = parseAllowedDevOrigins(process.env.ALLOWED_DEV_ORIGINS); const allowedDevOrigins = parseAllowedDevOrigins(process.env.ALLOWED_DEV_ORIGINS);
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
output: "standalone",
allowedDevOrigins, allowedDevOrigins,
reactCompiler: true, reactCompiler: true,
images: { images: {
unoptimized: true,
deviceSizes: [640, 750, 828, 1080, 1200, 1920], deviceSizes: [640, 750, 828, 1080, 1200, 1920],
}, },

View File

@@ -4,7 +4,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev --port 3800 -H 0.0.0.0", "dev": "next dev --port 3800 -H 0.0.0.0",
"build": "next build", "build": "next build && cp -r .next/static .next/standalone/.next/static && cp -r public .next/standalone/public && echo '✅ standalone 静态资源已复制完毕'",
"start": "next start --port 3800", "start": "next start --port 3800",
"lint": "eslint" "lint": "eslint"
}, },

21
scripts/deploy.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
# lotteryfront 一键部署脚本
# 用法: bash scripts/deploy.sh
set -e
SERVER="root@47.242.205.221"
REMOTE_DIR="/www/wwwroot/lotteryFront"
echo "🔨 构建中..."
npm run build
echo "📦 上传到服务器..."
ssh ${SERVER} "mkdir -p ${REMOTE_DIR}/.next/standalone ${REMOTE_DIR}/logs"
rsync -avz --delete .next/standalone/ ${SERVER}:${REMOTE_DIR}/.next/standalone/
rsync -avz ecosystem.config.cjs ${SERVER}:${REMOTE_DIR}/ecosystem.config.cjs
echo "🚀 服务器重启 PM2..."
ssh ${SERVER} "source /etc/profile && source ~/.bashrc && mkdir -p ${REMOTE_DIR}/logs && cd ${REMOTE_DIR} && (pm2 restart lotteryfront 2>/dev/null || pm2 start ecosystem.config.cjs) && pm2 save"
echo "✅ lotteryFront 部署完成!"