Deploy maven project based on Jianmu CI

Posted by lrsdsout on Tue, 07 Dec 2021 12:18:46 +0100

1. Preparatory work

Operating environment:

  • Test environment:
    • Operating system: Centos7
    • cpu: Quad Core
    • Memory: 4G
    • docker version: 20.10.8
  • Jianmu CI version: v2.0.0

2. How to install Jianmu CI

Use docker compose for deployment. For detailed instructions on how to use docker compose, please refer to the official docker document: https://docs.docker.com/compose/

  • Download the docker compose file of Jianmu CI:

    wget https://gitee.com/jianmu-dev/jianmu-deploy/raw/master/docker-compose.yml

  • To start a log CI:

    Execute docker compose up - D

    After a long wait, the image required by Jianmu CI has been pulled down and started

  • Take a look at the activated container

    It can be seen that Jianmu CI consists of Jianmu CI UI, Jianmu CI server and a mysql8

    Jianmu CI UI is developed by vue3, and Jianmu CI server is a java project developed by spring boot. Use the standard front and rear end separation development method

  • Visit the Jianmu CI we just started, enter our ip, and the port is the default port of 80. It is found that the project has been started and completed

  • For other methods and details of installing Jianmu Ci, please refer to the official document of Jianmu CI: https://docs.jianmu.dev

3. Start to use Jianmu CI to quickly build maven project

The steps are as follows:

  1. Select suitable nodes: nodes are the soul of Jianmu CI. Jianmu CI completes business operations by operating these nodes. Each node has its own specific responsibilities. Each node only completes one thing. Jianmu CI completes a series of process operations by arranging nodes
  2. Create the configuration file of Jianmu CI process: in Jianmu Ci, when we want to complete a business operation, we first define its process. This process is actually an arrangement of our nodes. Through this arrangement, together with our own specific business parameters, we flow between the arranged nodes to complete our business operations
  3. Based on Jianmu CI platform, run the above process configuration file

3.1 create a configuration file for the CI process

