aidress/entrypoint.sh
2025-03-21 21:59:44 +08:00

52 lines
1.7 KiB
Bash
Executable File
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
echo "============= 容器启动 ============="
echo "当前工作目录: $(pwd)"
echo "目录内容:"
ls -la
# 优先级1: 尝试从.env文件加载
if [ -f .env ]; then
echo "找到.env文件加载环境变量..."
# 打印文件内容(隐藏敏感信息)
echo "文件内容预览(敏感信息已隐藏):"
grep -v "KEY\|PASSWORD\|SECRET" .env | cat -n
# 从.env文件导出所有环境变量
export $(grep -v '^#' .env | xargs)
echo "已从.env加载环境变量"
elif [ -f /app/.env ]; then
echo "在/app目录下找到.env文件加载环境变量..."
export $(grep -v '^#' /app/.env | xargs)
echo "已从/app/.env加载环境变量"
elif [ -f .env.docker ]; then
echo "找到.env.docker文件加载环境变量..."
export $(grep -v '^#' .env.docker | xargs)
echo "已从.env.docker加载环境变量"
else
echo ".env文件不存在环境变量将从Docker环境中读取..."
fi
# 打印环境变量,确认是否已正确加载
echo "============= 环境变量检查 ============="
echo "DB_HOST: $DB_HOST"
echo "DB_PORT: $DB_PORT"
echo "DB_USER: $DB_USER"
echo "DB_NAME: $DB_NAME"
echo "DASHSCOPE_API_KEY是否存在: $(if [ -n "$DASHSCOPE_API_KEY" ]; then echo "是"; else echo "否"; fi)"
echo "QCLOUD_SECRET_ID是否存在: $(if [ -n "$QCLOUD_SECRET_ID" ]; then echo "是"; else echo "否"; fi)"
# 确保Python能找到应用
export PYTHONPATH=/app:$PYTHONPATH
echo "============= Python环境 ============="
echo "Python版本: $(python --version)"
echo "Python路径: $(which python)"
echo "PYTHONPATH: $PYTHONPATH"
echo "============= 启动应用 ============="
echo "执行命令: $@"
# 执行原始的命令
exec "$@"