国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務(wù)器 > Web服務(wù)器 > 正文

Docker容器使用jenkins部署web項(xiàng)目(總結(jié))

2024-09-01 13:55:30
字體:
供稿:網(wǎng)友

(1)需要安裝Docker容器,在Docker容器內(nèi)安裝jenkins,gogs,tomcat。   新建maven項(xiàng)目,添加findbugs plugin。

使用docker啟動(dòng)jenkins,gogs,Tomcat的命令gogs :

 

復(fù)制代碼代碼如下:
 docker run -itd -p 10022:22 -p 10080:3000 --restart=always --privileged=true --name=gogs -v /var/gogs:/data gogs/gogs

 

jenkins:

 

復(fù)制代碼代碼如下:
docker run -itd -p 8800:8080 -p 50000:50000 --restart=always --privileged=true --name=jenkins -v /home/jenkins:/var/jenkins_home jenkins

 

tomcat:

 

復(fù)制代碼代碼如下:
docker run -itd -p 8080:8080  --restart=always --privileged=true --name=tomcat -v /usr/local/tomcat:/var/tomcat_home

 

tomcat:8.0

 

復(fù)制代碼代碼如下:
docker run -itd -p 8080:8080  --restart=always --privileged=true --name=tomcat -v /usr/local/tomcat:/home/tomcat/tomcat_home tomcat:8.0

 

后來啟動(dòng)tomcat的命令:

解釋: 

-i :表示以交互形式打開
-d :后臺(tái)運(yùn)行
-t :偽終端
-p :指定端口 前面的是你指定用戶用來訪問的端口號(hào),后面的是指該軟件本來默認(rèn)的端口號(hào)
--restart=always : 使得程序總是處于運(yùn)行狀態(tài),自動(dòng)啟動(dòng)
--privileged=true : 和防火墻有關(guān),selinux權(quán)限 (設(shè)置這個(gè)程序不會(huì)受防火墻的影響)
--name : 指定容器運(yùn)行的名稱
 -v : 容器掛載,前面是實(shí)實(shí)在在存在的數(shù)據(jù)卷,后面是掛載目錄

最后的 gogs/gogs   jenkins  tomcat:8.0 是鏡像名,docker pull命令后面跟的參數(shù)

(2)在jenkins上安裝插件: maven Intergration plugin ,gogs-plugin ,publish over ssh, findbugs-plugin,Deploy to a container (jdk ,git 都使用Docker中默認(rèn)的,安裝jenkins的時(shí)候不需要配置這兩項(xiàng)的路徑)

(3)tomcat需要配置用戶: 通過 find / -name "tomcat" ,找到Tomcat的安裝路徑,再將內(nèi)容添加到  conf/tomcat-users.xml文件中  <tomcat-users>大概這個(gè)位置</tomcat-users>

<role rolename="admin"/> <role rolename="manager"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="tomcat" password="tomcat" roles="admin,manager,manager-gui,manager-script"/> 

(4)gogs創(chuàng)建倉庫時(shí),記得私有化,配置git鉤子,在.git/hooks/目錄下添加 pre-commit 文件,pre-commit 文件中的內(nèi)容如下

#!/bin/sh#execute shell before commit,check the codemvn clean install#recieve the execute resultresult=$?#output the result ,if the result less or equal 0 ,it proves this project has bugs,otherwise don't.echo $resultif [ $result -ne 0 ]then  mvn findbugs:gui  echo "REGRETFUL! BUILD FAILURE"  exit 1else  echo "CONGRATURATION! BUILD SUCCESS"  exit 0fi

注釋: 配置webhook時(shí),如果推送的時(shí)候出現(xiàn)了 403錯(cuò)誤,要查看jenkins中是否安裝了 gogs-plugin這個(gè)插件(因?yàn)槲耶?dāng)時(shí)出錯(cuò)了半天,就是因?yàn)闆]有安裝gogs-plugin)

webhook示例:http://172.150.15.9:8800/gogs-webhook/?job=WebdemoIn7   //WebdemoIn7是我的enkins項(xiàng)目名

