The original article is from my own blog yuequan’s blog

I originally wanted to write an enterprise-level general CI/CD, but it was too troublesome, involving a wide range of knowledge points, I first write a simple introduction, later see if there is a chance to share a recent study of enterprise-level general CI/CD scheme, with a SpringBoot project as an example.

If you have any good plan, you can add wechat or email and we can discuss it together

The release process is shown in figure

My server environment is

  • CentOS7
  • Docker 18.03.0 – ce
  • DockerCompose 1.19.0

The technologies used in this project are

  • Docker
  • Docker Compose
  • Jenkins

For convenience, I made a Docker-Jenkins to be careful

For the sake of this demonstration, I’m going to use the GitLab repository so that you don’t have to create your own Git repository, so that you can quickly and easily experience this simple continuous integration solution. However, the disadvantage of this method is that if you don’t have Intranet mapping or a separate server, You cannot access the Jenkins server interface using Git WebHook

Create a repository and push your project to that repository.

Okay, let’s get started, make sure you have Docker and Docker-compose installed before you get started first create a Jenkins folder and then bring down my GayHub repository docker-compsoe.yml, For convenience I have submitted the image to the Docker repository. If you don’t have speedup or some other way, you can download the Dockerfile and build it yourself

mkdir jenkins && cd jenkins

wget https://raw.githubusercontent.com/yuequan1997/docker-jenkins/master/docker-compose.yml

docker-compose up -d
Copy the code

Use docker PS to check if the container is running

then

Docker logs container IDCopy the code

Notice the area I’ve circled in red. If not, and if there is no exception, please wait and copy the encrypted string of characters

As my is: 61 cfaad2c6a94b7ebb54deafac051150

http://server IP address :8080/
docker-compose.yml

Paste the duplicate key and click Continue

Just go ahead and click on this

Once it is installed, you can also use the dokcer logs command to see which console is currently running

Create an Account

Then go to the console, system Administration = “manage plug-ins, then select the optional plug-ins, install the following plug-ins, using the filter in the upper right corner

  • Publish Over SSH
  • Gitlab
  • Gitlab Hook
  • Maven Integration

Since my project is built using Maven and installed with maven plugins, I select it directly

In the General option, I configured to keep 10 old builds

Configure your Git repository

Build trigger select this

Then click Advanced, where a secret key is generated and only the Master branch is allowed to trigger the Webhook build

Then configure build. It will ask you for your Maven configuration. Click the link to configure it

For simplicity, I’m not going to set the address, so I’m going to use auto-install. If you don’t want auto-install, you can remove this option and type MAVEN_HOME

After the configuration, MY configuration content is as follows. I used the docker-Maven-plugin to compile and push the image

My pom.xml plug-in is configured as follows

And then set

Add a

= = Go to System Management = “System Settings” and add an SSH Server

If you are sure to use this process, please mount ~/. SSH, otherwise it will be lost every time you restart

docker exec-it container ID bash ssh-keygenCopy the code

Then add the generated public key to your application server, and then create a directory under the application server as Releases

After the configuration, go back to the task for configuration

The contents of the deploy.sh script for my application server are as follows

docker pull registry.cn-hangzhou.aliyuncs.com/mitchell/eureka-server:latest
docker stop eureka-server
docker rm eureka-server
docker run --name eureka-server -p 9001:9001  -d registry.cn-hangzhou.aliyuncs.com/mitchell/eureka-server:latest
Copy the code

Then save and configure Gitlab WebHook

Configuration here

Fill in the blanks here

Then CLICK Add WebHook to add it successfully. Next, I’m using the Docker image push. I need to log in to my Docker private repository from Jenkins’ host. Then under the modified docker – compose. Yml file to/root /. Docker/config. The json mapping to Jenkins container mirror to push into my warehouse, otherwise you will have no legal power, Because the version of Docker-Maven-plugin 1.0 will read your Docker configuration by default, to push the repository, here I demo is to use ali cloud mirror repository, if you do not want to build their own can also use Ali Cloud.

I’ll push it to the master branch. If you’re on the Intranet = = Git can’t access your Jenkins machine, click build now

There are also some improvements, mapping Maven’s repository to the host so that you don’t have to re-package every time you restart. This process is a very simple process to give you an introduction but also meet some needs. If you want to be more flexible and more responsive to complex business scenarios, You can go to Jenkins pipline and Salave and I’m not going to mention that in this article and it’s going to be more extensive