project_name=$1
image_version=$2
project_env=$3
configure_overrides=$4
img_output=${project_name}
arrange_env=$6
if [ "${configure_overrides}" == "1" ];then
   server_ip=$5
   JAVA_PARAMETER="--spring.cloud.nacos.config.server-addr=${server_ip}:8848 --spring.cloud.nacos.config.namespace=prod-namespace --spring.cloud.nacos.discovery.server-addr=${server_ip}:8848 --spring.cloud.nacos.discovery.namespace=prod-namespace"
   echo "变更nacos地址：${server_ip}:8848"
else
   JAVA_PARAMETER=""
fi
docker rm -f ${project_name}
docker rmi -f 122.9.97.179:8080/ypt_local_deployment/${project_name}:${image_version}
if [ "${arrange_env}" == "local" ];then
   echo "从本地：/data/docker-images导入镜像..."
   if [ ! -f /data/docker-images/${project_name}.tar.gz ];then
      echo "镜像文件不存在,请先上传镜像文件/data/docker-images/${project_name}.tar.gz"
      exit 10
   fi
   cd /data/docker-images
   docker load -i ${project_name}.tar.gz
else
   echo "在线下载docker镜像..."
fi
sleep 2
if [ "$(echo ${server_name} | grep service-scoring)" != "" ] || [ "$(echo ${server_name} | grep service-file)" != "" ];then
   dir_name="absent  answer  barcode  paperNo  sliced  tess4j"
   for i in $dir_name
   do
      if [ ! -d /data/scoring_img/yide-service-scoring/$i ];then
         mkdir -p /data/scoring_img/yide-service-scoring/$i
      fi
   done
docker run -e "TZ=Asia/Shanghai" \
       -e "JAVA_OPTS=-Dspring.profiles.active=${project_env}" \
       -e "JAVA_PARAMETER=${JAVA_PARAMETER}" \
       -v /data/apache-skywalking-apm-bin:/apache-skywalking-apm-bin \
       -v /data/docker_logs/$img_output:/logs \
       -v /data/scoring_img/yide-service-scoring:/scoring_img \
       --privileged=true \
       -d --name ${project_name} --net=host \
       122.9.97.179:8080/ypt_local_deployment/${project_name}:${image_version}

else
docker run -e "TZ=Asia/Shanghai" \
       -e "JAVA_OPTS=-Dspring.profiles.active=${project_env}" \
       -e "JAVA_PARAMETER=${JAVA_PARAMETER}" \
       -v /data/apache-skywalking-apm-bin:/apache-skywalking-apm-bin \
       -v /data/docker_logs/$img_output:/logs \
       --privileged=true \
       -d --name ${project_name} --net=host \
       122.9.97.179:8080/ypt_local_deployment/${project_name}:${image_version}
fi
