Jerkin 制作自定义镜像推送到Harbor
docker build -t mytest:$tag .
docker login -u admin -p Harbor12345 178.119.30.133:80
docker tag mytest:$tag 178.119.30.133:80/repo/mytest:$tag
docker push 178.119.30.133:80/repo/mytest:$tag
编写部署脚本
部署项目需要通过Publish Over SSH插件,让目标服务器执行命令。为了方便一次性实现拉取镜像和启动的命令,推荐采用脚本文件的方式。
添加脚本文件到目标服务器,再通过Publish Over SSH插件让目标服务器执行脚本即可。
deploy.sh
harbor_addr=$1
harbor_repo=$2
project=$3
version=$4
port=$5imageName=$harbor_addr/$harbor_repo/$project:$versionecho $imageNamecontainerId=`docker ps -a|grep $project|awk '{print $1}' `echo $containerIdif [ "containerId" != "" ];thendocker stop $containerIddocker rm $containerId
fitag=`docker images|grep $project| awk '{print $2}'`echo $tagif [[ "$tag" =~ "$version" ]] ; thendocker rmi -f $imageName
fidocker login -u admin -p Harbor12345 $harbor_addrdocker pull $imageNamedocker run -d -p $port:$port --name $project $imageNameecho "Success"
[root@178-119-30-133 ~]# ./deploy.sh 178.119.30.133:80 repo mytest v3.0.0 8081