baodan/scripts/deploy/entrypoint.sh
2026-07-23 08:52:59 +08:00

46 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 自定义入口脚本
# 在原始入口脚本基础上添加自动初始化功能
set -e
# 设置 UTF-8 编码
export LANG=${LANG:-C.UTF-8}
export LC_ALL=${LC_ALL:-C.UTF-8}
export PYTHONIOENCODING=${PYTHONIOENCODING:-utf-8}
# 恢复 RSA 私钥到 volume镜像备份 → /app/api/storage/
if [ -d "/app/privkeys_backup" ] && [ ! -d "/app/api/storage/privkeys" ]; then
echo "Restoring RSA private keys..."
cp -r /app/privkeys_backup /app/api/storage/privkeys
echo "RSA private keys restored"
fi
# 恢复上传文件到 volume
if [ -d "/app/upload_files_backup" ] && [ ! -d "/app/api/storage/upload_files" ]; then
echo "Restoring upload files..."
cp -r /app/upload_files_backup /app/api/storage/upload_files
echo "Upload files restored"
fi
# 运行数据库迁移
if [[ "${MIGRATION_ENABLED}" == "true" ]]; then
echo "Running migrations"
flask upgrade-db
echo "Database migration completed"
fi
# 自动初始化管理员账号(仅在 API 模式下)
if [[ "${MODE}" != "worker" && "${MODE}" != "migration" ]]; then
echo "Running auto initialization..."
python /app/scripts/auto_init.py || echo "Auto init failed or skipped"
fi
# 确保 insurance Blueprint 已注册(运行时补丁)
echo "Patching app.py for insurance module..."
python /app/scripts/patch_app.py || echo "Patch failed or already applied"
# 执行原始命令(启动 API 服务器或 Worker
exec "$@"