The following is a detailed description of the process configuration file of Jianmu CI

  • What is a process profile: a process profile is a DSL (domain specific language). When we want to complete a series of operations (it may be the ci/cd process of the project or the process that eliminates our repeated operations), our programmers define the process in a way that we can understand, and Jianmu Ci uses yaml to define the process

    The DSL of Jianmu CI provides two syntax

  1. Workflow definition (DSL): the process definition specifies how our process goes, with branch selection and conditional judgment. These logics work together to complete one of our process definitions, as shown in the following figure

  2. Pipeline definition (DSL): pipeline definition is like a "no bifurcation" process definition. There is no branch selection and no conditional judgment. A node follows a node like a pipeline. Because there are many pipeline processes in the real business scenario, Jianmu CI has launched this type of process DSL, as shown in the following figure

  • When defining this process, we need to understand our purpose: we need to deploy our maven project and then select the appropriate nodes
  1. First, we need to clone the project from our warehouse by using the git clone node
  2. After git the project, we will build our project, use the maven build node to make the project into a docker image, and push it to our docker hub warehouse
  3. After push ing to our own warehouse, we need to find a way to start the project. We will use the docker pull and docker run commands to start the project, so we use the ssh execution command node to pull down the image and run it
  4. After the project deployment is completed, someone has to tell us that the project deployment is completed, so we use the enterprise wechat notification node to notify us that the project deployment is completed
  5. Are the above steps linked one by one, so we use the pipeline definition to complete the deployment of this maven project
  • Let's start the process DSL configuration

    1. Configuration of root DSL

      # Name of the process DSL
      name: hello Jianmu CI
      # Description of process DSL
      description: Jianmu CI Rapid deployment maven project
      # Globally defined environment variables
      global:
      param:
         # Environment variable name and value
        image_name: my-docker-hub-username/jianmu-build-maven-project
      # Indicates that pipe DSL is used, and all the following nodes are configured under pipeline
      pipeline:
      
    2. git clone node

       # git clone
      git_clone:
         # Use the version of git clone
        type: git_clone:1.2.0
         # Input parameters when using git clone parameter
        param:
           # Configure the remote git source, that is, the url from which to clone the project
          remote_url: https://gitee.com/canon_xi/hello-jianmu.git
      
    3. maven build node

      # maven build
      maven_jib_build:
         # maven build version
        type: maven_build:1.3.1-jdk11
        param:
           # maven build behavior
          mvn_action: install
           # Under which directory to build, the ${git_clone.git_path} here represents git from the previous node_ Input parameter git of clone_ Path, which can also be understood as taking environment variables, and the output parameters of the node will become environment variables
          workspace: ${git_clone.git_path}
           # The name of the image used in image creation is the global environment variable configured by the root DSL
          image_name: ${global.image_name}
           # The tag specified when mirroring
          image_tag: ${git_clone.git_branch}
           # Our image will be push ed into the docker hub. You need to specify the user name of the docker hub.
           # Many times, our business parameters contain some private information, which we don't want to show in clear text. Jianmu CI also provides the function of key management
           # We use the syntax of ((...)) to get its value from Jianmu CI key management
           # For more information on key usage and details, refer to: https://docs.jianmu.dev/guide/secrets.html
          docker_username: ((docker_hub.username))
           # Specify the password for the docker hub
          docker_password: ((docker_hub.password))
           # Where can we pull dependencies from our maven project? Here we use Alibaba cloud's image to pull dependencies
          maven_public_url: https://maven.aliyun.com/repository/public
      
    4. ssh execution

       # ssh execution
      deploy_server:
         # ssh_cmd version
        type: ssh_cmd:1.0.1
        param:
           # On which machine do you execute commands and configure ip
          ssh_ip: xxx.xxx.xxx.xxxx
           # The private key of the target machine. The key management platform provided by Jianmu CI is used here
          ssh_private_key: ((jianmu_ci.server_private_key))
           # Specific commands executed
          ssh_cmd: >-
            docker pull my-docker-hub-username/jianmu-build-maven-project:master
            &&
            docker run -d --name helloJianmu -p8888:8888 my-docker-hub-username/jianmu-build-maven-project:master
            &&
            echo done
      
    5. Enterprise wechat sending information

       # Enterprise wechat sending information
      send_message:
         # Version of information sent by enterprise wechat
        type: qywx_notice:1.2.1
        param:
           # The callback address of wechat robot is also managed with the key of Jianmu CI
          bot_webhook_url: ((charbot.webhook_url))
          mentioned_moblie_list: "[]"
           # Specific information sent
          text_content: "Jianmu CI Rapid deployment maven Project completion"
          msgtype: "text"
          mentioned_list: "[]"
      
  • For how to configure the process DSL of Jianmu CI platform, you can also refer to the process arrangement link in the official document of Jianmu CI: https://docs.jianmu.dev

  • Combine the above DSLs to form a detailed process DSL configuration:

    name: hello Jianmu CI
    description: Jianmu CI Rapid deployment maven project
    # Globally defined phase variables
    global:
    param:
      image_name: my-docker-hub-username/jianmu-build-maven-project
    # Use pipe DSL
    pipeline:
     # git clone
    git_clone:
      type: git_clone:1.2.0
      param:
        remote_url: https://gitee.com/canon_xi/hello-jianmu.git
     # maven build
    maven_jib_build:
      type: maven_build:1.3.1-jdk11
      param:
        mvn_action: install
        workspace: ${git_clone.git_path}
        image_name: ${global.image_name}
        image_tag: ${git_clone.git_branch}
        docker_username: ((docker_hub.username))
        docker_password: ((docker_hub.password))
        maven_public_url: https://maven.aliyun.com/repository/public
     # ssh execution
    deploy_server:
      type: ssh_cmd:1.0.1
      param:
        ssh_ip: xxx.xxx.xxx.xxxx
        ssh_private_key: ((jianmu_ci.server_private_key))
        ssh_cmd: >-
          docker pull my-docker-hub-username/jianmu-build-maven-project:master
          &&
          docker run -d --name helloJianmu -p8888:8888 my-docker-hub-username/jianmu-build-maven-project:master
          &&
          echo done
     # Enterprise wechat sending information
    send_message:
      type: qywx_notice:1.2.1
      param:
        bot_webhook_url: ((charbot.webhook_url))
        mentioned_moblie_list: "[]"
        text_content: "Jianmu CI Rapid deployment maven Project completion"
        msgtype: "text"
        mentioned_list: "[]"
    
  • Configure process DSL in Jianmu CI

    Click Add Item

    Add process DSL

  • After adding successfully, hello appears on the dashboard of Jianmu CI

  • Click in to see

    Everything is ready to go

  • Click the start button

  • Wait a minute and you can see

    Run completed

  • View the process log of each node

    No exceptions are found. At this time, the Jianmu CI rapid deployment maven project process is completed

    Our enterprise wechat has also received the notification of successful deployment

3.2 visit the project we just deployed

Visit ip:8888/jianmu/hello to get "Hello jianmu"

@RestController
@RequestMapping("jianmu")
public class HelloJianmuController {
   @GetMapping("hello")
   public String helloJianmu(){
       return "Hello jianmu";
  }
}
--------- application.yml------------
server:
 port: 8888

Get greetings from Jianmu CI

Topics: Docker Maven DevOps ci