Docker容器使用jenkins部署web项目

(1)需要安装Docker容器,在Docker容器内安装jenkins,gogs,tomcat。   新建maven项目,添加findbugs plugin。

使用docker启动jenkins,gogs,Tomcat的命令gogs :

1 docker run -itd -p 10022:22 -p 10080:3000 --restart=always --privileged=true --name=gogs -v /var/gogs:/data gogs/gogs 2 3jenkins: 4 docker run -itd -p 8800:8080 -p 50000:50000 --restart=always --privileged=true --name=jenkins -v /home/jenkins:/var/jenkins_home jenkins 5 6tomcat: 7 docker run -itd -p 8080:8080 --restart=always --privileged=true --name=tomcat -v /usr/local/tomcat:/var/tomcat_home tomcat:8.0后来启动tomcat的命令: docker run -itd -p 8080:8080  --restart=always --privileged=true --name=tomcat -v /usr/local/tomcat:/home/tomcat/tomcat_home tomcat:8.0解释: -i :表示以交互形式打开-d :后台运行-t :伪终端-p :指定端口 前面的是你指定用户用来访问的端口号,后面的是指该软件本来默认的端口号--restart=always : 使得程序总是处于运行状态,自动启动--privileged=true : 和防火墙有关,selinux权限 (设置这个程序不会受防火墙的影响)--name : 指定容器运行的名称 -v : 容器挂载,前面是实实在在存在的数据卷,后面是挂载目录最后的 gogs/gogs jenkins tomcat:8.0 是镜像名,docker pull命令后面跟的参数

(2)在jenkins上安装插件: maven Intergration plugin ,gogs-plugin ,publish over ssh, findbugs-plugin,Deploy to a container (jdk ,git 都使用Docker中默认的,安装jenkins的时候不需要配置这两项的路径)

(3)tomcat需要配置用户: 通过 find / -name "tomcat" ,找到Tomcat的安装路径,再将内容添加到  conf/tomcat-users.xml文件中  <tomcat-users>大概这个位置</tomcat-users>

1<role rolename="admin"/> 2 <role rolename="manager"/> 3 <role rolename="manager-gui"/> 4 <role rolename="manager-script"/> 5 <user username="tomcat" password="tomcat" roles="admin,manager,manager-gui,manager-script"/>

(4)gogs创建仓库时,记得私有化,配置git钩子,在.git/hooks/目录下添加 pre-commit 文件,pre-commit 文件中的内容如下

1#!/bin/sh 2#execute shell before commit,check the code 3mvn clean install 4 5#recieve the execute result 6result=$? 7#output the result ,if the result less or equal 0 ,it proves this project has bugs,otherwise don't. 8echo $result 9 10if [ $result -ne 0 ] 11then 12 mvn findbugs:gui 13 echo "REGRETFUL! BUILD FAILURE" 14 exit 1 15else 16 echo "CONGRATURATION! BUILD SUCCESS" 17 exit 0 18fi

注释: 配置webhook时,如果推送的时候出现了 403错误,要查看jenkins中是否安装了 gogs-plugin这个插件(因为我当时出错了半天,就是因为没有安装gogs-plugin)

webhook示例:http://172.150.15.9:8800/gogs-webhook/?job=WebdemoIn7   //WebdemoIn7是我的enkins项目名

(5)创建maven项目时,pom.xml中的内容

1<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>cn.demo</groupId> 5 <artifactId>WebdemoIn7</artifactId> 6 <packaging>war</packaging> <!-- 打包为war包 --> 7 <version>0.0.1-SNAPSHOT</version> 8 <name>WebdemoIn7 Maven Webapp</name> 9 <url>http://maven.apache.org</url> 10 <build> 11 <finalName>WebdemoIn7</finalName> 12 <plugins> 13 <plugin> 14 <inherited>true</inherited> 15 <groupId>org.apache.maven.plugins</groupId> 16 <artifactId>maven-compiler-plugin</artifactId> 17 <version>3.5.1</version> 18 <configuration> 19 <source>${compiler.source}</source> 20 <target>${compiler.target}</target> 21 <encoding>${project.build.sourceEncoding}</encoding> 22 <compilerArguments> 23 <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs> 24 </compilerArguments> 25 </configuration> 26 </plugin> 27 <!-- 指定执行的主类(main方法所在的类)--> 28 <plugin> 29 <groupId>org.apache.maven.plugins</groupId> 30 <artifactId>maven-jar-plugin</artifactId> 31 <version>2.6</version> 32 <configuration> 33 <archive> 34 <!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 --> 35 <!-- <index>true</index> --> 36 <manifest> 37 <mainClass>cn.demo.JavademoIn7.application.ApplicationMain</mainClass> 38 </manifest> 39 40 </archive> 41 </configuration> 42 </plugin> 43 44 <!-- findbugs插件 :静态检查代码的错误--> 45 <plugin> 46 <groupId>org.codehaus.mojo</groupId> 47 <artifactId>findbugs-maven-plugin</artifactId> 48 <version>3.0.4</version> 49 <configuration> 50 <!-- 设置分析工作的等级,可以为Min、Default和Max --> 51 <effort>Low</effort> 52 <!-- Low、Medium和High (Low最严格) --> 53 <threshold>Medium</threshold> 54 <failOnError>true</failOnError> 55 <includeTests>true</includeTests> 56 <!--findbugs需要忽略的错误的配置文件--> 57 <!-- <excludeFilterFile>compile.bat</excludeFilterFile> --> 58 </configuration> 59 <executions> 60 <execution> 61 <id>run-findbugs</id> 62 <!-- 在install 阶段触发执行findbugs检查,比如执行 mvn clean package--> 63 <phase>install</phase> 64 <goals> 65 <goal>check</goal> 66 </goals> 67 </execution> 68 </executions> 69 </plugin> 70 71 </plugins> 72 </build> 73 <properties> 74 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 75 <compiler.source>1.7</compiler.source> 76 <compiler.target>1.7</compiler.target> 77 78 <!-- servlet/jsp/EL (2.4/2.0/?)(2.5/2.1/2.1),(3.0/2.2/2.2),(3.1/2.3/3.0) --> 79 <servlet.version>3.1.0</servlet.version> 80 <jsp.version>2.3.1</jsp.version> 81 <jstl.version>1.2</jstl.version> 82 <junit.version>4.12</junit.version> 83 </properties> 84 <dependencies> 85 <dependency> 86 <groupId>org.apache.maven.plugins</groupId> 87 <artifactId>maven-clean-plugin</artifactId> 88 <version>2.5</version> 89 </dependency> 90 <dependency> 91 <groupId>junit</groupId> 92 <artifactId>junit</artifactId> 93 <version>${junit.version}</version> 94 <scope>test</scope> 95 </dependency> 96 <dependency> 97 <groupId>javax.servlet</groupId> 98 <artifactId>javax.servlet-api</artifactId> 99 <version>${servlet.version}</version> 100 <scope>provided</scope> 101 </dependency> 102 <dependency> 103 <groupId>javax.servlet.jsp</groupId> 104 <artifactId>javax.servlet.jsp-api</artifactId> 105 <version>${jsp.version}</version> 106 <scope>provided</scope> 107 </dependency> 108 <dependency> 109 <groupId>javax.servlet</groupId> 110 <artifactId>jstl</artifactId> 111 <version>${jstl.version}</version> 112 </dependency> 113 </dependencies> 114</project>

(6)jenkins构建项目时,前面的配置一如往常,可以查看其它的案例

主要配置 源码管理,构建触发器,build,构建后操作

然后部署可以访问了

http://172.150.12.32:8080/WebdemoIn7

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )