1、部署好docker slave后,接下来需要下载dubbo应用的镜像
2、下载zookeeper
docker pull zookeeper:3.4.11
3、运行zookeeper
docker run --name zookeeper-test6 --restart always -d zookeeper:3.4.11
4、下载dubbo-admin
docker pull lemonguge/dubbo-admin:latest
5、运行dubbo-admin
docker run --name dubbo-admin --link zookeeper-test6:zookeeper --restart=unless-stopped -d lemonguge/dubbo-admin:latest
6、使用用户名root密码root登录dubbo-admin管理平台进行查看,默认端口8080
7、下载应用发布使用的tomcat镜像
docker pull tomcat:8.0.50-jre8-alpine
8、使用jenkins创建发布任务,选maven,然后节点选jenkins slave的节点
9、在docker slave所在宿主机的上的发布脚本 builddocker.sh
echo "##############################################"
echo ""
echo "2.Now starting build docker images"
echo ""
echo "##############################################"
mkdir -p /home/services
mkdir -p /home/services/serviceslogs/$servicename
mkdir -p /home/services/tomcatlogs/$servicename
NOWTIME=`date "+%Y%m%d%H%M"`
SERVICENAME=$1
NEV=$2
WORKSPACE=$3
WEBPORT=$4
DUBBOPORT=$5
HARBORADDRESS=192.168.1.74
#HOSTIP=`/sbin/ip route|egrep 'src 192\.|src 172\.|src 10\.' |grep -v docker |awk '{print $9}'|head -n 1`
rm -rf /home/services/war/$SERVICENAME*
cp $WORKSPACE/$SERVICENAME-web/target/$SERVICENAME.war /home/services/war/
sed -i "s/\$DOCKER_IP/$HOSTIP/" /home/services/shell/setip.sh
echo "FROM $HARBORADDRESS/public/tomcat:latest" > /home/services/Dockerfile
echo "ADD shell/setip.sh /app/bin/" >> /home/services/Dockerfile
echo "RUN sed -i '2i /app/bin/setip.sh' /app/bin/catalina.sh" >> /home/services/Dockerfile
echo "ADD war/$SERVICENAME.war /app/webapps/" >> /home/services/Dockerfile
/usr/bin/docker build -t $HARBORADDRESS/$NEV/$SERVICENAME:$NOWTIME /home/services/
if [ $? -eq 0 ]
then
echo "###########################################################################"
echo ""
echo "3.docker images build success,NOW beginng deploy the $SERVICENAME service"
echo ""
echo "###########################################################################"
docker rm -f $SERVICENAME
docker run --name $SERVICENAME -d --restart=unless-stopped -p $WEBPORT:8080 -p $DUBBOPORT:20881 -v /home/services/serviceslogs/$SERVICENAME:/home/services/$SERVICE
NAME -v /home/services/tomcatlogs/$SERVICENAME:/app/logs -v /opt:/opt $HARBORADDRESS/$NEV/$SERVICENAME:$NOWTIME
if [ $? -eq 0 ]
then
echo "###########################################################################"
echo ""
echo "4.deploy the $SERVICENAME service allready,NOW Beginng check the $SERVICENAME service"
echo ""
echo "###########################################################################"
sleep 15
echo "http://$HOSTIP:$WEBPORT/$SERVICENAME/check"
curl "http://$HOSTIP:$WEBPORT/$SERVICENAME/check"
curl "http://$HOSTIP:$WEBPORT/$SERVICENAME/check" 2>&1 |awk '{print $NF}' |grep 'true' | wc -l
VALUE=`curl "http://$HOSTIP:$WEBPORT/$SERVICENAME/check" 2>&1 |awk '{print $NF}' |grep 'true' | wc -l`
if [ $VALUE = 0 ]
then
echo "$SERVICENAME service check is OK, deploy completed"
echo ""
echo "###########################################################################"
echo ""
echo "5.delete the history $SERVICENAME service images"
echo ""
echo "###########################################################################"
CURRENTIMAGES=`docker images | grep $SERVICENAME | grep $NEV | awk '{print $3}' | head -n 1`
HISTORYIMAGES=`docker images | grep $SERVICENAME | grep $NEV | awk '{print $3}' |grep -v $CURRENTIMAGES`
docker rmi $HISTORYIMAGES
else
echo "$SERVICENAME service check is FAILD,NOW beginng ROLLBACK the service"
docker rm -f $SERVICENAME
docker rmi `docker images | grep $SERVICENAME | grep $NEV | awk '{print $3}' | head -n 1`
echo "beginng ROLLBACK the service"
docker run --name $SERVICENAME -d --restart=unless-stopped -p $WEBPORT:8080 -p $DUBBOPORT:20881 -v /home/services/serviceslogs/$SERVICENAME:/home/services/$
SERVICENAME -v /home/services/tomcatlogs/$SERVICENAME:/app/logs -v /opt:/opt `docker images | grep $SERVICENAME | grep $NEV | awk '{print $3}' | head -n 1`
echo "the service ROLLBACK completed"
fi
else
echo "###########################################################################"
echo "4.published the $SERVICENAME service FAILD,NOW beginng ROLLBACK the service"
echo "###########################################################################"
docker rm -f $SERVICENAME
docker rmi `docker images | grep $SERVICENAME | grep $NEV | awk '{print $3}' | head -n 1`
echo "beginng ROLLBACK the service"
docker run --name $SERVICENAME -d --restart=unless-stopped -p $WEBPORT:8080 -p $DUBBOPORT:20881 -v /home/services/serviceslogs/$SERVICENAME:/home/services/$SERV
ICENAME -v /home/services/tomcatlogs/$SERVICENAME:/app/logs -v /opt:/opt `docker images | grep $SERVICENAME | grep $NEV | awk '{print $3}' | head -n 1`
echo "the service ROLLBACK completed"
fi
else
echo "###########################################################################"
echo ""
echo "3.docker images build failed,It will stop deploy the $SERVICENAME service"
echo ""
echo "###########################################################################"
fi
sed -i "s/$HOSTIP/\$DOCKER_IP/" /home/services/shell/setip.sh
10、使用pipeline方式编译发布
node('test6'){
stage('get Code') {
git credentialsId: 'b160a96c-ed57-4c69-a092-77c520016bda', url: 'git@192.168.1.2/usercenter.git',branch: 'test6'
}
stage('编译打包') {
echo 'Building'
sh 'mvn clean package -Dmaven.test.skip=true -e -X'
}
stage('fabu') {
echo 'Building'
sh '/home/services/shell/builddocker.sh ordercenter test6 ${WORKSPACE} 18082 20882'
}
}