init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: dukang-mysql
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
MYSQL_DATABASE: dukang_haoke
|
||||
ports:
|
||||
- '3306:3306'
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: dukang-redis
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- '6379:6379'
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
redis_data:
|
||||
@@ -0,0 +1,45 @@
|
||||
/** PM2 ecosystem — 杜康好客生产部署 */
|
||||
const APP_ROOT = '/opt/dukang-haoke';
|
||||
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'dukang-api',
|
||||
cwd: `${APP_ROOT}/server/dukang-api`,
|
||||
script: 'dist/main.js',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 8090,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'dukang-h5-user',
|
||||
cwd: `${APP_ROOT}/apps/h5-user`,
|
||||
script: 'npx',
|
||||
args: 'serve -s dist -l 8091',
|
||||
interpreter: 'none',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
},
|
||||
{
|
||||
name: 'dukang-h5-shop',
|
||||
cwd: `${APP_ROOT}/apps/h5-shop`,
|
||||
script: 'npx',
|
||||
args: 'serve -s dist -l 8092',
|
||||
interpreter: 'none',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
},
|
||||
{
|
||||
name: 'dukang-h5-partner',
|
||||
cwd: `${APP_ROOT}/apps/h5-partner`,
|
||||
script: 'npx',
|
||||
args: 'serve -s dist -l 8093',
|
||||
interpreter: 'none',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
map $host $dukang_h5_port {
|
||||
user.ai-mirror.xyz 8091;
|
||||
shop.ai-mirror.xyz 8092;
|
||||
partner.ai-mirror.xyz 8093;
|
||||
}
|
||||
|
||||
# HTTP — 证书申请期间先提供 HTTP 服务
|
||||
server {
|
||||
listen 80;
|
||||
server_name user.ai-mirror.xyz shop.ai-mirror.xyz partner.ai-mirror.xyz;
|
||||
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:8090;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:$dukang_h5_port;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
# 杜康好客 H5 三端 — ai-mirror.xyz
|
||||
# API 内部端口 8090;H5 分别 8091/8092/8093
|
||||
|
||||
map $host $dukang_h5_port {
|
||||
user.ai-mirror.xyz 8091;
|
||||
shop.ai-mirror.xyz 8092;
|
||||
partner.ai-mirror.xyz 8093;
|
||||
}
|
||||
|
||||
# HTTP → HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
server_name user.ai-mirror.xyz shop.ai-mirror.xyz partner.ai-mirror.xyz;
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
location / {
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name user.ai-mirror.xyz shop.ai-mirror.xyz partner.ai-mirror.xyz;
|
||||
|
||||
access_log /var/log/nginx/dukang/access.log main;
|
||||
error_log /var/log/nginx/dukang/error.log warn;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/user.ai-mirror.xyz/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/user.ai-mirror.xyz/privkey.pem;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
client_max_body_size 20m;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:8090;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:$dukang_h5_port;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
APP_ROOT="/opt/dukang-haoke"
|
||||
DEPLOY_DIR="$APP_ROOT/deploy"
|
||||
|
||||
echo "==> install api deps only"
|
||||
cd "$APP_ROOT"
|
||||
export NODE_OPTIONS="--max-old-space-size=1024"
|
||||
pnpm install --filter @dukang/api... --filter @dukang/domain --filter @dukang/shared-types
|
||||
|
||||
echo "==> env"
|
||||
cat > "$APP_ROOT/server/dukang-api/.env" <<'ENV'
|
||||
DATABASE_URL="mysql://dukang:Dukang2026!@localhost:3306/dukang_haoke"
|
||||
REDIS_URL="redis://localhost:6379"
|
||||
JWT_SECRET="dukang-prod-jwt-secret-2026"
|
||||
JWT_EXPIRES_IN="7d"
|
||||
PORT=8090
|
||||
MOCK_SMS=true
|
||||
MOCK_SMS_CODE=123456
|
||||
MOCK_PAY=true
|
||||
MOCK_DELIVERY_AUTO=true
|
||||
AUTO_APPROVE_STORE=true
|
||||
ENV
|
||||
|
||||
echo "==> prisma"
|
||||
cd "$APP_ROOT/server/dukang-api"
|
||||
pnpm prisma:generate
|
||||
npx prisma db push --accept-data-loss
|
||||
pnpm prisma:seed
|
||||
|
||||
echo "==> serve"
|
||||
npm install -g serve
|
||||
|
||||
echo "==> pm2"
|
||||
mkdir -p /var/log/nginx/dukang /var/www/certbot
|
||||
pm2 delete dukang-api dukang-h5-user dukang-h5-shop dukang-h5-partner 2>/dev/null || true
|
||||
pm2 start "$DEPLOY_DIR/ecosystem.config.cjs"
|
||||
pm2 save
|
||||
|
||||
echo "==> ssl"
|
||||
if [ ! -f /etc/letsencrypt/live/user.ai-mirror.xyz/fullchain.pem ]; then
|
||||
certbot certonly --webroot -w /var/www/certbot \
|
||||
-d user.ai-mirror.xyz -d shop.ai-mirror.xyz -d partner.ai-mirror.xyz \
|
||||
--non-interactive --agree-tos -m admin@ai-mirror.xyz
|
||||
fi
|
||||
|
||||
echo "==> nginx"
|
||||
cp "$DEPLOY_DIR/nginx-ai-mirror.conf" /etc/nginx/conf.d/dukang-ai-mirror.conf
|
||||
nginx -t
|
||||
systemctl reload nginx
|
||||
|
||||
echo "==> DONE"
|
||||
pm2 list
|
||||
ss -tlnp | grep -E '809[0-3]' || true
|
||||
curl -s -o /dev/null -w "user:%{http_code}\n" http://127.0.0.1:8091/
|
||||
curl -s -o /dev/null -w "api:%{http_code}\n" http://127.0.0.1:8090/api/v1/health 2>/dev/null || curl -s -o /dev/null -w "api:%{http_code}\n" http://127.0.0.1:8090/
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
APP_ROOT="/opt/dukang-haoke"
|
||||
DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
echo "==> 1. 安装 MySQL(如未安装)"
|
||||
if ! command -v mysqld &>/dev/null; then
|
||||
dnf install -y mysql-server
|
||||
systemctl enable --now mysqld
|
||||
sleep 3
|
||||
fi
|
||||
|
||||
echo "==> 2. 配置 MySQL 数据库"
|
||||
mysql -uroot -e "CREATE DATABASE IF NOT EXISTS dukang_haoke CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null || true
|
||||
mysql -uroot -e "CREATE USER IF NOT EXISTS 'dukang'@'localhost' IDENTIFIED BY 'Dukang2026!';" 2>/dev/null || \
|
||||
mysql -uroot -e "ALTER USER 'dukang'@'localhost' IDENTIFIED BY 'Dukang2026!';" 2>/dev/null || true
|
||||
mysql -uroot -e "GRANT ALL PRIVILEGES ON dukang_haoke.* TO 'dukang'@'localhost'; FLUSH PRIVILEGES;" 2>/dev/null || true
|
||||
|
||||
echo "==> 3. 启用 pnpm"
|
||||
corepack enable
|
||||
corepack prepare pnpm@11.2.2 --activate
|
||||
|
||||
echo "==> 4. 安装依赖并构建"
|
||||
cd "$APP_ROOT"
|
||||
pnpm install --frozen-lockfile 2>/dev/null || pnpm install
|
||||
pnpm build
|
||||
|
||||
echo "==> 5. 写入 API 生产环境变量"
|
||||
cat > "$APP_ROOT/server/dukang-api/.env" <<'ENV'
|
||||
DATABASE_URL="mysql://dukang:Dukang2026!@localhost:3306/dukang_haoke"
|
||||
REDIS_URL="redis://localhost:6379"
|
||||
JWT_SECRET="dukang-prod-jwt-secret-2026"
|
||||
JWT_EXPIRES_IN="7d"
|
||||
PORT=8090
|
||||
MOCK_SMS=true
|
||||
MOCK_SMS_CODE=123456
|
||||
MOCK_PAY=true
|
||||
MOCK_DELIVERY_AUTO=true
|
||||
AUTO_APPROVE_STORE=true
|
||||
ENV
|
||||
|
||||
echo "==> 6. 初始化数据库"
|
||||
cd "$APP_ROOT/server/dukang-api"
|
||||
pnpm prisma:generate
|
||||
npx prisma db push --accept-data-loss
|
||||
pnpm prisma:seed
|
||||
|
||||
echo "==> 7. 安装 serve(静态服务)"
|
||||
npm install -g serve
|
||||
|
||||
echo "==> 8. 启动 PM2 进程"
|
||||
mkdir -p /var/log/nginx/dukang /var/www/certbot
|
||||
pm2 delete dukang-api dukang-h5-user dukang-h5-shop dukang-h5-partner 2>/dev/null || true
|
||||
pm2 start "$DEPLOY_DIR/ecosystem.config.cjs"
|
||||
pm2 save
|
||||
|
||||
echo "==> 9. 申请 SSL 证书"
|
||||
if [ ! -f /etc/letsencrypt/live/user.ai-mirror.xyz/fullchain.pem ]; then
|
||||
certbot certonly --webroot -w /var/www/certbot \
|
||||
-d user.ai-mirror.xyz \
|
||||
-d shop.ai-mirror.xyz \
|
||||
-d partner.ai-mirror.xyz \
|
||||
--non-interactive --agree-tos -m admin@ai-mirror.xyz || \
|
||||
certbot certonly --nginx \
|
||||
-d user.ai-mirror.xyz \
|
||||
-d shop.ai-mirror.xyz \
|
||||
-d partner.ai-mirror.xyz \
|
||||
--non-interactive --agree-tos -m admin@ai-mirror.xyz
|
||||
fi
|
||||
|
||||
echo "==> 10. 配置 Nginx"
|
||||
cp "$DEPLOY_DIR/nginx-ai-mirror.conf" /etc/nginx/conf.d/dukang-ai-mirror.conf
|
||||
nginx -t
|
||||
systemctl reload nginx
|
||||
|
||||
echo "==> 部署完成"
|
||||
pm2 list
|
||||
ss -tlnp | grep -E '809[0-3]' || true
|
||||
Reference in New Issue
Block a user