(5)創(chuàng)建maven項(xiàng)目時(shí),pom.xml中的內(nèi)容

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>cn.demo</groupId>  <artifactId>WebdemoIn7</artifactId>  <packaging>war</packaging> <!-- 打包為war包 -->  <version>0.0.1-SNAPSHOT</version>  <name>WebdemoIn7 Maven Webapp</name>  <url>http://maven.apache.org</url>  <build>    <finalName>WebdemoIn7</finalName>    <plugins>      <plugin>        <inherited>true</inherited>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-compiler-plugin</artifactId>        <version>3.5.1</version>        <configuration>          <source>${compiler.source}</source>          <target>${compiler.target}</target>          <encoding>${project.build.sourceEncoding}</encoding>          <compilerArguments>            <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>          </compilerArguments>        </configuration>      </plugin>      <!-- 指定執(zhí)行的主類(main方法所在的類)-->      <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-jar-plugin</artifactId>         <version>2.6</version>         <configuration>           <archive>           <!-- 添加index則不從mainfest中讀取classpath,而是從Index.list中讀取 -->           <!-- <index>true</index> -->             <manifest>               <mainClass>cn.demo.JavademoIn7.application.ApplicationMain</mainClass>             </manifest>                       </archive>         </configuration>       </plugin>             <!-- findbugs插件 :靜態(tài)檢查代碼的錯(cuò)誤-->    <plugin>      <groupId>org.codehaus.mojo</groupId>      <artifactId>findbugs-maven-plugin</artifactId>      <version>3.0.4</version>      <configuration>        <!-- 設(shè)置分析工作的等級(jí),可以為Min、Default和Max -->        <effort>Low</effort>        <!-- Low、Medium和High (Low最嚴(yán)格) -->        <threshold>Medium</threshold>        <failOnError>true</failOnError>        <includeTests>true</includeTests>        <!--findbugs需要忽略的錯(cuò)誤的配置文件-->        <!-- <excludeFilterFile>compile.bat</excludeFilterFile> -->      </configuration>       <executions>        <execution>          <id>run-findbugs</id>          <!-- 在install 階段觸發(fā)執(zhí)行findbugs檢查,比如執(zhí)行 mvn clean package-->          <phase>install</phase>           <goals>            <goal>check</goal>          </goals>        </execution>      </executions>    </plugin>          </plugins>  </build>  <properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    <compiler.source>1.7</compiler.source>    <compiler.target>1.7</compiler.target>    <!-- 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) -->    <servlet.version>3.1.0</servlet.version>    <jsp.version>2.3.1</jsp.version>    <jstl.version>1.2</jstl.version>    <junit.version>4.12</junit.version>  </properties>  <dependencies>    <dependency>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-clean-plugin</artifactId>      <version>2.5</version>    </dependency>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>${junit.version}</version>      <scope>test</scope>    </dependency>    <dependency>      <groupId>javax.servlet</groupId>      <artifactId>javax.servlet-api</artifactId>      <version>${servlet.version}</version>      <scope>provided</scope>    </dependency>    <dependency>      <groupId>javax.servlet.jsp</groupId>      <artifactId>javax.servlet.jsp-api</artifactId>      <version>${jsp.version}</version>      <scope>provided</scope>    </dependency>    <dependency>      <groupId>javax.servlet</groupId>      <artifactId>jstl</artifactId>      <version>${jstl.version}</version>    </dependency>  </dependencies></project>

(6)jenkins構(gòu)建項(xiàng)目時(shí),前面的配置一如往常,可以查看其它的案例

主要配置 源碼管理,構(gòu)建觸發(fā)器,build,構(gòu)建后操作

Docker容器,jenkins,web項(xiàng)目

然后部署可以訪問了

http://172.150.12.32:8080/WebdemoIn7

書寫Shell腳本來構(gòu)建Java Web鏡像和容器:

1.在Post Steps目錄中選擇

Docker容器,jenkins,web項(xiàng)目

填寫如下Shell腳本

#!/bin/bashimageId=`sudo docker images|grep -i test|awk '{print $3}'`echo "Test鏡像ID = "$imageId containId=`sudo docker ps -a |grep -i test|awk '{print $1}'`echo "Test容器ID = "$containIdproject=/var/jenkins_home/workspace/test/src/main/resources/docker#判斷是否存在舊的Test鏡像if test -z "$imageId"thenecho "Test鏡像不存在"else if test -z "$containId"thenecho "Test容器不存在"elseecho "Test容器將要被執(zhí)行stop命令"sudo docker stop testecho "Test容器處于stop狀態(tài)"fiecho "舊Test鏡像將要被刪除"sudo docker rmi -f $imageIdecho "成功刪除舊Test鏡像" fi#Dockerfile所在目錄sudo mv $project/Dockerfile /usr#切換目錄至usrcd /usr#將Tms war包拷貝到Dockerfile所在目錄下sudo mv /var/jenkins_home/workspace/test/target/test.war . echo "Test鏡像構(gòu)建中:------->"#構(gòu)建Tms鏡像sudo docker build -t test .#判斷是否存在舊的Tms容器if test -z "$containId"thenecho "Test容器不存在"else echo "舊Test容器將要被刪除"sudo docker rm -f $containIdecho "成功刪除舊Test容器" fi#創(chuàng)建容器echo "開始創(chuàng)建新Test容器"sudo docker run -d -p 8088:8080 -v /usr/logs:/usr/tomcat/logs --name test test

echo "新Test容器創(chuàng)建成功"

2.點(diǎn)擊立即保存,立即構(gòu)建

Docker容器,jenkins,web項(xiàng)目

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到服務(wù)器教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 上杭县| 隆子县| 库伦旗| 宜州市| 临邑县| 祁东县| 漳州市| 泗阳县| 抚顺县| 家居| 育儿| 长泰县| 古蔺县| 洪湖市| 金湖县| 金川县| 镇巴县| 突泉县| 普兰店市| 资源县| 昌江| 宾阳县| 介休市| 安泽县| 常山县| 马鞍山市| 临海市| 桃园县| 民权县| 平和县| 蓬安县| 义马市| 鲜城| 通州区| 南澳县| 白朗县| 武汉市| 广饶县| 南丰县| 洛隆县| 清流县|