Cloud Toolkit packages springcloud project multi-module

What is Cloud Toolkit

Cloud Toolkit is a free local IDE plug-in that helps developers develop, test, diagnose, and deploy applications more efficiently. Through plug-ins, local applications can be deployed to any server, even the cloud (ECS, EDAS, ACK, ACR, and applet cloud, etc.) with one click; Arthas diagnosis, Dubbo tools, Terminal, file upload, function computing and Tools such as MySQL executor.

First add in the pom of the parent project

/Users/kaifa/Documents/lxh/xxx-new/jar是你的jar打包后存放的地址  
   <properties>
        <!--打包配置-->
        <copy>true</copy>
        <localDir>/Users/kaifa/Documents/lxh/xxx-new/jar</localDir>
    </properties>

The submodule pom is added so that the current submodule can be entered into the specified directory when the package is executed. If the install is executed, please add

 <phase>package</phase>改为 <phase>install</phase>

<!--复制jar包到指定文件目录,连接服务器,复制文件到服务器-->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id><!--需要唯一-->
                        <phase>package</phase><!--当执行package操作时执行一下任务-->
                        <configuration>
                            <tasks><!--任务-->
                                <echo message="start.................................."/><!--打印-->
                                <echo message="load maven plugin ant-contrib-1.0b3"/>
                                <!--加载plugin ant-contrib的配置文件-->
                                <taskdef resource="net/sf/antcontrib/antlib.xml">
                                    <classpath><!--加载jar包,${settings.localRepository}的值是你maven settings文件中配置的本地仓库位置-->
                                        <pathelement location="${settings.localRepository}/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
                                    </classpath>
                                </taskdef>
                                <!--复制jar包-->
                                <if>
                                    <equals arg1="${copy}" arg2="true"/><!--是否复制jar包-->
                                    <then>
                                        <echo message="Copy jar to your desired path."/>
                                        <copy todir="${localDir}" overwrite="true"><!--执行复制操作,todir的值是将要复制jar包到的地方,overwrite是否重写-->
                                            <fileset dir="${project.build.directory}"><!--${project.build.directory}值是你的target目录-->
                                                <include name="*.jar"/><!--target目录下的jar包-->
                                            </fileset>
                                        </copy>
                                    </then>
                                </if>
                                <!--打印-->
                                <echo message="pom type:${project.packaging}"/>
                                <echo message="target path:${project.build.directory}"/>
                                <echo message="maven local repository:${settings.localRepository}"/>
                                <echo message="if pom type equals pom,delete ant generate target and antrun folder"/>
                                <echo message="${project.build.finalName}"></echo>
                                <!--
                                因为 maven-antrun-plugin 执行后,会在你的项目中生成一个target/antrun/build-main.xml,
                                在packageing=pom的项目下也会生成一个这样的文件和文件目录,个人觉得很烦,索引引入ant-contrib依赖,
                                如果你觉得不烦,可以不添加ant-contrib依赖,下边的if标签也不能使用.
                                -->
                                <!--删除-->
                                <if><!--if 标签-->
                                    <equals arg1="${project.packaging}" arg2="pom"/> <!--判断当前pom文件的packageing是否是pom类型,-->
                                    <then><!--如果是pom类型则删除 该项目下的target目录-->
                                        <echo message="delete ${project.build.directory}"/>
                                        <delete dir="${project.build.directory}"/>
                                    </then>
                                </if>
                               
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Start using Cloud Toolkit to package. Deploy Spring Boot / Spring Cloud applications to Alibaba Cloud in Intellij IDEA. IDEA2019 is used here. First install the Alibaba Cloud Toolkit plug-in

Installation tutorial https://yq.aliyun.com/articles/674021?spm=5176.11997469.1283546..7a8f2fa8U2VOhA&aly_as=FgAcVHLg

1. Select Tools -> Alibaba Cloud View -> Host as shown in the figure

2. Click on the server name, username and password entered in add host to test the connection and then click on add

upload is used to upload files. Termianl is the command corresponding to your server. The console command is the place to enter the command.

In More, there are some operations such as deleting the current connection and editing, as shown in the figure

3. Click Edit Confugurations... -> click + to add Deploy to Host as shown in the figure

4. Choose a jar address packaged and stored in your server's Target Directory

After deplay fill in the script you executed after packaging (the script is at the end)

Multi-module needs to add sub-module clean package operation in before launch as shown in the figure

Multi-module packaging  https://yq.aliyun.com/articles/676151

 5. Switch upload file and click browse to add the jar you want to upload

6. Switch to advanced and fill in the script you executed before packaging (the script is at the end) click apply -> ok

7. Click run to execute and then view the log. Wait for the execution to be completed. First execute eureka and then execute config before executing the commands of other services after the startup.

before.sh script

#!/bin/bash
echo "before打包前执行"
source /etc/profile
ps -ef|grep xxxx-eureka|grep -v "grep"|awk '{print $2}'|xargs kill -9
ps -ef|grep xxxx-config|grep -v "grep"|awk '{print $2}'|xargs kill -9
ps -ef|grep xxxx-gateway|grep -v "grep"|awk '{print $2}'|xargs kill -9
ps -ef|grep xxxx-user|grep -v "grep"|awk '{print $2}'|xargs kill -9
ps -ef|grep xxxx-activity|grep -v "grep"|awk '{print $2}'|xargs kill -9
ps -ef|grep xxxx-search|grep -v "grep"|awk '{print $2}'|xargs kill -9
cd /usr/jarprod
rm -rf  xxxx-*
echo "before执行结束"

after.sh script

source /etc/profile
nohup java -Xms128m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar  /usr/jarprod/xxx-eureka.jar > /dev/null 2>&1 &
RESULT=000
while [[ $RESULT != "200" ]]; do
RESULT=$(curl -I -m 10 -o /dev/null -s -w %{http_code} xxx-new:xxx-new@localhost:8761)
echo eureka $RESULT
sleep 5
done
nohup java -Xms128m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar /usr/jarprod/xxx-config.jar  --spring.profiles.active=native > /dev/null 2>&1 &
RESULT2=000
while [[ $RESULT2 != "200" ]]; do
RESULT2=$(curl -I -m 10 -o /dev/null -s -w %{http_code} localhost:8888/actuator/info)
echo config $RESULT2
sleep 5
done
echo gateway
nohup java -Xms128m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar /usr/jarprod/xxx-gateway.jar --spring.profiles.active=test > /dev/null 2>&1 &

echo activity
nohup java -Xms128m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar  /usr/jarprod/xxx-activity.jar --spring.profiles.active=test > /dev/null 2>&1 &

echo user
nohup java -Xms128m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar  /usr/jarprod/xxx-user.jar --spring.profiles.active=test > /dev/null 2>&1 &
echo search
nohup java -Xms128m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar /usr/jarprod/xxx-search.jar --spring.profiles.active=test > /dev/null 2>&1 &
exit

Refer to official documents

Official website address  https://toolkit.aliyun.com

Use Cloud Toolkit to package  https://yq.aliyun.com/articles/665693

Cloud Toolkit upload files to remote server  https://yq.aliyun.com/articles/686715?spm=5176.11997469.1283546.20.7a8f2fa8U2VOhA&aly_as=cNz16eod

https://yq.aliyun.com/articles/680157?spm=5176.11997469.1283546.19.7a8f2fa8U2VOhA&aly_as=7Nu5SVxF

Guess you like

Origin blog.csdn.net/qq_39313596/article/details/103731836