project_name=$1
# tag=$2
target_user='root'
target_ip='172.29.2.3'
target_dir="/home/quant_group/${project_name}"
deploy_dir="/home/quant_group/qa-deploy-utils"

qaapi='http://172.30.220.22:3003'
git_path=`curl -s "${qaapi}/proconfig/get_info?system_name=${project_name}&key=git_path"`
build_command=`curl -s "${qaapi}/proconfig/get_info?system_name=${project_name}&key=build_command"`

cd ${deploy_dir}
if [ ! -d "$deploy_dir" ];then
	echo "not exist"
	git clone ${git_path}
else
	echo "exist"
	git pull
fi


ssh ${target_user}@${target_ip} "cd /home/quant_group/qa-platform-ui "
ssh ${target_user}@${target_ip} "git pull"
ssh ${target_user}@${target_ip} "npm install"
ssh ${target_user}@${target_ip} "npm run build"
ssh ${target_user}@${target_ip} "supervisorctl restart ${project_name}"

echo "done"
