#!/bin/bash
# dev_deploy.sh
set -x

# 用法: ./dev_deploy.sh <分支名> <镜像名>
BRANCH_NAME=$1
IMAGE_NAME=$2

if [ -z "$BRANCH_NAME" ] || [ -z "$IMAGE_NAME" ]; then
  echo "用法: $0 <分支名> <镜像名>"
  exit 1
fi

# 分支名到端口映射
declare -A PORT_MAP
PORT_MAP[v0.5.0]="10280:80"
PORT_MAP[main]="10080:80"

PORTS=${PORT_MAP[$BRANCH_NAME]}

if [ -z "$PORTS" ]; then
  echo "未知分支: $BRANCH_NAME"
  exit 1
fi

CONTAINER_NAME="memowake-front-$BRANCH_NAME"

# 检查容器是否存在，如果存在则停止并删除
if docker ps -a | grep -q $CONTAINER_NAME; then
    docker stop $CONTAINER_NAME
    docker rm $CONTAINER_NAME
fi

# 运行新容器
docker run --name $CONTAINER_NAME -p $PORTS -d $IMAGE_NAME