The introduction

In the face of more and more microservices, more and more frequent version releases, last weekend at home, it was Jenkins + Docker continuous integration and continuous delivery.

== If you send a push tag to a Git server and wait for an email to announce a new release, it will automatically trigger a project build and release.

Let’s share my practice with you.

Principle of continuous integration

Continuous Integration (CI).

  • As an important step in agile development, CI aims to keep products as high quality as possible while iterating quickly.
  • CI is a development practice that increases project visibility and reduces the risk of project failure. For each code update, the correctness of the code and function should be tested through automated tests. Only the code that passes the automatic tests can be delivered and deployed later.
  • CI is to better coordinate work among team members (production and research), better adapt to agile iterative development, automatically complete and reduce manual intervention, and ensure that the code submitted by team members at each time point can be successfully integrated. It can be well used for the packaging of various WEB and APP projects.

Jenkins

Jenkins is an open source continuous integration tool written in Java, providing continuous integration services for software development, which can monitor and trigger continuous and repeated work. It has the characteristics of open source, supporting multi-platform and plug-in extension, easy installation, interface management and so on.

Attached is Jenkins continuous delivery flow chart online

Continuous integration, the use of some of the typical tools used in each phase of continuous delivery, and the associated activities of the teams involved in each phase, are shown below as typical DevOPs-related activities

Jenkins and Docker private repository Registry environment installation

Please install and configure Docker acceleration first (you get the idea!). , have not played the students please baidu first.

Jenkins installation

Docker install Jenkins very convenient to execute the following script OK

docker run --name devops-jenkins --user=root -p 8080:8080 -p 50000:50000 -v /opt/data/jenkins_home:/var/jenkins_home -d jenkins/jenkins:lts
Copy the code

You can refer to https://github.com/jenkinsci/docker need more customization parameters

The registry is installed

docker run --name devops-registry -p 5000:5000 -v /opt/devdata/registry:/var/lib/registry -d registry
Copy the code

Jenkins configuration

Initialize Jenkins and install plugins

After enabling Jenkins, enter http://host IP address of Jenkins deployment: port in the browser

docker logs devops-jenkins
Copy the code

View this password as follows:

Choose to install the plug-in mode, here I am the default first

The plug-in installation screen is displayed, and the network is connected to wait for the plug-in installation

After the plug-in is installed, the page for creating administrators is displayed

After entering the administrator account, click continue as Admin to enter the administration interface and click System Administration – Plug-in Management to install the Docker build plug-in and role management plug-in

Install the Docker build plug-in and look for the Docker Build Step Plugin in the optional plug-ins

Install the Role management plug-in and search for role-based Authorization Strategy in the optional plug-in

Install SSH plug-in, which is used to execute remote server script to obtain image from docker local repository and release new version after successful build

Install the Email Extension Plugin to configure automatic Email sending

Configure Jenkins attributes and related permissions

Jenkins properties

Click System Administration ->Global Tool Configuration-> Find JDK and click add button (please register your account with Oracle for automatic installation)

Choose System Administration > System Settings to configure SSH

Configuration docker

Set the Docker host to be accessible remotely

Vim/usr/lib/systemd/system/docker. Service in ExecStart = / usr/bin/docker daemon after additional -h TCP: / / 0.0.0.0:2375 - H Unix: / / / var/run/docker. The sock, such as: ExecStart = / usr/bin/docker daemon - H TCP: / / 0.0.0.0:2375 - H Unix: / / / var/run/docker. The sockCopy the code

Configure mail

Jenkins permissions

  1. Choose System Administration ->Configuration Global Security-> Select Enable Security: TCP port for JNLP agents -> Disable, Access control – Security domain -> Jenkins proprietary user database, Access control – Authorization policy -> role-based Strategy
  2. Choose System Administration ->Manage and Assign Roles->Manage Roles:
  • Add Global Roles(admin, member, OPS, others) Set global roles (Global roles can set Jenkins system and perform operations on Jenkins projects) admin: can perform operations on Jenkins. Ops: can manage all jobs. Other /member: only has read permission
  • Add project Roles(DMP-manager, DMP-view, Tsc-manager, or Tsc-view) and assign the following permissions to the Roles
  • Note: When adding Project Roles, if you want different users to see different jobs, you must set Pattern. For example, for Roles dmp_manager, only jobs starting with DMP can be viewed. The Pattern rule must be DMP. The same is true for TSC.
  1. Choose System Management > Manage User: Create several administrator users, such as dmpadmin and tscadmin

  2. Assign Roles >Manage and Assign Roles >Assign Relos add the user to user/group and Assign the assigned Roles as follows:

Create – compile – Package – Upload a Docker image task – Execute a remote script to obtain the image from a private repository. Release the new version

Source code management

Build trigger

Such as http://admin:[email protected]:8080/generic-webhook-trigger/invoke

build

1. Maven construction Project 2. Construct docker image 3

Post-build operation

Send email Push

Build validation

It’s time for a miracle

Click Build Now

A success email is automatically sent after the build is successful