springboot docker jenkins 部署 对比 tomcat

 

 

----------------------------------------------------------------------------------------------------------------

springboot 详解 (一) helloworld                                    下载demo          

springboot 详解 (二) crud                                             下载demo     

springboot 详解 (三) 多数据源                                        下载demo      

springboot 详解 (四)redis & filter                                    下载demo    

springboot 详解 (五)interceptor                                       下载demo     

springboot 详解 (六)servlet & scheduled & listener         下载demo     

springboot 详解(七) dubbox & zookeeper   下载(productor) 下载(constumser)

springboot 同步解耦 异步化 下载demo

springboot jenkins docker 部署 

springboot 详解(八) springboot & springcloud 

----------------------------------------------------------------------------------------------------------------

 

 

 

 

 

 

 

springboot docker jenkins 部署

1.pom 文件

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion> 
  <groupId>com.curiousby.baoyou.cn</groupId>
  <artifactId>showandshare.docker.jenkinsdockerdemo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>showandshare.docker.jenkinsdockerdemo</name>
  <url>http://maven.apache.org</url>
  <packaging>jar</packaging>
  
  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
        <relativePath>../pom.xml</relativePath>  <!-- lookup parent from repository -->
    </parent>
    
   <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
        </pluginRepository>
    </pluginRepositories>
    

	

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
     
     
        <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>  
		    <groupId>org.springframework.boot</groupId>  
		    <artifactId>spring-boot-starter-aop</artifactId>  
		</dependency>  
          <dependency>  
            <groupId>com.google.code.gson</groupId>  
            <artifactId>gson</artifactId>  
        </dependency>
        <dependency>
				<groupId>com.alibaba</groupId>
				<artifactId>fastjson</artifactId>
				<version>1.2.8</version>
			</dependency>
        
    </dependencies>

	<build>
		<finalName>showandshare.docker.jenkinsdockerdemo</finalName>
		<resources>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
				</includes>
				<filtering>false</filtering>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
				<includes>
					<include>**/*</include>
				</includes>
				<filtering>false</filtering>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<!-- 忽略测试失败或者跳过测试继续打包或安装 -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.10</version>
				<configuration>
					<skip>true</skip>
					<!-- <testFailureIgnore>true</testFailureIgnore> -->
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
					<compilerArguments>
						<verbose />
						<bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
					</compilerArguments>
				</configuration>
			</plugin>
			
			
			<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <!-- Docker maven plugin -->
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>1.0.0</version>
            <configuration>
                <!-- <imageName>${docker.image.prefix}/${project.artifactId}</imageName> -->
                <imageName>curiousby/showandshare.docker.jenkinsdockerdemo</imageName>  
                <dockerDirectory>src/main/docker</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>
        <!-- Docker maven plugin -->
        
		</plugins>

	</build>
</project>

 

2.dockerfile

############################################  
# version:   
# desc : 当前版本安装的 
############################################  
  
  
# 设置继承自我们创建的 tools 镜像   
FROM dquintela/openjdk-8-jdk-alpine 

VOLUME /tmp 

ADD  showandshare.docker.jenkinsdockerdemo.jar app.jar

ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar




 

 

 

3.svn 配置 



 

 

4.bulid



 MAVEN_OPTS 设置 -Xms128m -Xmx512m

执行mvn 命令 clean package docker:build

 

 

5.发布脚本



 

echo "======================================"
echo `date ` -- start start docker 


docker_container_name="curiousby/showandshare.docker.jenkinsdockerdemo"
docker_container_pid=`docker ps  | grep $docker_container_name | awk '{print $1}'`

if [ "" = "$docker_container_pid" ] ; then
        echo " docker_container isn't running."
else
        docker stop $docker_container_pid 
        echo " docker_container(pid:$docker_container_pid) be killed. sleep 5s"
        sleep 5
fi
 
docker run -p 7071:7071 -d $docker_container_name

echo `date ` -- end start docker 
echo "======================================"

 

 

6.构建输出日志

Started by user baoyou
Building in workspace /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo
Updating svn://192.168.206.235/showandshare.docker.jenkinsdockerdemo at revision '2018-06-26T03:44:07.235 -0700' --quiet
Using sole credentials baoyou/****** in realm ‘<svn://192.168.206.235:3690> /data/svn/repo’
At revision 17

No changes for svn://192.168.206.235/showandshare.docker.jenkinsdockerdemo since the previous build
Parsing POMs
Established TCP socket on 44875
[showandshare.docker.jenkinsdockerdemo] $ /home/baoyou/soft/jdk1.8.0_151/bin/java -Xms128m -Xmx512m -cp /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.12-alpha-1.jar:/home/baoyou/soft/apache-maven-3.5.4/boot/plexus-classworlds-2.5.2.jar:/home/baoyou/soft/apache-maven-3.5.4/conf/logging jenkins.maven3.agent.Maven35Main /home/baoyou/soft/apache-maven-3.5.4 /home/baoyou/soft/apache-tomcat-8.0.47/webapps/jenkins/WEB-INF/lib/remoting-3.20.jar /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.12-alpha-1.jar /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.12-alpha-1.jar 44875
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/pom.xml clean package docker:build
[INFO] Scanning for projects...
[INFO] 
[INFO] ---< com.curiousby.baoyou.cn:showandshare.docker.jenkinsdockerdemo >----
[INFO] Building showandshare.docker.jenkinsdockerdemo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Deleting /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 6 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Compiling 2 source files to /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Tests are skipped.
[WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.BuildInfoRecorder$1; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
[INFO] 
[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Building jar: /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/showandshare.docker.jenkinsdockerdemo.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.3.5.RELEASE:repackage (default) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] 
[INFO] --- docker-maven-plugin:1.0.0:build (default-cli) @ showandshare.docker.jenkinsdockerdemo ---
[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier]
[INFO] Copying /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/showandshare.docker.jenkinsdockerdemo.jar -> /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/docker/showandshare.docker.jenkinsdockerdemo.jar
[INFO] Copying src/main/docker/.svn/text-base/Dockerfile.svn-base -> /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/docker/.svn/text-base/Dockerfile.svn-base
[INFO] Copying src/main/docker/.svn/format -> /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/docker/.svn/format
[INFO] Copying src/main/docker/.svn/entries -> /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/docker/.svn/entries
[INFO] Copying src/main/docker/Dockerfile -> /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/docker/Dockerfile
[INFO] Building image curiousby/showandshare.docker.jenkinsdockerdemo
Step 1/4 : FROM dquintela/openjdk-8-jdk-alpine
 ---> 419025210ef0
Step 2/4 : VOLUME /tmp
 ---> Using cache
 ---> 14f67319ff67
Step 3/4 : ADD showandshare.docker.jenkinsdockerdemo.jar app.jar
 ---> cc9ce84e0337
Step 4/4 : ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
 ---> Running in dfc3cb3f8494
 ---> a0b7f7d8132e
Removing intermediate container dfc3cb3f8494
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built a0b7f7d8132e
Successfully tagged curiousby/showandshare.docker.jenkinsdockerdemo:latest
[INFO] Built curiousby/showandshare.docker.jenkinsdockerdemo
[WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.MavenArtifactArchiver$2; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
[WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.MavenFingerprinter$1; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:06 min
[INFO] Finished at: 2018-06-26T03:45:23-07:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/pom.xml to com.curiousby.baoyou.cn/showandshare.docker.jenkinsdockerdemo/0.0.1-SNAPSHOT/showandshare.docker.jenkinsdockerdemo-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/showandshare.docker.jenkinsdockerdemo/target/showandshare.docker.jenkinsdockerdemo.jar to com.curiousby.baoyou.cn/showandshare.docker.jenkinsdockerdemo/0.0.1-SNAPSHOT/showandshare.docker.jenkinsdockerdemo-0.0.1-SNAPSHOT.jar
channel stopped
[showandshare.docker.jenkinsdockerdemo] $ /bin/sh -xe /home/baoyou/soft/apache-tomcat-8.0.47/temp/jenkins5841437373663528941.sh
+ echo ======================================
======================================
++ date
+ echo Tue Jun 26 03:45:25 PDT 2018 -- start start docker
Tue Jun 26 03:45:25 PDT 2018 -- start start docker
+ docker_container_name=curiousby/showandshare.docker.jenkinsdockerdemo
++ docker ps
++ grep curiousby/showandshare.docker.jenkinsdockerdemo
++ awk '{print $1}'
+ docker_container_pid=
+ '[' '' = '' ']'
+ echo ' docker_container isn'\''t running.'
 docker_container isn't running.
+ docker run -p 7071:7071 -d curiousby/showandshare.docker.jenkinsdockerdemo
8690971a19f90dbdd49df757483c76462e3d360e2d2736eac87ce199fadb5d40
++ date
+ echo Tue Jun 26 03:45:29 PDT 2018 -- end start docker
Tue Jun 26 03:45:29 PDT 2018 -- end start docker
+ echo ======================================
======================================
Finished: SUCCESS

 

7.访问



 

 

 

 

 

对比 tomcat 部署方式,添加 

 



 

修改pom 中<packaging>

 jar 为 war 

生成war 包

重新访问 



 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

个人主页http://knight-black-bob.iteye.com/



 
 
 谢谢您的赞助,我会做的更好!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值