fix(release): support environment validation in containers
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 12s
Deploy / Deploy Staging (push) Successful in 1m54s
Deploy / Deploy Production (push) Has been skipped

This commit is contained in:
Xiaoxia AI
2026-06-21 12:39:40 +08:00
parent e36347210c
commit 1708401bcd
2 changed files with 20 additions and 4 deletions
+2 -1
View File
@@ -21,7 +21,8 @@
- `REDIS_URL` 指向生产 Redis。
- OSS 配置已确认或明确保持本地 fallback。
- `GENERATED_FILES_HOST_DIR` 生产环境不得指向 staging 目录。
- 本地校验:`python scripts/validate_release_env.py /var/lib/xiaoxia-saas-production/.env --strict-external`
- 本地校验文件`python scripts/validate_release_env.py /var/lib/xiaoxia-saas-production/.env --strict-external`
- 容器内校验已注入环境:`docker exec xiaoxia-api-production python /app/scripts/validate_release_env.py --from-environ --strict-external`
- 如开启邮件/session
- `ENABLE_EMAIL_DELIVERY=true` 前先验证 SMTP 凭证。
- `ENABLE_REDIS_SESSIONS=true` 前先验证 Redis 连通性。
+18 -3
View File
@@ -108,7 +108,12 @@ def validate(values: dict[str, str], strict_external: bool) -> list[str]:
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("env_file", type=Path)
parser.add_argument("env_file", type=Path, nargs="?", help="Env file to validate. Omit with --from-environ.")
parser.add_argument(
"--from-environ",
action="store_true",
help="Validate the current process environment instead of reading an env file.",
)
parser.add_argument(
"--strict-external",
action="store_true",
@@ -116,14 +121,24 @@ def main() -> int:
)
args = parser.parse_args()
values = parse_env_file(args.env_file)
if args.from_environ:
import os
values = dict(os.environ)
source = "process environment"
else:
if args.env_file is None:
parser.error("env_file is required unless --from-environ is set")
values = parse_env_file(args.env_file)
source = str(args.env_file)
errors = validate(values, args.strict_external)
if errors:
for error in errors:
print(f"ERROR: {error}")
return 1
print(f"OK: {args.env_file} passed release env validation")
print(f"OK: {source} passed release env validation")
return 0