I have shared some techniques for using Jenkins for automated deployment . Recently, I found an IDEA plug-in produced by Ali CloudToolkit
, which not only supports direct packaging and deployment of applications to remote servers, but also can be used as a terminal tool. I tried this plugin, it's very good, I recommend it to everyone! With this plug-in installed, IDEA one-stop development is one step closer!
SpringBoot actual e-commerce project mall (50k+star) address: https://github.com/macrozheng/mall
Introduction to CloudToolkit
CloudToolkit
is an IDEA plug-in produced by Ali, through which we can realize automatic deployment more conveniently, and its built-in terminal tools and file upload function are very convenient even for server management! Not only is this IDEA plugin powerful, it's completely free!
Install
The installation of CloudToolkit is very simple, search directly in IDEA's plug-in market Cloud Toolkit
and then install it.
use
Next, let's experience the automated deployment function of CloudToolkit, take the SpringBoot application packaged and deployed to the Docker environment as an example, to see if it is good enough.
Automated deployment
- After the plugin is installed, open the left panel, right click
Host
icon, we can add the connection information of the server, and the connection information needs to be configured before automatic deployment;
- Under normal circumstances, if we want to deploy the local SpringBoot application to the Docker environment, we need to go through the following steps. Using CloudToolkit, we only need to configure the process, and it will help us to complete these operations automatically;
- First, prepare the Dockerfile file required to package the application image;
# 该镜像需要依赖的基础镜像
FROM java:8
# 将当前目录下的jar包复制到docker容器的/目录下
ADD mall-tiny-deploy-1.0-SNAPSHOT.jar /mall-tiny-deploy-1.0-SNAPSHOT.jar
# 声明服务运行在8088端口
EXPOSE 8088
# 指定docker容器启动时运行jar包
ENTRYPOINT ["java", "-jar","/mall-tiny-deploy-1.0-SNAPSHOT.jar"]
# 指定维护者的名字
MAINTAINER macrozheng
- Then prepare the script that can automatically package the application image, create and run the container
run.sh
, the specific use of these two scripts can refer to the skills of using Jenkins for automated deployment ;
#!/usr/bin/env bash
# 定义应用组名
group_name='mall-tiny'
# 定义应用名称
app_name='mall-tiny-deploy'
# 定义应用版本
app_version='1.0-SNAPSHOT'
# 定义应用环境
profile_active='prod'
echo '----copy jar----'
docker stop ${app_name}
echo '----stop container----'
docker rm ${app_name}
echo '----rm container----'
docker rmi ${group_name}/${app_name}:${app_version}
echo '----rm image----'
# 打包编译docker镜像
docker build -t ${group_name}/${app_name}:${app_version} .
echo '----build image----'
docker run -p 8088:8088 --name ${app_name} \
--link mysql:db \
-e 'spring.profiles.active'=${profile_active} \
-e TZ="Asia/Shanghai" \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/${app_name}/logs:/var/logs \
-d ${group_name}/${app_name}:${app_version}
echo '----start container----'
- Upload these two files to the Linux server and add executable permissions to
run.sh
;
- Right-click the project to be deployed, click
Deploy to Host
;
- Then choose to upload the Jar package packaged by Maven to the specified directory, and execute the
run.sh
script after the upload is complete;
- Next, edit the goal of Maven's build, and only package the
mall-tiny-deploy
module;
- Then modify the advanced settings and configure the command to view the container log;
- Finally, run the configuration, and you can directly view the application operation log after the operation is completed;
- Open the Swagger page of the application and see that it can be accessed normally. The access address is: http://192.168.3.105:8088/swagger-ui/
Common Functions
- Of course, the functions of CloudToolkit are far more than that. It has a built-in terminal tool to manage Linux servers in IDEA. It is enough to use it. You can open it directly through the bottom panel and click the
终端
button;
- I have experienced this terminal tool, and the prompts are quite complete. What Xshell is needed now?
- You can upload files through the upload function, and WinSCP is no longer needed!
Summarize
I have experienced a CloudToolkit produced by Alibaba. After the configuration is done, it is basically possible to deploy applications to remote servers with one click. It is not an exaggeration to say that it is the IDEA version of Jenkins! Its built-in terminal tool is also very easy to use, and it is strongly recommended that you try it out!
Project source code address
https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-deploy
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。