chore: 统一环境配置,支持 .env 快速切换本地/远程基础设施

This commit is contained in:
2026-07-13 14:17:49 +08:00
parent 8c4deb5be4
commit 0bf48fd449
8 changed files with 273 additions and 57 deletions

View File

@@ -17,6 +17,17 @@ MCI_SERVER_PORT=${MCI_SERVER_PORT:-8080}
ADMIN_WEB_PORT=${ADMIN_WEB_PORT:-80}
CHANNEL_SERVICE_PORT=${CHANNEL_SERVICE_PORT:-8000}
# Docker Compose 内部连接必须使用容器名,覆盖 .env 中的 host 配置。
# 当用本脚本启动应用服务时,应用与基础设施在同一 Docker 网络。
dc() {
MYSQL_HOST=mci-mysql \
REDIS_HOST=mci-redis \
RABBITMQ_HOST=mci-rabbitmq \
SEAWEEDFS_HOST=mci-seaweedfs \
MCI_SERVER_URL=http://mci-server:8080/msg-platform \
docker compose "$@"
}
WITH_APPS=""
BUILD_FLAG=""
INIT_DATA=""
@@ -60,7 +71,7 @@ wait_for_healthy() {
echo "Waiting for $service to become healthy..."
while [ "$retry_count" -lt "$max_retries" ]; do
container_name=$(docker compose -p sino-mci --profile infra --profile app ps -q "$service" 2>/dev/null | head -n1 || true)
container_name=$(dc -p sino-mci --profile infra --profile app ps -q "$service" 2>/dev/null | head -n1 || true)
if [ -n "$container_name" ]; then
local status
@@ -76,7 +87,7 @@ wait_for_healthy() {
done
echo "$service did not become healthy within $((max_retries * 2)) seconds."
docker compose -p sino-mci --profile infra --profile app logs --tail=50 "$service"
dc -p sino-mci --profile infra --profile app logs --tail=50 "$service"
return 1
}
@@ -102,7 +113,7 @@ init_database() {
}
echo "Starting infrastructure services..."
docker compose -p sino-mci --profile infra up -d $BUILD_FLAG
dc -p sino-mci --profile infra up -d $BUILD_FLAG
wait_for_healthy mysql 60
wait_for_healthy redis 30
@@ -123,7 +134,7 @@ echo "SeaweedFS: http://localhost:${SEAWEEDFS_MASTER_PORT}"
if [ -n "$WITH_APPS" ]; then
echo "Starting application services..."
# Include infra profile so that depends_on conditions can resolve.
docker compose -p sino-mci --profile infra --profile app up -d $BUILD_FLAG
dc -p sino-mci --profile infra --profile app up -d $BUILD_FLAG
wait_for_healthy mci-server 90
wait_for_healthy channel-service 60