#!/bin/bash

# 构建镜像
echo "正在构建 Docker 镜像..."
docker build -t baidu-translate-api:latest .

# 停止并删除旧容器（如果存在）
if [ "$(docker ps -q -f name=baidu-translate)" ]; then
    echo "停止旧容器..."
    docker stop baidu-translate
fi

if [ "$(docker ps -aq -f status=exited -f name=baidu-translate)" ]; then
    echo "删除旧容器..."
    docker rm baidu-translate
fi

# 启动新容器
echo "启动容器..."
docker run -d \
  --name baidu-translate \
  -p 28081:5000 \
  --restart unless-stopped \
  baidu-translate-api:latest

echo "服务已启动！访问 http://<服务器IP>:5000/health"