之前有看到过nexus,但不了解干什么的。
想要搭建Maven仓库,可以下载nexus私服,然后在项目的pox.xml中增加需要的依赖以及Repository的位置配置即可
最近有在了解持续集成,项目有被部署到Docker,然后使用Jenkins提供页面化配置
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
SpringBoot+Maven+svn+docker+jenkins 自动化部署项目过程
首先在pom.xml加入下面的配置
<profile> <id>build-push-docker</id> <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <executions> <!-- 生成第一个镜像并push --> <execution> <id>build-image</id> <!-- 执行阶段 --> <phase>install</phase> <goals> <goal>build</goal> </goals> <configuration> <!-- 自动push镜像 --> <pushImage>true</pushImage> <serverId>镜像服务器地址</serverId> <registryUrl>http://url:端口</registryUrl> <!-- 第一个docker文件目录 --> <dockerDirectory>${project.basedir}/deploy</dockerDirectory> <!-- 镜像 --> <imageName>url/mbd-web</imageName> <imageTags> <imageTag>build-${docker_tag}</imageTag> <imageTag>latest</imageTag> </imageTags> <!-- 所需资源 --> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>mbd-web.war</include> </resource> </resources> <!-- 执行目录 --> <buildDirectory>${project.build.directory}/docker</buildDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build>
</profile>
<!-- 项目build名称 --> <finalName>mbd-web</finalName> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory> <resources> <resource> <directory>${project.basedir}/src/main/java</directory> <filtering>false</filtering> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.*</exclude> </excludes> </resource> </resources> <testResources> <testResource> <directory>${project.basedir}/src/test/java</directory> <filtering>false</filtering> <excludes> <exclude>**/*.java</exclude> </excludes> </testResource> </testResources> <!--directory>${project.basedir}/target</directory --> <!--<directory>${project.basedir}/webapp/WEB-INF/target</directory>--> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <!-- 打成jar包 --> <archiveClasses>true</archiveClasses> <!-- <webXml>${project.basedir}/web/WEB-INF/web.xml</webXml> --> <warSourceDirectory>${project.basedir}/src/main/web</warSourceDirectory> <webResources> <resource> <directory>${project.basedir}/src/main/web/WEB-INF</directory> <targetPath>WEB-INF</targetPath> <filtering>true</filtering> <includes> <include>web.xml</include> </includes> </resource> <resource> <directory>${project.basedir}/src/main/resources/conf-${profiles.active}</directory> <targetPath>WEB-INF/conf</targetPath> <filtering>true</filtering> <includes> <include>*.*</include> </includes> </resource> <resource> <directory>${project.basedir}/src/main/resources</directory> <targetPath>WEB-INF</targetPath> <filtering>true</filtering> <includes> <include>jdp-*.xml</include> <include>conf/*.*</include> </includes> </resource> </webResources> </configuration> </plugin> </plugins>
</build>
Dockfile文件的内容
FROM tmp/tomcat:8.0-openjdkADD server.xml $CATALINA_HOME/conf/ADD mbd-web.war $CATALINA_HOME/webapps/ENV JAVA_OPTS "-Xms512m -Xmx1024m"CMD ["catalina.sh", "run"]
deploy.sh文件内容
#!/bin/shset -xif [ x$1 != x ]; thenIMAGE_NAME=$1elseIMAGE_NAME=tomcatfiif [ x$2 != x ]; thenTAG_NUM=build-$2elseTAG_NUM=latestfidocker login url -u anonymous -p anonymousdocker rm -f $IMAGE_NAME || truesleep 5docker kill -s KILL $IMAGE_NAME || truesleep 3docker rm -f $IMAGE_NAME || truedocker pull founder/$IMAGE_NAME:$TAG_NUMdocker run -d --rm --name $IMAGE_NAME -p 8081:8080 founder/$IMAGE_NAME:$TAG_NUM