#!/bin/bash
#服务名,服务组名,是否重载compose, compose文件路径
echo "更新开始"
serviceGroupName=$1
deployName=$2
directoryName="/opt/docker-service/${deployName}"
reload=${3:-false}
dockerComposeName=$4
#判断文件夹是否存在 -d
echo "开始查找文件夹:${directoryName}"
if [[ ! -d "$directoryName" ]]; then
echo "文件夹不存在,请检查"
exit
fi
projectName=${directoryName}"/"${deployName}".jar"
#判断文件是否存在
#echo "开始查找文件:${projectName}"
#if [[ ! -e "$projectName" ]]; then
# echo "文件不存在,请检查"
# exit
#fi
imageName="xuntong/"${deployName}
echo "开始打镜像包,镜像名称为:${imageName}"
docker build -t ${imageName} ${directoryName}
echo "镜像打包完成"
check_service=`docker service ls -f NAME=${serviceGroupName}_${deployName} -q`
echo "check-service-"${check_service}
if [[ ${reload} == 'true' || ${check_service} == '' ]]; then
echo "尝试用compose文件启动:${dockerComposeName}"
if [[ ! -e "$dockerComposeName" ]]; then
echo "${dockerComposeName}文件不存在,请检查"
exit
fi
docker stack deploy -c ${dockerComposeName} ${serviceGroupName}
else
echo "该服务已启动,正强制更新该服务(不更新配置文件)"
docker service update --force ${serviceGroupName}_${deployName}
fi
docker push ${imageName}
echo "更新完成"
11-10
9355
09-08
932