@@ -54,7 +54,7 @@ function check_config_dir {
5454 if [ ! -d " config/$env " ]; then
5555 echo -e " ${YELLOW} 配置目录 config/$env 不存在,正在创建...${NC} "
5656 mkdir -p config/$env
57-
57+
5858 # 如果没有环境配置文件,从示例文件复制
5959 if [ ! -f " config/$env /.env" ]; then
6060 if [ -f " .env_example" ]; then
@@ -70,11 +70,11 @@ function check_config_dir {
7070
7171# 检查并创建外部网络
7272function ensure_network_exists {
73- if ! docker network ls | grep -q sandbox-network; then
74- echo -e " ${YELLOW} 创建外部网络 sandbox-network...${NC} "
75- docker network create sandbox-network
73+ if ! docker network ls | grep -q magic- sandbox-network; then
74+ echo -e " ${YELLOW} 创建外部网络 magic- sandbox-network...${NC} "
75+ docker network create magic- sandbox-network
7676 else
77- echo -e " ${GREEN} 外部网络 sandbox-network 已存在${NC} "
77+ echo -e " ${GREEN} 外部网络 magic- sandbox-network 已存在${NC} "
7878 fi
7979}
8080
@@ -87,15 +87,15 @@ function start_env {
8787 local debug
8888 local redis_port
8989 local redis_db
90-
90+
9191 # 检查配置目录
9292 check_config_dir $env
93-
93+
9494 # 确保外部网络存在
9595 ensure_network_exists
96-
96+
9797 echo -e " ${GREEN} 正在启动 $env 环境...${NC} "
98-
98+
9999 case $env in
100100 test)
101101 port=8001
@@ -122,7 +122,7 @@ function start_env {
122122 debug=" false"
123123 ;;
124124 esac
125-
125+
126126 # 检查Redis容器是否已存在
127127 if docker ps -a | grep -q " api-gateway-redis" ; then
128128 echo -e " ${YELLOW} Redis容器 api-gateway-redis 已存在,跳过创建...${NC} "
@@ -134,13 +134,13 @@ function start_env {
134134 else
135135 echo -e " ${YELLOW} 创建Redis容器...${NC} "
136136 # 直接启动Redis容器,不通过docker-compose
137- docker run -d --name api-gateway-redis --network sandbox-network -p ${redis_port} :6379 -v $( pwd) /redis_data:/data redis:alpine redis-server --appendonly yes
137+ docker run -d --name api-gateway-redis --network magic- sandbox-network -p ${redis_port} :6379 -v $( pwd) /redis_data:/data redis:alpine redis-server --appendonly yes
138138 fi
139-
139+
140140 # 获取Redis容器的IP地址
141141 local redis_ip=$( docker inspect -f ' {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' api-gateway-redis)
142142 echo -e " ${YELLOW} Redis容器IP地址: ${redis_ip}${NC} "
143-
143+
144144 # 创建临时的docker-compose重写文件
145145 cat > docker-compose.override.yml << EOF
146146services:
@@ -153,13 +153,13 @@ services:
153153 magic-redis:
154154 profiles: ["disabled"]
155155EOF
156-
156+
157157 ENV=$env PORT=$port MAGIC_GATEWAY_PORT=$port MAGIC_GATEWAY_API_KEY=$api_key JWT_SECRET=$jwt_secret MAGIC_GATEWAY_DEBUG=$debug \
158158 docker compose -p magic-gateway-$env up -d --build
159-
159+
160160 # 移除临时文件
161161 rm docker-compose.override.yml
162-
162+
163163 echo -e " ${GREEN} $env 环境已启动,访问地址: http://localhost:$port ${NC} "
164164 echo -e " ${GREEN} Redis信息: IP=${redis_ip} , 端口=6379, DB=${redis_db}${NC} "
165165}
@@ -190,7 +190,7 @@ function check_status {
190190function process_operation {
191191 local env=$1
192192 local operation=$2
193-
193+
194194 case $operation in
195195 start)
196196 start_env $env
@@ -214,7 +214,7 @@ function process_operation {
214214# 处理所有环境
215215function process_all_envs {
216216 local operation=$1
217-
217+
218218 for env in test pre prod; do
219219 process_operation $env $operation
220220 done
@@ -225,4 +225,4 @@ if [ "$1" == "all" ]; then
225225 process_all_envs $2
226226else
227227 process_operation $1 $2
228- fi
228+ fi
0 commit comments