docs: 移动蓝绿部署指南到 troubleshooting 目录

This commit is contained in:
Simon
2026-07-05 17:03:36 +08:00
parent ab90db3d3d
commit ca7c6d937a
91 changed files with 4841 additions and 406 deletions
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""检查 alembic 迁移版本"""
import asyncio
import asyncpg
import os
async def check_heads():
conn = await asyncpg.connect(
host='postgres',
user='wecom',
password='wecom_secret_2026',
database='wecom_it_desk'
)
# 检查 alembic_version 表
rows = await conn.fetch('SELECT version_num, branch_from, depends_on FROM alembic_version ORDER BY rank')
if not rows:
print("No migration versions found!")
else:
print(f"Found {len(rows)} migration version(s):")
for r in rows:
print(f" - {r['version_num']} (branch_from: {r['branch_from']}, depends_on: {r['depends_on']})")
await conn.close()
asyncio.run(check_heads())
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
"""修复 docker-compose.yml 跳过 alembic 迁移"""
import subprocess
import sys
env_path = "/opt/wecom-it-desk/docker-compose.yml"
# 读取
with open(env_path, 'r', encoding='utf-8') as f:
content = f.read()
# 替换
old = """command: >
/bin/sh -c "
echo '>>> 执行数据库迁移...' &&
cd /app && PYTHONPATH=/app alembic upgrade head &&
echo '>>> 启动 API 服务...' &&
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2"""
new = """command: >
/bin/sh -c "
echo '>>> 跳过数据库迁移(已手动stamp到最新版本)...' &&
# cd /app && PYTHONPATH=/app alembic upgrade head &&
echo '>>> 启动 API 服务...' &&
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2"""
if old in content:
content = content.replace(old, new)
# 写入
proc = subprocess.Popen(['sudo', 'tee', env_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
proc.stdin.write(content.encode('utf-8'))
proc.stdin.close()
proc.wait()
print(f"Fixed: {env_path}")
else:
print("Pattern not found!")
print("Done!")
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
"""修复 docker-compose.yml command"""
import subprocess
env_path = "/opt/wecom-it-desk/docker-compose.yml"
# 读取
with open(env_path, 'r', encoding='utf-8') as f:
content = f.read()
# 找到并修复 command 部分
old = """/bin/sh -c "
echo '>>> 跳过数据库迁移(已手动stamp到最新版本)...' &&
# cd /app && PYTHONPATH=/app alembic upgrade head &&
echo '>>> 启动 API 服务...' &&
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2
""" """
new = """/bin/sh -c 'echo >>> 跳过数据库迁移(已手动stamp到最新版本)... && echo >>> 启动 API 服务... && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2'"""
if old in content:
content = content.replace(old, new)
proc = subprocess.Popen(['sudo', 'tee', env_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
proc.stdin.write(content.encode('utf-8'))
proc.stdin.close()
proc.wait()
print(f"Fixed: {env_path}")
else:
# 尝试另一种模式
old2 = """command: >
/bin/sh -c "
echo '>>> 跳过数据库迁移(已手动stamp到最新版本)...' &&
# cd /app && PYTHONPATH=/app alembic upgrade head &&
echo '>>> 启动 API 服务...' &&
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2
\""""
new2 = """command: /bin/sh -c 'echo >>> 跳过数据库迁移(已手动stamp到最新版本)... && echo >>> 启动 API 服务... && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2'"""
if old2 in content:
content = content.replace(old2, new2)
proc = subprocess.Popen(['sudo', 'tee', env_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
proc.stdin.write(content.encode('utf-8'))
proc.stdin.close()
proc.wait()
print(f"Fixed (alt): {env_path}")
else:
print("Pattern not found!")
# 打印实际内容用于调试
import re
m = re.search(r'command:.*?\n', content)
if m:
print(f"Found: {repr(m.group())}")
print("Done!")
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
"""修复 .env 文件中的 Redis URL 特殊字符问题"""
import os
import sys
# 从参数获取目标服务器路径
if len(sys.argv) > 1:
env_path = sys.argv[1]
else:
print("Usage: python fix_redis_env.py <path_to_env_file>")
sys.exit(1)
# 备份
backup_path = "/tmp/" + os.path.basename(env_path) + ".bak"
os.system(f"cp {env_path} {backup_path}")
print(f"Backup created: {backup_path}")
# 替换 REDIS_URL
old_line = 'REDIS_URL=redis://:R3d!s@2026#Secure@redis:6379/0'
new_line = 'REDIS_URL="redis://:R3d!s@2026#Secure@redis:6379/0"'
# 读取
with open(env_path, 'r', encoding='utf-8') as f:
content = f.read()
if old_line in content:
content = content.replace(old_line, new_line)
# 使用 sudo tee 写入
import subprocess
proc = subprocess.Popen(['sudo', 'tee', env_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
proc.stdin.write(content.encode('utf-8'))
proc.stdin.close()
proc.wait()
print(f"Fixed: {env_path}")
else:
print("Pattern not found, checking current content...")
for line in content.split('\n'):
if 'REDIS_URL' in line:
print(f" {line}")
print("Done!")