1
头图
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
 #!/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;

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


macrozheng
1.1k 声望1.3k 粉丝