Jenkins ( jenkins+harbor)
Harbor 是咱们国产的docke仓库具体详细了解请参考以下连接
https://blog.csdn.net/csdn_duomaomao/article/details/78036331
http://blog.itpub.net/28624388/viewspace-2153546
如何将Jenkins和Harbor 相互结合,下图是比较理想的状态,当然还缺一下管理工具等等
当你部署完harbor之后,创建好相应的项目,以及用户信息。
接下来就开始配置Jenkins了
前面Jenkins的配置 跟我之前写的博客有重复所以不在这一一列举了
这个部分就是你的java代码构建之后进行的操作
脚本内容
#!/bin/bash #获取镜像id imagesid=`docker images|grep -i docker-harbor|awk '{print $3}'` project=/harbor_repo/ #dockerid=`docker ps -a|grep -i docker-test|awk '{print $1}' ` echo $project #判断镜像是否存在如果存在则删除,否则不删除 if [ ! -n "$imagesid" ];then echo $imagesid "is null" else docker rmi -f $imagesid fi #进入工作目录 cd $project #生成新的镜像 docker build -t docker-harbor . #登录docker仓库 docker login -u admin -p Harbor12345 192.168.10.110 #上传镜像到镜像仓库 docker tag docker-harbor 192.168.10.110/my_data/docker-harbor:1 docker push 192.168.10.110/my_data/docker-harbor:1
最终达到效果
Jenkins输出日志
Sending build context to Docker daemon 45.6 MB Step 1/4 : FROM java8 ---> 6a6b9be10cdd Step 2/4 : ADD ./target/raymedy.war /root/apache-tomcat-7.0.92/webapps ---> 67b92d6b55ec Removing intermediate container 0f072b0eea0b Step 3/4 : EXPOSE 8080 ---> Running in 444cd5db90ae ---> bd9eca176876 Removing intermediate container 444cd5db90ae Step 4/4 : CMD /root/apache-tomcat-7.0.92/bin/catalina.sh run ---> Running in dd3040e31d2f ---> 4030cf9e821e Removing intermediate container dd3040e31d2f Successfully built 4030cf9e821e Login Succeeded The push refers to a repository [192.168.10.110/my_data/docker-harbor] e2d60c921771: Preparing 8bd3de159ec9: Preparing 3cded00e5415: Preparing 071d8bd76517: Preparing 071d8bd76517: Layer already exists 8bd3de159ec9: Layer already exists 3cded00e5415: Layer already exists e2d60c921771: Pushed 1: digest: sha256:0c1b67f4d4d3f994a5fc517d02115513933bd25d237e76ce9a6d8e38e8a58b1f size: 1165 SSH: EXEC: completed after 4,803 ms SSH: Disconnecting configuration [192.168.10.110] ... SSH: Transferred 2 file(s) Finished: SUCCESS
镜像自动更新,这样其他地方就可以直接获取docker镜像文件了
不足之处请多指教