#!/bin/bash
environment=$1
version=$2
echo "环境变量为${environment},版本为$version!"
if [[ ${environment} == 'production' ]]; then
	echo "开始远程构建容器"
	docker stop health_monitor || true
	docker rm health_monitor || true
	docker rmi -f $(docker images | grep registry.cn-shanghai.aliyuncs.com/gps_card/health_monitor | awk '{print $3}')
	#docker login --username=telpo_linwl@1111649216405698 --password=telpo#1234 registry.cn-shanghai.aliyuncs.com
	docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com
	docker pull registry.cn-shanghai.aliyuncs.com/gps_card/health_monitor:$version
	docker run --network=host -d -v /home/data/health_monitor/log:/var/health_monitor/logs --restart=always -e FirstEP=172.19.42.48:6030 -e environment=production --name health_monitor registry.cn-shanghai.aliyuncs.com/gps_card/health_monitor:$version;
	#删除产生的None镜像
	docker rmi -f $(docker images | grep none | awk '{print $3}')
	docker ps -a

elif [[ ${environment} == 'test' || ${environment} == 'presure' ]]; then
	echo "开始在测试环境远程构建容器"
	docker stop health_monitor || true
	docker rm health_monitor || true
	docker rmi -f $(docker images | grep 139.224.254.18:5000/health_monitor | awk '{print $3}')
	docker pull 139.224.254.18:5000/health_monitor:$version
	docker run --network=host -d -v /home/data/health_monitor/log:/var/health_monitor/logs --restart=always -e FirstEP=172.19.42.44:6030 -e environment=test --name health_monitor 139.224.254.18:5000/health_monitor:$version;
	#删除产生的None镜像
	docker rmi -f $(docker images | grep none | awk '{print $3}')
	docker ps -a

fi