source ../environment.sh

if [ -z "$NETWORK" ]; then
echo "错误: 未找到 NETWORK 环境变量"
exit 1
fi
if [ -z "$SKYWALKING_OAP_NAME" ]; then
echo "错误: 未找到 SKYWALKING_OAP_NAME 环境变量"
exit 1
fi
if [ -z "$SKYWALKING_UI_NAME" ]; then
echo "错误: 未找到 SKYWALKING_UI_NAME 环境变量"
exit 1
fi
if [ -z "$SKYWALKING_OAP_IMAGE" ]; then
echo "错误: 未找到 SKYWALKING_OAP_IMAGE 环境变量"
exit 1
fi
if [ -z "$SKYWALKING_UI_IMAGE" ]; then
echo "错误: 未找到 SKYWALKING_UI_IMAGE 环境变量"
exit 1
fi
if [ -z "$SKYWALKING_OAP_MEMORY" ]; then
echo "错误: 未找到 SKYWALKING_OAP_MEMORY 环境变量"
exit 1
fi
if [ -z "$SKYWALKING_UI_MEMORY" ]; then
echo "错误: 未找到 SKYWALKING_UI_MEMORY 环境变量"
exit 1
fi
if [ -z "$SKYWALKING_UI_PORT" ]; then
echo "错误: 未找到 SKYWALKING_UI_PORT 环境变量"
exit 1
fi

 

if docker ps -a | grep -q ${SKYWALKING_UI_NAME}; then
    echo "停止并删除已存在的 SkyWalking UI 容器..."
    docker stop ${SKYWALKING_UI_NAME} >/dev/null 2>&1
    docker rm ${SKYWALKING_UI_NAME} >/dev/null 2>&1
fi

 
echo "启动 SkyWalking UI..."
docker run -d \
    --name ${SKYWALKING_UI_NAME} \
    --network $NETWORK \
    --memory $SKYWALKING_UI_MEMORY \
    --restart unless-stopped \
    -p ${SKYWALKING_UI_PORT}:8080 \
    -e TZ=Asia/Shanghai \
    -e SW_OAP_ADDRESS=http://${SKYWALKING_OAP_NAME}:12800 \
    --mount type=bind,source=/etc/localtime,target=/etc/localtime,readonly \
    $SKYWALKING_UI_IMAGE

echo "SkyWalking 部署完成!"
echo "OAP 端口: ${SKYWALKING_OAP_PORT}"
echo "UI 访问地址: http://localhost:${SKYWALKING_UI_PORT}"
