Files
claude-relay-service/docker-entrypoint.sh
shaw 382efff867 fix: 简化为root用户运行,彻底解决权限问题
- 移除claude用户创建,直接使用root用户运行
- 删除所有复杂的权限设置和chown操作
- 恢复简单的sed命令修改配置文件
- 移除调试权限信息输出
- 简化Dockerfile,减少构建复杂度
- 确保所有文件操作都有完整权限

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-19 02:48:35 +08:00

88 lines
2.6 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/sh
set -e
echo "🚀 Claude Relay Service 启动中..."
# 生成随机字符串的函数
generate_random_string() {
length=$1
# 使用 /dev/urandom 生成随机字符串
tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c $length
}
# 检查并复制配置文件
if [ ! -f "/app/config/config.js" ]; then
echo "📋 检测到 config.js 不存在,从模板创建..."
if [ -f "/app/config/config.example.js" ]; then
cp /app/config/config.example.js /app/config/config.js
echo "✅ config.js 已创建"
else
echo "❌ 错误: config.example.js 不存在"
exit 1
fi
fi
# 检查并配置 .env 文件(文件已在构建时创建)
if [ -f "/app/.env" ]; then
echo "📋 配置 .env 文件..."
# 生成随机的 JWT_SECRET (64字符)
if [ -z "$JWT_SECRET" ]; then
JWT_SECRET=$(grep "^JWT_SECRET=" /app/.env | cut -d'=' -f2)
if [ -z "$JWT_SECRET" ] || [ "$JWT_SECRET" = "your-jwt-secret-here" ]; then
JWT_SECRET=$(generate_random_string 64)
echo "🔑 生成 JWT_SECRET"
fi
fi
# 生成随机的 ENCRYPTION_KEY (32字符)
if [ -z "$ENCRYPTION_KEY" ]; then
ENCRYPTION_KEY=$(grep "^ENCRYPTION_KEY=" /app/.env | cut -d'=' -f2)
if [ -z "$ENCRYPTION_KEY" ] || [ "$ENCRYPTION_KEY" = "your-encryption-key-here" ]; then
ENCRYPTION_KEY=$(generate_random_string 32)
echo "🔑 生成 ENCRYPTION_KEY"
fi
fi
# 直接使用sed修改.env文件 - root用户无权限问题
sed -i "s/JWT_SECRET=.*/JWT_SECRET=${JWT_SECRET}/" /app/.env
sed -i "s/ENCRYPTION_KEY=.*/ENCRYPTION_KEY=${ENCRYPTION_KEY}/" /app/.env
sed -i "s/REDIS_HOST=.*/REDIS_HOST=redis/" /app/.env
echo "✅ .env 已配置"
else
echo "❌ 错误: .env 文件不存在"
exit 1
fi
# 导出环境变量
export JWT_SECRET
export ENCRYPTION_KEY
# 检查是否需要初始化
if [ ! -f "/app/data/init.json" ]; then
echo "📋 首次启动,执行初始化设置..."
# 如果设置了环境变量,显示提示
if [ -n "$ADMIN_USERNAME" ] || [ -n "$ADMIN_PASSWORD" ]; then
echo "📌 检测到预设的管理员凭据"
fi
# 执行初始化脚本
node /app/scripts/setup.js
echo "✅ 初始化完成"
else
echo "✅ 检测到已有配置,跳过初始化"
# 如果 init.json 存在但环境变量也设置了,显示警告
if [ -n "$ADMIN_USERNAME" ] || [ -n "$ADMIN_PASSWORD" ]; then
echo "⚠️ 警告: 检测到环境变量 ADMIN_USERNAME/ADMIN_PASSWORD但系统已初始化"
echo " 如需使用新凭据,请删除 data/init.json 文件后重启容器"
fi
fi
# 启动应用
echo "🌐 启动 Claude Relay Service..."
exec "$@"