Compare commits
2 Commits
8b7222127c
...
fb703c8b85
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb703c8b85 | ||
|
|
70816b6ebe |
10
README.md
10
README.md
@ -119,7 +119,7 @@ pnpm dev:api
|
|||||||
- 审核冻结分支:`pre4`(**微信审核包,勿在本分支继续功能迭代**)
|
- 审核冻结分支:`pre4`(**微信审核包,勿在本分支继续功能迭代**)
|
||||||
- `pre5`:承接 pre4 之后的功能(含游民社区 `/social`)
|
- `pre5`:承接 pre4 之后的功能(含游民社区 `/social`)
|
||||||
- `test5` / `test6`:游民社区实时层与 H5 初版(已合入后续分支)
|
- `test5` / `test6`:游民社区实时层与 H5 初版(已合入后续分支)
|
||||||
- **当前发版分支:`test7`**(游民社区 H5 深优);下一轮开发切 **`test8`**
|
- **当前开发分支:`test8`**(从 `test7` 拉出);发版线 `test7` 已含 H5 深优
|
||||||
|
|
||||||
### 游民社区(`/social`)
|
### 游民社区(`/social`)
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ pnpm dev:api
|
|||||||
- **MiroTalk**:钉死 82 `.cn`、白标中文、极速进房
|
- **MiroTalk**:钉死 82 `.cn`、白标中文、极速进房
|
||||||
- **视觉**:T1 默认;T2 代码保留、切换器隐藏
|
- **视觉**:T1 默认;T2 代码保留、切换器隐藏
|
||||||
|
|
||||||
## test6 / test7(当前发版)
|
## test6 / test7(已发版)
|
||||||
|
|
||||||
游民社区 `/social` 手机端深优(门户 `h5.css` 最后加载):
|
游民社区 `/social` 手机端深优(门户 `h5.css` 最后加载):
|
||||||
|
|
||||||
@ -180,9 +180,11 @@ pnpm dev:api
|
|||||||
- **首屏**:群组聊天在左、认识一下在右;窄屏收掉宇宙轨道,Ways 进首视口
|
- **首屏**:群组聊天在左、认识一下在右;窄屏收掉宇宙轨道,Ways 进首视口
|
||||||
- **滑卡 / 群聊**:手机更低滑动阈值、震动反馈;composer / 加入 sheet 全宽底栏
|
- **滑卡 / 群聊**:手机更低滑动阈值、震动反馈;composer / 加入 sheet 全宽底栏
|
||||||
- **Meetup**:活动卡保留参与者头像 + 声纹条
|
- **Meetup**:活动卡保留参与者头像 + 声纹条
|
||||||
- **发版**:`python deploy/social/deploy_82.py`(仅 82);冒烟 `https://nomadro.cn/social`
|
- **发版**:`python deploy/social/deploy_82.py`(仅 82;**2C/4G**:堆 1536MB + swap + nice;打包跳过 `__pycache__`;勿并发 SSH);冒烟 `https://nomadro.cn/social`
|
||||||
|
|
||||||
下一轮:`test8`(从 `test7` 拉出)。后续还可做:课时资料后台可视化、桥接 UX、真机网络/域名排查。
|
## test8(当前开发)
|
||||||
|
|
||||||
|
从 `test7` 切出,承接后续 `/social` 与门户迭代。后续还可做:课时资料后台可视化、桥接 UX、真机网络/域名排查。
|
||||||
|
|
||||||
## pre3 摘要(已合入)
|
## pre3 摘要(已合入)
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,13 @@ pnpm dev
|
|||||||
|
|
||||||
## 线上增量(只部署 82)
|
## 线上增量(只部署 82)
|
||||||
|
|
||||||
|
生产机规格:**2C / 4G**。发版铁律(防 OOM 挂机):
|
||||||
|
|
||||||
|
- **禁止** `NODE_OPTIONS=--max-old-space-size=4096`(会吃光内存)
|
||||||
|
- `deploy/social/deploy_82.py` 默认堆 **1536MB** + `nice`/`ionice` + 确保 **2G swap**
|
||||||
|
- 构建失败会回滚上一份 `.next`;构建期间只停 `nomadro.service`
|
||||||
|
- **禁止**并行多次 SSH / 并发跑 deploy;一次发版一条会话
|
||||||
|
|
||||||
生产铁律:[`https://nomadro.cn`](https://nomadro.cn/) / MiroTalk / API / Centrifugo **全部在 `82.157.112.245`**,进房用 `mirotalk.nomadro.cn`。
|
生产铁律:[`https://nomadro.cn`](https://nomadro.cn/) / MiroTalk / API / Centrifugo **全部在 `82.157.112.245`**,进房用 `mirotalk.nomadro.cn`。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -54,7 +61,7 @@ python deploy/social/deploy_82.py
|
|||||||
- `NEXT_PUBLIC_MIROTALK_URL=https://mirotalk.nomadro.cn`(`/etc/nomadro/portal.env`)
|
- `NEXT_PUBLIC_MIROTALK_URL=https://mirotalk.nomadro.cn`(`/etc/nomadro/portal.env`)
|
||||||
- Centrifugo:`CENTRIFUGO_*`(见 `/etc/nomadro/centrifugo.env`,可并入 `portal.env`)
|
- Centrifugo:`CENTRIFUGO_*`(见 `/etc/nomadro/centrifugo.env`,可并入 `portal.env`)
|
||||||
|
|
||||||
**前端发版**:先本地 `pnpm dev` 验收 `/social`;**未经负责人允许不上线**门户 `.next`。当前发版线:`test7`(H5 深优见根 `README.md`);下一轮 `test8`。
|
**前端发版**:先本地 `pnpm dev` 验收 `/social`;**未经负责人允许不上线**门户 `.next`。发版线:`test7`(H5 深优见根 `README.md`);当前开发:`test8`。
|
||||||
|
|
||||||
**H5(≤900px)**:`src/modules/social/app/h5.css` 最后加载;Ways 竖列表(群组聊天优先)、底栏聊天在「认识」左侧、滑卡/composer 避开 dock。
|
**H5(≤900px)**:`src/modules/social/app/h5.css` 最后加载;Ways 竖列表(群组聊天优先)、底栏聊天在「认识」左侧、滑卡/composer 避开 dock。
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,19 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Deploy 游民社区 + MiroTalk(.cn) portal bits to 82.157.112.245 only."""
|
"""Deploy 游民社区 portal bits to 82.157.112.245 — safe for 2C/4G.
|
||||||
|
|
||||||
|
Guardrails:
|
||||||
|
- single SSH session
|
||||||
|
- skip __pycache__ / node_modules in pack
|
||||||
|
- ensure 2G swap before build
|
||||||
|
- Node heap capped at 1536MB (never 4096 on 4G box)
|
||||||
|
- build niceness + single-threaded-ish Next
|
||||||
|
- keep site down only for the build window; always try start in finally
|
||||||
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import tarfile
|
import tarfile
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import paramiko
|
import paramiko
|
||||||
@ -15,12 +23,12 @@ USER = "ubuntu"
|
|||||||
PASS = "Xiao4669805"
|
PASS = "Xiao4669805"
|
||||||
APP = "/var/www/nomadro.cn"
|
APP = "/var/www/nomadro.cn"
|
||||||
ROOT = Path(__file__).resolve().parents[2]
|
ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
# 2C/4G: keep Node well under RAM so kernel + nginx survive
|
||||||
|
NODE_HEAP_MB = 1536
|
||||||
|
|
||||||
# Paths relative to repo root
|
|
||||||
INCLUDE = [
|
INCLUDE = [
|
||||||
"src/modules/social",
|
"src/modules/social",
|
||||||
"src/app/social",
|
"src/app/social",
|
||||||
"src/modules/social/lib/seed.ts", # covered by tree
|
|
||||||
"src/lib/remote-config.ts",
|
"src/lib/remote-config.ts",
|
||||||
"src/components/sections/hero.tsx",
|
"src/components/sections/hero.tsx",
|
||||||
"src/app/layout.tsx",
|
"src/app/layout.tsx",
|
||||||
@ -37,6 +45,8 @@ INCLUDE = [
|
|||||||
"README.md",
|
"README.md",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
_SKIP_DIR = {"__pycache__", "node_modules", ".next", ".git"}
|
||||||
|
|
||||||
|
|
||||||
def connect() -> paramiko.SSHClient:
|
def connect() -> paramiko.SSHClient:
|
||||||
c = paramiko.SSHClient()
|
c = paramiko.SSHClient()
|
||||||
@ -48,7 +58,8 @@ def connect() -> paramiko.SSHClient:
|
|||||||
timeout=40,
|
timeout=40,
|
||||||
allow_agent=False,
|
allow_agent=False,
|
||||||
look_for_keys=False,
|
look_for_keys=False,
|
||||||
banner_timeout=120,
|
banner_timeout=90,
|
||||||
|
auth_timeout=40,
|
||||||
)
|
)
|
||||||
t = c.get_transport()
|
t = c.get_transport()
|
||||||
if t:
|
if t:
|
||||||
@ -56,16 +67,13 @@ def connect() -> paramiko.SSHClient:
|
|||||||
return c
|
return c
|
||||||
|
|
||||||
|
|
||||||
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 1200) -> tuple[str, int]:
|
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 1800) -> tuple[str, int]:
|
||||||
_i, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
_i, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
||||||
out = o.read().decode("utf-8", "ignore")
|
out = o.read().decode("utf-8", "ignore")
|
||||||
code = o.channel.recv_exit_status()
|
code = o.channel.recv_exit_status()
|
||||||
return out, code
|
return out, code
|
||||||
|
|
||||||
|
|
||||||
_SKIP_DIR = {"__pycache__", "node_modules", ".next", ".git"}
|
|
||||||
|
|
||||||
|
|
||||||
def _add_tree(tar: tarfile.TarFile, path: Path, arcname: str) -> None:
|
def _add_tree(tar: tarfile.TarFile, path: Path, arcname: str) -> None:
|
||||||
if path.is_file():
|
if path.is_file():
|
||||||
if path.suffix == ".pyc":
|
if path.suffix == ".pyc":
|
||||||
@ -102,24 +110,44 @@ def pack() -> Path:
|
|||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
archive = pack()
|
archive = pack()
|
||||||
|
print("connecting (single session)...", flush=True)
|
||||||
c = connect()
|
c = connect()
|
||||||
print("connected")
|
print("connected", flush=True)
|
||||||
|
|
||||||
# upload
|
|
||||||
sftp = c.open_sftp()
|
sftp = c.open_sftp()
|
||||||
sftp.put(str(archive), "/tmp/social82.tgz")
|
sftp.put(str(archive), "/tmp/social82.tgz")
|
||||||
sftp.close()
|
sftp.close()
|
||||||
print("uploaded")
|
print("uploaded", flush=True)
|
||||||
|
|
||||||
# extract into app (preserve remote-config backup)
|
|
||||||
script = f"""
|
script = f"""
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
cd {APP}
|
APP='{APP}'
|
||||||
|
HEAP={NODE_HEAP_MB}
|
||||||
|
|
||||||
|
echo '=== preflight 2C/4G ==='
|
||||||
|
uptime
|
||||||
|
free -h | head -2
|
||||||
|
|
||||||
|
# swap (idempotent)
|
||||||
|
if ! swapon --show | grep -q .; then
|
||||||
|
if [ ! -f /swapfile ]; then
|
||||||
|
sudo fallocate -l 2G /swapfile || sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=none
|
||||||
|
sudo chmod 600 /swapfile
|
||||||
|
sudo mkswap /swapfile
|
||||||
|
fi
|
||||||
|
sudo swapon /swapfile || true
|
||||||
|
fi
|
||||||
|
grep -q '/swapfile' /etc/fstab || echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab >/dev/null
|
||||||
|
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-nomadro-swap.conf >/dev/null
|
||||||
|
sudo sysctl -p /etc/sysctl.d/99-nomadro-swap.conf >/dev/null || true
|
||||||
|
free -h | head -2
|
||||||
|
|
||||||
|
cd "$APP"
|
||||||
sudo cp -a data/remote-config.json /tmp/remote-config.pre-social.json || true
|
sudo cp -a data/remote-config.json /tmp/remote-config.pre-social.json || true
|
||||||
sudo chown -R ubuntu:ubuntu {APP}
|
sudo chown -R ubuntu:ubuntu "$APP"
|
||||||
find {APP}/apps/api/services/social_svc -type d -name '__pycache__' -prune -exec rm -rf {{}} + 2>/dev/null || true
|
find "$APP/apps/api/services/social_svc" -type d -name '__pycache__' -prune -exec rm -rf {{}} + 2>/dev/null || true
|
||||||
tar -xzf /tmp/social82.tgz --no-same-owner
|
tar -xzf /tmp/social82.tgz --no-same-owner
|
||||||
# restore operational remote-config then merge social module key via python
|
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -128,14 +156,12 @@ live = app / 'data' / 'remote-config.json'
|
|||||||
bak = Path('/tmp/remote-config.pre-social.json')
|
bak = Path('/tmp/remote-config.pre-social.json')
|
||||||
incoming = json.loads(live.read_text(encoding='utf-8')) if live.exists() else {{}}
|
incoming = json.loads(live.read_text(encoding='utf-8')) if live.exists() else {{}}
|
||||||
base = json.loads(bak.read_text(encoding='utf-8')) if bak.exists() else {{}}
|
base = json.loads(bak.read_text(encoding='utf-8')) if bak.exists() else {{}}
|
||||||
# keep live ops flags; ensure modules.social exists from incoming
|
|
||||||
mods = base.setdefault('modules', {{}}) if isinstance(base, dict) else {{}}
|
mods = base.setdefault('modules', {{}}) if isinstance(base, dict) else {{}}
|
||||||
inc_mods = incoming.get('modules') if isinstance(incoming, dict) else {{}}
|
inc_mods = incoming.get('modules') if isinstance(incoming, dict) else {{}}
|
||||||
if isinstance(inc_mods, dict) and 'social' in inc_mods:
|
if isinstance(inc_mods, dict) and 'social' in inc_mods:
|
||||||
mods['social'] = inc_mods['social']
|
mods['social'] = inc_mods['social']
|
||||||
elif 'social' not in mods:
|
elif 'social' not in mods:
|
||||||
mods['social'] = {{'enabled': True, 'title': '游民社区', 'tabLabel': '社区'}}
|
mods['social'] = {{'enabled': True, 'title': '游民社区', 'tabLabel': '社区'}}
|
||||||
# prefer base (prod) as SoT with social injected
|
|
||||||
if isinstance(base, dict):
|
if isinstance(base, dict):
|
||||||
base['modules'] = mods
|
base['modules'] = mods
|
||||||
live.write_text(json.dumps(base, ensure_ascii=False, indent=2) + '\\n', encoding='utf-8')
|
live.write_text(json.dumps(base, ensure_ascii=False, indent=2) + '\\n', encoding='utf-8')
|
||||||
@ -144,7 +170,6 @@ else:
|
|||||||
print('kept incoming remote-config')
|
print('kept incoming remote-config')
|
||||||
PY
|
PY
|
||||||
|
|
||||||
# portal env: force MiroTalk on 82 .cn
|
|
||||||
sudo mkdir -p /etc/nomadro
|
sudo mkdir -p /etc/nomadro
|
||||||
if [ -f /etc/nomadro/portal.env ]; then
|
if [ -f /etc/nomadro/portal.env ]; then
|
||||||
sudo grep -q '^NEXT_PUBLIC_MIROTALK_URL=' /etc/nomadro/portal.env \\
|
sudo grep -q '^NEXT_PUBLIC_MIROTALK_URL=' /etc/nomadro/portal.env \\
|
||||||
@ -153,28 +178,54 @@ if [ -f /etc/nomadro/portal.env ]; then
|
|||||||
else
|
else
|
||||||
echo 'NEXT_PUBLIC_MIROTALK_URL=https://mirotalk.nomadro.cn' | sudo tee /etc/nomadro/portal.env >/dev/null
|
echo 'NEXT_PUBLIC_MIROTALK_URL=https://mirotalk.nomadro.cn' | sudo tee /etc/nomadro/portal.env >/dev/null
|
||||||
fi
|
fi
|
||||||
grep MIROTALK /etc/nomadro/portal.env || true
|
|
||||||
|
|
||||||
# .next often root-owned from prior deploys — clear then build as ubuntu
|
# stop portal only for build; always restart
|
||||||
|
cleanup() {{
|
||||||
|
sudo systemctl start nomadro.service || true
|
||||||
|
}}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
sudo systemctl stop nomadro.service || true
|
sudo systemctl stop nomadro.service || true
|
||||||
sudo chown -R ubuntu:ubuntu {APP}
|
sudo chown -R ubuntu:ubuntu "$APP"
|
||||||
sudo rm -rf {APP}/.next
|
# keep previous .next as fallback until new build succeeds
|
||||||
export NODE_OPTIONS=--max-old-space-size=4096
|
if [ -d "$APP/.next" ]; then
|
||||||
/usr/local/bin/pnpm build
|
rm -rf /tmp/nomadro.next.bak
|
||||||
test -f .next/BUILD_ID
|
mv "$APP/.next" /tmp/nomadro.next.bak
|
||||||
echo BUILD_ID=$(cat .next/BUILD_ID)
|
fi
|
||||||
|
|
||||||
|
export NODE_OPTIONS="--max-old-space-size=$HEAP"
|
||||||
|
export NEXT_TELEMETRY_DISABLED=1
|
||||||
|
export UV_THREADPOOL_SIZE=2
|
||||||
|
export CI=1
|
||||||
|
echo "building heap=${{HEAP}}MB nice=15"
|
||||||
|
# low priority so sshd/nginx stay responsive
|
||||||
|
set +e
|
||||||
|
nice -n 15 ionice -c2 -n7 /usr/local/bin/pnpm build
|
||||||
|
BUILD_CODE=$?
|
||||||
|
set -e
|
||||||
|
if [ "$BUILD_CODE" -ne 0 ] || [ ! -f "$APP/.next/BUILD_ID" ]; then
|
||||||
|
echo "BUILD FAILED code=$BUILD_CODE — restoring previous .next"
|
||||||
|
rm -rf "$APP/.next"
|
||||||
|
if [ -d /tmp/nomadro.next.bak ]; then
|
||||||
|
mv /tmp/nomadro.next.bak "$APP/.next"
|
||||||
|
fi
|
||||||
|
exit "$BUILD_CODE"
|
||||||
|
fi
|
||||||
|
rm -rf /tmp/nomadro.next.bak
|
||||||
|
echo BUILD_ID=$(cat "$APP/.next/BUILD_ID")
|
||||||
|
|
||||||
sudo systemctl start nomadro.service
|
sudo systemctl start nomadro.service
|
||||||
sleep 5
|
trap - EXIT
|
||||||
|
sleep 4
|
||||||
systemctl is-active nomadro.service
|
systemctl is-active nomadro.service
|
||||||
curl -sk -o /dev/null -w 'home %{{http_code}}\\n' https://nomadro.cn/
|
curl -sk -m 10 -o /dev/null -w 'home %{{http_code}}\\n' https://nomadro.cn/ || true
|
||||||
curl -sk -o /dev/null -w 'social %{{http_code}}\\n' https://nomadro.cn/social
|
curl -sk -m 10 -o /dev/null -w 'social %{{http_code}}\\n' https://nomadro.cn/social || true
|
||||||
curl -sk -o /dev/null -w 'meetup %{{http_code}}\\n' https://nomadro.cn/social/meetup
|
curl -sk -m 10 -o /dev/null -w 'meetup %{{http_code}}\\n' https://nomadro.cn/social/meetup || true
|
||||||
curl -sk -o /dev/null -w 'mirotalk_cn %{{http_code}} %{{time_total}}\\n' 'https://mirotalk.nomadro.cn/join?room=t&name=t¬ify=0'
|
|
||||||
echo DONE
|
echo DONE
|
||||||
"""
|
"""
|
||||||
print("building on 82 (may take several minutes)...")
|
print("building on 82 (low-mem mode)...", flush=True)
|
||||||
out, code = run(c, script, timeout=1500)
|
out, code = run(c, script, timeout=2400)
|
||||||
print(out[-8000:] if len(out) > 8000 else out)
|
print(out[-10000:] if len(out) > 10000 else out)
|
||||||
c.close()
|
c.close()
|
||||||
try:
|
try:
|
||||||
archive.unlink()
|
archive.unlink()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user