springboot docker jenkins 部署 对比 tomcat

简介:     ---------------------------------------------------------------------------------------------------------------- springboot 详解 (一) hello...

 

 

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

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/



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

目录
相关文章
|
7天前
|
监控 Java 应用服务中间件
Spring Boot整合Tomcat底层源码分析
【11月更文挑战第20天】Spring Boot是一个用于快速构建基于Spring框架的应用程序的开源框架。它通过自动配置和起步依赖等特性,大大简化了Spring应用的开发和部署过程。本文将深入探讨Spring Boot的背景历史、业务场景、功能点以及底层原理,并通过Java代码手写模拟Spring Boot的启动过程,特别是其与Tomcat的整合。
26 1
|
28天前
|
监控 jenkins 持续交付
Docker和Jenkins有什么不同
【10月更文挑战第18天】Docker和Jenkins有什么不同
|
1月前
|
Java jenkins 持续交付
Centos7下docker的jenkins下载并配置jdk与maven
通过上述步骤,您将成功在CentOS 7上的Docker容器中部署了Jenkins,并配置好了JDK与Maven,为持续集成和自动化构建打下了坚实基础。
104 1
|
1月前
|
运维 jenkins 持续交付
自动化部署的魅力:如何用Jenkins和Docker简化运维工作
【10月更文挑战第7天】在现代软件开发周期中,快速且高效的部署是至关重要的。本文将引导你理解如何使用Jenkins和Docker实现自动化部署,从而简化运维流程。我们将从基础概念开始,逐步深入到实战操作,让你轻松掌握这一强大的工具组合。通过这篇文章,你将学会如何利用这些工具来提升你的工作效率,并减少人为错误的可能性。
|
1月前
|
jenkins Java 持续交付
Docker搭建jenkins环境
这篇文章详细介绍了如何利用Docker搭建Jenkins环境,包括拉取Jenkins镜像、配置端口映射及初始化设置的步骤。
145 0
Docker搭建jenkins环境
|
1月前
|
jenkins Java 持续交付
Jenkins打包,发布,部署
Jenkins打包,发布,部署
215 0
|
1月前
|
Ubuntu jenkins 持续交付
Ubuntu系统 用docker安装jenkins
Ubuntu系统 用docker安装jenkins
|
3月前
|
JavaScript jenkins 持续交付
自动化部署与持续集成:使用Jenkins和Docker优化开发流程
【8月更文挑战第31天】在软件开发的世界里,时间就是一切。本文将引导你通过Jenkins和Docker的强大组合,实现自动化部署和持续集成,让你的开发流程如丝般顺滑。我们将从基础设置开始,逐步深入到构建管道,最终实现一键部署的梦想。准备好让你的开发效率飞跃,一起探索这个令人兴奋的旅程吧!
|
3月前
|
jenkins Shell 持续交付
自动化部署:使用Jenkins和Docker实现CI/CD
【8月更文挑战第31天】 本文旨在引导读者了解如何通过Jenkins和Docker来实现持续集成和持续部署(CI/CD),从而优化开发流程,提升工作效率。文章将详细介绍配置Jenkins服务器、创建Docker镜像以及设置自动化构建和部署的步骤。通过实际操作案例,我们将展示如何将代码变更快速部署到测试或生产环境,确保软件质量与发布速度的双重保障。
|
3月前
|
负载均衡 jenkins 应用服务中间件
大规模部署下的 Jenkins 高可用性与负载均衡
【8月更文第31天】随着软件开发流程的加速,持续集成/持续交付(CI/CD)工具的重要性日益凸显。Jenkins 作为最受欢迎的 CI/CD 平台之一,为企业提供了强大的自动化构建和部署功能。然而,在大规模部署场景下,单一的 Jenkins 实例可能无法满足高可用性和性能的需求。本文将探讨如何设计和实施 Jenkins 高可用集群,以支持大型组织的需求,并通过负载均衡技术来提高系统的稳定性和响应速度。
266 0