"""Generate a local .env using only Docker's Python image (no host Python needed).""" import os import secrets from pathlib import Path root=Path(__file__).resolve().parent.parent config=root/'.env' if config.exists(): print('已存在 .env:为了防止覆盖现有密码和密钥,本次不做修改。') raise SystemExit(0) password=secrets.token_urlsafe(24) secret=secrets.token_urlsafe(48) config.write_text(f'''# SiteForge Web Docker v0.3 - 不要上传至代码仓库\nSITEFORGE_PORT=8787\nSITEFORGE_ADMIN_PASSWORD={password}\nSITEFORGE_SESSION_SECRET={secret}\nSITEFORGE_COOKIE_SECURE=false\nSITEFORGE_DOMAIN=siteforge.example.com\n''', encoding='utf-8') try:os.chmod(config,0o600) except OSError:pass print('SiteForge 已生成 .env 配置。') print('首次登录管理员密码:'+password) print('请将密码保存在安全的位置,忘记后可编辑 .env 的密码并重启容器。') print('本机启动命令:docker compose up -d --build')