One-click remote deployment to tomcat using cargo

Recently, I took over several Tomcat web applets. Every time the function goes online, it has to be deployed to the remote development environment and production environment. There are quite a lot of operation steps, and I found it based on the principle that the machine can do it and never do it manually. After comparing several automatic deployment schemes, we found that maven's cargo-maven2-plugin plugin is the most suitable for the current scenario. Let me share it.

The working principle of this plug-in is to use the manager application that comes with tomcat to deploy web applications. The project introduction https://codehaus-cargo.github.io/cargo/Home.html

The steps to be done are also quite simple. tomcat8 as an example. First make sure that the manager application already exists under tomcat in the remote environment to be deployed, then configure the role username and password accessed by the manager under tomcat8, modify the tomcat8/conf/tomcat-users.xml file, and add the following configuration:

Xml code   Favorite code
  1. <role rolename="manager-gui"/>  
  2. <role rolename="manager-script"/>  
  3. <role rolename="manager-jmx"/>  
  4. <role rolename="manager-status"/>  
  5. <user username="admin" password="123456" roles="manager-gui,manager-script,manager-jmx,manager-status"/>  

In order to allow users to access manager as text, it is best to configure all four tomcat predefined roles manager-gui, manager-script, manager-jmx, manager-status on the assigned username and

then in the actual web project Add the plugin configuration to the pom file:

Xml code   Favorite code
  1. <plugin>  
  2.     <groupId>org.codehaus.cargo</groupId>  
  3.     <artifactId>cargo-maven2-plugin</artifactId>  
  4.     <version>1.5.0</version>  
  5.     <configuration>  
  6.         <container>  
  7.             <containerId>tomcat8x</containerId>  
  8.             <type>remote</type>  
  9.         </container>  
  10.         <configuration>  
  11.             <type>runtime</type>  
  12.             <properties>  
  13.                 <cargo.protocol>http</cargo.protocol>  
  14.                 < cargo.hostname > actual domain name </ cargo.hostname >  
  15.                 < cargo.servlet.port > actual port number </ cargo.servlet.port >  
  16.                 <cargo.remote.username>admin</cargo.remote.username>  
  17.                 <cargo.remote.password>123456</cargo.remote.password>  
  18.                 < cargo.remote.uri > http://actual domain name:actual port number/manager/text </ cargo.remote.uri >  
  19.             </properties>  
  20.         </configuration>  
  21.     </configuration>  
  22. </plugin>  

cargo.remote.username and cargo.remote.password are the username and password of the user node in the tomcat-users.xml file configured above, and http://actual domain name:actual port number/ in cargo.remote.uri is the remote deployment The root path address that tomcat actually accesses.

Finally, run the command in the web project root directory:

Txt code   Favorite code
  1. mvn org.codehaus.cargo:cargo-maven2-plugin:redeploy  

One-click remote deployment of web applications is done.

If you want the command to be shorter, you can add a pluginGroup to maven's settings.xml:

Xml code   Favorite code
  1. <pluginGroups>  
  2.        <pluginGroup>org.codehaus.cargo</pluginGroup>  
  3. </pluginGroups>  

This command can be abbreviated as:

Txt code   Favorite code
  1. mvn cargo:redeploy  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326522913&siteId=291194637