Docker + Jenkins continuous integration environment (1) use docker to build Jenkins + docker continuous integration environment

This article describes how to build a continuous integration environment based on docker image from scratch through Jenkins' docker image, including automatic construction, publishing to the warehouse \ and deployment online.

0. Preconditions

Install docker on the server and start docker swarm

Note that when docker is started, the TCP port needs to be opened

1. Jenkins installation

1.1 command line startup:

The installation is relatively simple and can run directly

docker run -p 8080:8080 -p 50000:50000 -d  -v /home/jenkins-home-docker:/var/jenkins_home  jenkins/jenkins:lts

After running, check the log, get the token, open IP: 8080, enter the token, and install common plug-ins

1.2 using swarm cluster management tool

In services, add a service

2. Jenkins plug-in installation

We need some plug-in support

System management - plug-in management can be installed.

2.1 docker configuration

Added in "system management - system settings - cloud"

Note that the docker host URL needs to be added with TCP://

2.2 SSH host configuration

Configure SSH Remote Host in "system management - system settings - SSH remote hosts"

2.3 configuring email

Set directly in system settings and configure SMTP

2.4 configuring JDK and maven

Set JDK automatic installation in system management - global tool configuration

Maven can also be configured

3. Jenkins project configuration

3.1 new project

We are Maven project, choose Maven

3.2 configuration source code management

First, configure the source code, which can be git or SVN. The project team uses SVN

3.3 configuring triggers

Configure automatic build, check poll SCM, and configure it once every 5 minutes. When SVN changes, the build will be started automatically

3.4 configuring build

Simple Maven project, built using POM XML, execute package - dskiptests

3.5 configuring post steps

Post steps refers to the steps to complete the construction. We will build dockers, publish dockers and deploy services

3.5. 1. Configure docker

Click add post build step and select build / publish docker image:

Select cloud as the previously configured docker cloud image, fill in the private server publishing address, and check push image.

This configuration will automatically push to the private server after the build is completed.

3.5. 2 configure remote deployment

We use docker stack to deploy services

First, write docker - compose yml

version: "3"
services:
   backend:
	image: 192.168.86.8:5000/allinone-service-cicd
	deploy:
	  replicas: 1
	  restart_policy:
		condition: on-failure
	ports:
	  - "8007:8006"
	networks:
	  - webnet
networks:
  webnet:

Save to the docker server, such as the / root / AllInOne / AllInOne service / AllInOne directory

Then, add the post build step:

Select the configured remote docker host:

Fill in command:

cd /root/allinone/allinone-service/allinone
docker stack down allinone-cicd
docker stack deploy -c docker-compose.yml allinone-cicd

4 start building

4.1 manual build

Back to the project, click build now. The first build will automatically download JDK and maven, which will be slow

Wait for a while and the build is successful:

9e70992ebc17: Pushing [===============================================>   ]  42.66MB/45.02MB
9e70992ebc17: Pushing [=================================================> ]  44.96MB/45.02MB
9e70992ebc17: Pushing [==================================================>]  45.02MB
9e70992ebc17: Pushed
latest: digest: sha256:5df6c97d6173527bc92ddc436fcef063069cd1cd3d0da8a0c74d2238443ae4d6 size: 1582
Docker Build Done
[SSH] script:

cd /root/allinone/allinone-service/allinone
docker stack down allinone-cicd
docker stack deploy -c docker-compose.yml allinone-cicd

[SSH] executing...
Removing service allinone-cicd_backend
Removing network allinone-cicd_webnet
Creating network allinone-cicd_webnet
Creating service allinone-cicd_backend

[SSH] completed
[SSH] exit-status: 0

Finished: SUCCESS

If mail notification is configured, you will receive a build success message.

4.2 automatic build

Svn submits a change. Wait a few minutes and check the subversion polling log. There are records. It is found that a version has been automatically built

Perfect!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>