五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動(dòng)態(tài)

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

發(fā)布日期:2022-03-30 08:27 | 文章來源:源碼之家

(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 code
mvn clean install
#recieve the execute result
result=$?
#output the result ,if the result less or equal 0 ,it proves this project has bugs,otherwise don't.
echo $result
if [ $result -ne 0 ]
then
  mvn findbugs:gui
  echo "REGRETFUL! BUILD FAILURE"
  exit 1
else
  echo "CONGRATURATION! BUILD SUCCESS"
  exit 0
fi

注釋: 配置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)建后操作

然后部署可以訪問了

http://172.150.12.32:8080/WebdemoIn7

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

1.在Post Steps目錄中選擇

填寫如下Shell腳本

#!/bin/bash
imageId=`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 = "$containId
project=/var/jenkins_home/workspace/test/src/main/resources/docker
#判斷是否存在舊的Test鏡像
if test -z "$imageId"
then
echo "Test鏡像不存在"
else 
if test -z "$containId"
then
echo "Test容器不存在"
else
echo "Test容器將要被執(zhí)行stop命令"
sudo docker stop test
echo "Test容器處于stop狀態(tài)"
fi
echo "舊Test鏡像將要被刪除"
sudo docker rmi -f $imageId
echo "成功刪除舊Test鏡像" 
fi
#Dockerfile所在目錄
sudo mv $project/Dockerfile /usr
#切換目錄至usr
cd /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"
then
echo "Test容器不存在"
else 
echo "舊Test容器將要被刪除"
sudo docker rm -f $containId
echo "成功刪除舊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)建

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

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對(duì)1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部