Files
CloudSearch/source_clean/deploy.sh

57 lines
1.8 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
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# 如果 docker-compose.yml 不存在,自动下载
if [ ! -f docker-compose.yml ]; then
echo "📥 下载 docker-compose.yml..."
wget -q https://gitea.timxx.cn/admin/CloudSearch/raw/branch/master/source_clean/docker-compose.yml
fi
echo "🔍 检测 Redis..."
EXISTING_REDIS=$(docker ps --format '{{.Names}}' | grep -i redis | head -1)
if [ -n "$EXISTING_REDIS" ]; then
if docker network inspect cloudsearch-net --format '{{range .Containers}}{{.Name}} {{end}}' 2>/dev/null | grep -qw "$EXISTING_REDIS"; then
echo "✅ 已有 Redis: $EXISTING_REDIS (已加入 cloudsearch-net),跳过创建"
else
echo "✅ 已有 Redis: $EXISTING_REDIS,正在加入网络..."
docker network connect cloudsearch-net "$EXISTING_REDIS" 2>/dev/null || true
echo " ✅ 已加入 cloudsearch-net"
fi
# 检测 Redis 密码
REDIS_PASS=$(docker inspect "$EXISTING_REDIS" --format '{{range .Config.Cmd}}{{println .}}{{end}}' 2>/dev/null | grep -A1 'requirepass' | tail -1 || true)
if [ -n "$REDIS_PASS" ]; then
REDIS_URL="redis://:${REDIS_PASS}@${EXISTING_REDIS}:6379"
echo " 🔑 检测到 Redis 密码,已自动配置"
else
REDIS_URL="redis://${EXISTING_REDIS}:6379"
fi
PROFILE=""
else
echo "📦 未检测到 Redis将自动创建..."
REDIS_URL="redis://CloudSearch_Redis:6379"
PROFILE="--profile full"
fi
# 生成 .env
cat > .env <<EOF
REDIS_URL=${REDIS_URL}
CORS_ORIGIN=https://zy.hk.timxx.cn
JWT_SECRET=cloudsearch-jwt-secret-2024
ADMIN_PASSWORD=0nL5kLhMIJ1121PYmQb25A
LOG_LEVEL=info
EOF
echo ""
echo "🚀 启动服务..."
docker compose $PROFILE up -d
echo ""
echo "✅ 部署完成"
docker compose ps