SpringBoot e-Commerce project mall (25K + STAR) address: github.com/macrozheng/…

Abstract

In a microservice architecture, as more and more services become available, the packaging and deployment of services becomes quite a hassle. For example, there are currently 8 services to be deployed in my mall-swarm project. Is there any way that we can deploy them automatically as long as we click execute after we deploy them once? B: of course! Let’s use Jenkins to automate deployment in a microservice architecture.

Basic use of Jenkins

The basic use of Jenkins can be described as follows: Use Jenkins to package and deploy SpringBoot applications with one click.

Preparing for executing scripts

First let’s get the scripts ready for remote execution.

  • Script files are storedmall-swarmThe project/document/shDirectory:

  • Change the newline format of all script files in IDEA toLFOtherwise, the script cannot be executed.

  • Upload all script files to the specified directory, as we did here/mydata/shDirectory;

  • Change all script files to executable files:
chmod +x ./mall-*
Copy the code

Create a task in Jenkins

Next we will automate deployment by creating tasks in Jenkins. Because our mall-Swarm is a multi-module project, the deployment above is different from the previous single-module project.

mall-admin

Since the creation of the execution tasks for each module is similar, the creation of the tasks for the mall-admin module will be explained in detail below, and the other modules will be covered briefly.

  • First we chooseBuild a free-style software projectAnd then enter the task name as mall-admin and configure the Git repository address. Here I directly use the address above Gitee:

  • And then we create a build, buildmall-swarmDependency modules in the project that would otherwise fail when building working service modules because they cannot be found;
Install ml-common, ml-mbg, and ml-security
clean install -pl mall-common,mall-mbg,mall-security -am
Copy the code
  • Schematic diagram of dependent project construction:

  • Create another build to build and package the mall-admin module separately:

  • Add a build to perform remote tasks over SSH to execute the mall-admin run script:

  • Click Save to complete the creation of the mall-admin task.

mall-registry

Mall-registry and other modules create tasks in the same way as mall-admin. You only need to change the location of the POM.xml file and script execution when building the module.

  • We can create one directly from the task of the mall-admin module:

  • Modify the pom.xml file location in the second build to:${WORKSPACE}/mall-registry/pom.xml

  • Change the SSH execution script file location in the third build to:/mydata/sh/mall-registry.sh

  • Click Save to complete the creation of the execution task of mall- Registry.

Other modules

For other modules, refer to the creation of mall-admin and mall- Registry.

Task creation complete

The module startup sequence is incorrect

As for the startup order of each module, the mall- Registry module must be started first, the mall-config module must be started second, and the other modules have no restriction on the startup order.

Recommended boot sequence:

  • mall-registry
  • mall-config
  • mall-monitor
  • mall-gateway
  • mall-admin
  • mall-portal
  • mall-search
  • mall-demo

conclusion

By creating tasks in Jenkins, we completed the packaging and deployment of services in microservice architecture. In this way, after modifying the code each time, we only need to click the start task to achieve one-click packaging and deployment, saving the trouble of frequent packaging and deployment.

The project address

Github.com/macrozheng/…

The public,

Mall project full set of learning tutorials serialized, attention to the public number the first time access.