微服务利用docker+jenkins+maven+git一键自
2018-08-02 本文已影响123人
ROCK_杰哥
接到勇哥指示,项目docker化,由于在搭建测试环境,以及各个地域项目现场搭建系统的时候,老费劲了,浪费人力物力,遂就有这篇文章,这里感谢勇哥,给这个机会。
目标
只需点击jenkins的
即可打包,部署,启动
前提
这篇文章的前提就是已经安装好了jenkins,docker,以及maven,如果没有安装,就看之前的文章,我的jenkins和maven都是docker的,直接安装到物理机上也可以。
配置jenkins
#######git配置

#######构建
项目打jar包,和微服务build上传至服务器

构建之后,启动

项目中docker化
pom.xml中添加
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<dockerHost>http://192.168.112.143:2375</dockerHost>
<imageName>${project.name}:${project.version}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<skipDockerBuild>false</skipDockerBuild>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<include>${project.name}-${project.version}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
项目目录结构添加

dockerfile:

runboot.sh

myhosts就是hosts文件
docker-compose.yml
这个是启动文件


工作中遇到比较麻烦的问题:
1,jenkins是docker的,maven是jenkins的插件,想要修改setting.xml,很难,vi,vim等等编辑命令docker已经禁止了,只能在pom.xml中修改,添加自己的私服
2,可以根据https://www.jianshu.com/p/b953eb2b4e9a先测试好自己的项目是否能打包上传功能
在编译失败的时候在这里看失败信息:

到这里已经启动,但是中间件没有在启动文件中,最好不要放到启动文件中,单独放到物理机上或者docker化都可以,还有项目的集群用docker非常容易部署,因为docker与生俱来的隔离特性,让微服务集群变得非常容易。
望指正,不吝赐教