62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""AlphaX Docker 副本离线布局校验。"""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
errors = []
|
|
warnings = []
|
|
|
|
required_files = [
|
|
"Dockerfile",
|
|
"docker-compose.yml",
|
|
"requirements.txt",
|
|
".env.example",
|
|
".dockerignore",
|
|
"docker/entrypoint.sh",
|
|
"docker/scheduler.py",
|
|
"README_DOCKER.md",
|
|
]
|
|
for rel in required_files:
|
|
if not (ROOT / rel).exists():
|
|
errors.append({"rule": "missing_file", "path": rel})
|
|
|
|
compose = (ROOT / "docker-compose.yml").read_text(errors="ignore") if (ROOT / "docker-compose.yml").exists() else ""
|
|
for needle in ["8191:8190", "DATABASE_URL", "ALPHAX_DB_BACKEND: \"postgres\"", "ALPHAX_SCHEDULER_DRY_RUN"]:
|
|
if needle not in compose:
|
|
errors.append({"rule": "compose_missing_expected_setting", "needle": needle})
|
|
|
|
entrypoint = ROOT / "docker/entrypoint.sh"
|
|
if entrypoint.exists() and not os.access(entrypoint, os.X_OK):
|
|
errors.append({"rule": "entrypoint_not_executable", "path": str(entrypoint)})
|
|
|
|
ignore = (ROOT / ".dockerignore").read_text(errors="ignore") if (ROOT / ".dockerignore").exists() else ""
|
|
for needle in ["data/", "archive/", "*.db", ".env"]:
|
|
if needle not in ignore:
|
|
warnings.append({"rule": "dockerignore_missing_recommended_pattern", "needle": needle})
|
|
|
|
# 镜像上下文不应包含真实 DB / 大备份;它们应在 data/archive 并被 .dockerignore 排除。
|
|
root_db = list(ROOT.glob("*.db")) + list(ROOT.glob("*.db-wal")) + list(ROOT.glob("*.db-shm"))
|
|
if root_db:
|
|
warnings.append({"rule": "root_db_files_present", "files": [p.name for p in root_db]})
|
|
|
|
# 不应残留 Hermes venv 绝对路径作为运行依赖。
|
|
hermes_refs = []
|
|
for p in ROOT.glob("*.py"):
|
|
txt = p.read_text(errors="ignore")
|
|
if "/home/ubuntu/.hermes" in txt:
|
|
hermes_refs.append(p.name)
|
|
if hermes_refs:
|
|
errors.append({"rule": "hermes_path_reference_in_py", "files": hermes_refs})
|
|
|
|
summary = {
|
|
"root": str(ROOT),
|
|
"errors": errors,
|
|
"warnings": warnings,
|
|
"has_data_db": (ROOT / "data" / "altcoin_monitor.db").exists(),
|
|
}
|
|
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
|
if errors:
|
|
raise SystemExit(1)
|