1 项目配置
- springboot pom配置:
<build>
<resources><!-- 使用@@站位符,输出Dockerfile至docker文件夹 -->
<resource>
<directory>src/main/docker</directory>
<filtering>true</filtering>
<includes>
<include>**/Dockerfile</include>
</includes>
<targetPath>../docker</targetPath>
</resource>
<!-- 此处注意,如果不配置整个resource 可能配置文件打入不到jar中-->
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}/classes</targetPath>
</resource>
</resources>
<plugins>
<plugin><!-- 置顶 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>remove</id>
<phase>package</phase>
<goals>
<goal>removeImage</goal>
</goals>
<configuration>
<skipDocker>${skipDockerRemove}</skipDocker>
</configuration>
</execution>
</executions>
<configuration>
<serverId>${dockerServerId}</serverId>
<registryUrl>http://${dockerRegistry}</registryUrl>
<dockerDirectory>${project.build.directory}/docker</dockerDirectory>
<imageName>${dockerImageName}</imageName>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.${project.packaging}</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>docker-dev</id>
<properties>
<dockerServerId>founder-docker-hub</dockerServerId>
<dockerRegistry>push.fzyun.io</dockerRegistry>
<!-- docker 私库地址,也可以使用阿里云的-->
<dockerHost>http://docker-host.serverpit.com:2375</dockerHost>
<pushImage>true</pushImage>
<dockerImageName>${dockerRegistry}/founder/${project.artifactId}:${dockerImageTags}</dockerImageName>
<dockerImageTags>${project.version}</dockerImageTags>
</properties>
</profile>
</profiles>
注意resource配置,需要增加resource配置,否则配置文件打入不到jar中。
- Dockfile 配置:
FROM java:8
ADD zy-view-*.jar /app/springboot-zy-view.jar
ENTRYPOINT [ "java", "-jar", "/app/springboot-zy-view.jar" ]
zy-view 是你的项目名称。
2 jenkins 配置:
如果你的jenkins和开发环境在一台机器上,则跳过ssh这一步
- 安装ssh 插件备用:
在jenkins的系统配置中配置开发环境机器:
新增一个项目:
配置svn,比较简单,省略。
配置maven 省略
配置出发省略
build配置:
clean install -P docker-dev
这个docker-dev和项目中pom配置对应。
到此为止可实现编码,打包,生成镜像,推送到私库。
一下是实现从私库拉取镜像到开发环境部署启动。
远程执行脚本:
c=`docker ps |grep 'zy-view'|wc -l`;
if [ $c -gt 0 ]
then
docker stop zy-view
docker rm zy-view
fi
sleep 15
docker pull founder/zy-view:0.1
docker run -p 8071:8071 -d -it --name='zy-view' founder/zy-view:0.1