# 源jar路径
# SOURCE_PATH=/usr/local/data/jenkins/workspace/insagent/target
# Dockerfile路径
DOCKER_FILE_PATH=/usr/local/java/nightFragrance
# 容器id
CID=$(''docker ps | grep "night-fragrance" | awk '{print $1}''')
echo $CID
# 运行docker容器
function run(){
  echo "开始构建镜像..."
  cd $DOCKER_FILE_PATH
  echo "当前路径如下"
  pwd
  # 构建前判断是否存在镜像，存在则删除
  if [ -n "$CID" ]; then
    echo "存在demo容器，CID=$CID,重启docker容器 ..."
    # 停止容器运行
    sudo docker stop $CID
    # 删除容器
    sudo docker rm $CID
    # 删除镜像
    sudo docker rmi night-fragrance
    echo "删除镜像和容器成功，下面开始构建新镜像"
  else
    echo "不存在people-healthy容器，下面直接开始构建镜像"
  fi
  # 构建镜像
  docker build -t night-fragrance .
  echo "创建容器成功"
  docker images
  # 杀死特定端口进程
  # mypid=$(netstat -apn|grep 9001|awk '{print $7}'|cut -d/ -f1);
  # echo $mypid
  # kill -9 $mypid
  docker run -it --name night-fragrance -p 8097:8097 -e "--spring.profiles.active=test" --restart=always -v /usr/local/java/nightFragrance:/nightFragrance -v /usr/local/java/nightFragrance/uploadPath:/nightFragrance/uploadPath -v /usr/local/java/nightFragrance/logs:/nightFragrance/logs -v /usr/local/java/nightFragrance/pay:/nightFragrance/pay -d night-fragrance:latest
}

#入口
run

