Docker uses Git to implement the detailed process of Jenkins release and test projects

Docker uses Git to implement the detailed process of Jenkins release and test projects

1. Install Docker

PS: The prerequisite for installation is that CentOS VM has been installed
1. Set up the image source for downloading Docker

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2. Install Docker

yum -y install docker-ce

3. Start the Docker service

systemctl start docker

4. Configure image acceleration

4.1. Modify the docker service configuration: vim /usr/lib/systemd/system/docker.service to enter and find the parameter: ExecStart=/usr/bin/dockerd

4.2. Add the following line after the parameter: --registry-mirror=https://xfaawkne.mirror.aliyuncs.com
4.3. The final parameters of this line are:

ExecStart=/usr/bin/dockerd --registry-mirror=https://xfaawkne.mirror.aliyuncs.com -H fd:// --containerd=/run/containerd/containerd.sock

4.4. Restart Docker

systemctl daemon-reload
systemctl restart docker

2. Create a custom network address

//Create cbnet network docker network create --subnet=172.18.0.0/16 cbnet
//Delete docker network command docker network rm network IP name //View docker network definition docker network ls

3. Docker creates a container

1. Create mysql, redis, and nginx containers

MySQL:
docker run -d --name mysql --network cbnet --ip 172.18.0.100 -p 3309:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
Redis:
docker run -itd --name redis -p 6379:6379 --network cbnet --ip 172.18.0.102 redis
Nginx:
docker run --name nginx -p 80:80 --network cbnet --ip 172.18.0.105 nginx //If not, it will be downloaded automatically

4. Custom Image

View all local docker images images
Delete the local image docker rmi image identifier

1. Add the docker-maven plugin under plugins in the pom.xml file in the project.

<groupId>com.spotify</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>1.0.0</version>
				<configuration>
					<dockerHost>http://192.168.161.129:2375</dockerHost>
					<imageName>creatorblue/spring-security</imageName>
					<imageTags>
						<imageTag>latest</imageTag>
					</imageTags>
					<forceTags>false</forceTags>
					<dockerDirectory>${project.basedir}/src/main/resources</dockerDirectory>
					<resources>
						<resource>
							<targetPath>/</targetPath>
							<directory>${project.build.directory}</directory>
							<include>${project.build.finalName}.jar</include>
						</resource>
					</resources>
				</configuration>
			</plugin> 

insert image description here

2. Create a new Dockerfile file in the resource directory and fill in the following content

FROM frolvlad/alpine-oraclejdk8:slim
USER root
VOLUME /tmp
ADD springboot-security-0.0.1-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS="-server -Xms256M -Xmx512M -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -Dfile.encoding=UTF-8 -Duser.timezone=GMT+08"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 

insert image description here

3. Package the project, right-click the project and select Maven build under Run As. Enter the following code and click Run.

docker:build -P prod or cleanpack docker:build -P prod

The console displays the following figure and success

insert image description here

4. Modify the docker.service configuration on the virtual machine and open port 2375

1. First enter the docker.service file vim /usr/lib/systemd/system/docker.service
2. Next, open port 2375 -H tcp://0.0.0.0:2375
3. Finally restart Docker
systemctl daemon-reload
systemctl restart docker 

insert image description here

5. Check whether the custom image is successful in the virtual machine: docker images

insert image description here

6. Configure a custom container IP address

docker run -d --name spring-security -p 8088:8080 -v /mnt/uploads : /mnt/uploads --network cbnet --ip 172.18.0.110
docker run -d --name spring-security2 -p 8089:8080 -v /mnt/uploads : /mnt/uploads --network cbnet --ip 172.18.0.111 

insert image description here

Finally, start the MySQL, Redis, Nginx, and Spring-security containers

5. Configure nginx reverse proxy

Achieve load balancing (after one IP logs in, the second IP can log in directly without crowding each other)

1. View the nginx directory

insert image description here

1. Copy the container file: docker cp nginx:/etc/nginx/conf.d/default.conf default.conf 
2. Edit the file: vi default.conf

2. Add code to the default.conf file

insert image description here

Modify the default.conf file as follows:

//Two containers in the same image upstream my{
   server 172.18.0.110:8080;
   server 172.18.0.111:8080;
}

location /spring
   proxy_pass http://my;
}

6. Upload the project to the Git repository

1. First create a warehouse

insert image description here

2. After successful creation, copy the warehouse address

insert image description here

3. Select the project to be uploaded and right-click the project, select Share Project under Team

insert image description here

Finally, click finish to complete! As shown in the figure:

insert image description here

> It means it has been touched but not submitted
Represents newly created
紅色雙箭頭indicate that the remote and local files have been modified, and an error message is displayed.

4. Submit to the local warehouse. Right-click the project and select Commit under Team.

insert image description here

5. Submit to the remote warehouse, right-click the project, as shown in the following figure

insert image description here

If you copied it from the first step of this article, you don’t need to copy it, eclipse has already synchronized; if you didn’t copy it at the beginning, you just need to copy the git repository address!

insert image description here

At this point, refresh the git URL, and it will be successful as shown below

insert image description here

If you encounter problems with being unable to pull or upload, please see https://blog.csdn.net/ZHANGDANDAN04/article/details/115725977 for more details.

7. Use Jenkins to publish and test projects

Go to the official website https://www.jenkins.io/
1. Install Jenkins

insert image description here

2. Follow the steps below to install it in the virtual machine

insert image description here

3. After successful installation, start Jenkins

insert image description here

Access address virtual machine IP address + Jenkins default port 8080

insert image description here

insert image description here

Just choose to install the recommended plugins!

insert image description here

Due to network problems, some plug-ins failed to install. Git has been installed successfully. You can click Continue to the next step.

insert image description here

4. Install Git on the virtual machine

yum install -y git

5. Create a new Item in Jenkins to build the project. The steps are as follows:

insert image description here
insert image description here

Click on the successfully built project to configure it, and then click OK.

insert image description here

6. Click Manage Jenkins

insert image description here

And configure the global tools to configure

insert image description here

7. Download jdk in the virtual machine and configure jdk

Order:
yum install -y javacc-maven-plugin.noarch
//Search for javac
find / -name javac 

insert image description here

8. Configure Maven
8.1. First, go to the Maven official website and copy the Maven compressed package

insert image description here

8.2. Return to the home directory and use wget+粘貼剛剛復制的maven地址

insert image description here

Unzip the file

insert image description here

8.4. After the file is unzipped, enter Maven and enter cd conf, modify the settings.xml file, and load the Alibaba Cloud server to speed up

insert image description here
insert image description here

1. Enter the editing command: vi settings.xm
2. Add Alibaba Cloud Server <mirror> in mirrors
	  <!--This sends everything else to /public -->
	  <id>aliyun</id>
	  <mirrorOf>*</mirrorOf> 
	  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
	</mirror>
  <mirror>
    <!--This is used to direct the public snapshots repo in the 
        profile below over to a different nexus group -->
    <id>aliyun-public-snapshots</id>
    <mirrorOf>*</mirrorOf> 
    <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
  </mirror>

8.5. Configuration

insert image description here

9. Call the top-level Maven goal to enter the build project settings

insert image description here

And build the Maven project, package the command clean install -P prod , and click Save

insert image description here

10. Find the spring-security path on the virtual machine

insert image description here
insert image description here

11. Complete the build project

insert image description here

The following interface and startup are successful!

insert image description here

Common errors encountered when running Jenkins:
1. Download jdk yum install -y javacc-maven-plugin.noarch in the virtual machine

insert image description here

2. Jenkins does not have sufficient access rights

insert image description here

The command to solve permissions is vim /etc/sysconfig/jenkins 

insert image description here

3. Execute Shell writes the wrong project name

insert image description here

13. Test URL access address

insert image description here

Finally, when you need to upgrade the project, first complete the code writing, then commit and push it to the git repository, then rebuild it in Jenkins, and access the new interface again, as shown in the following example steps:

insert image description here
insert image description here
insert image description here

Supplement: You can write a script to start multiple containers at the same time
1. Write a script to start multiple containers: vi auto.sh
2. For example: start three containers

 !/bin/bash
docker run -d --name spring-security -p 8087:8080 -v /mnt/uploads:/mnt/uploads --network cbnet --ip 172.18.0.10 cetorblue/spring-security
docker' run -d --name spring-security -p 8088:8080 -v /mnt/uploads : /mnt/uploads --network chnet --ip 172.18.0.10 creatorblue/spring-security
docker run_ -d --name spring-security -p 8089:8080 -v /mnt/uploads : /mnt /uploads --network chnet --ip17.18.0.10 cretorblue/spring-security

Finally, start sh auto.sh !

This is the end of this article about the detailed process of Docker using Git to implement Jenkins release and test projects. For more relevant Docker Jenkins release test project content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Implementation of Centos7+Docker+Jenkins+ASP.NET Core 2.0 automated release and deployment
  • Install Jenkins with Docker and solve the problem of initial plugin installation failure
  • Automatically build and deploy using Docker+Jenkins
  • How to build docker+jenkins+node.js automated deployment environment from scratch

<<:  js to achieve drag and drop sorting details

>>:  Use pure CSS to achieve switch effect

Recommend

How to obtain a permanent free SSL certificate from Let's Encrypt in Docker

1. Cause The official cerbot is too annoying. It ...

Detailed tutorial on installing Ubuntu 19.10 on Raspberry Pi 4

Because some dependencies of opencv could not be ...

Problems with using wangeditor rich text editing in Vue

wangEditor is a web rich text editor developed ba...

Implementation method of Nginx+tomcat load balancing cluster

The experimental environment is as follows Here y...

The principle and basic use of Vue.use() in Vue

Table of contents Preface 1. Understanding with e...

JavaScript's unreliable undefined

undefined In JavaScript, if we want to determine ...

Detailed tutorial on installing mysql8.0.22 on Alibaba Cloud centos7

1. Download the MySQL installation package First ...

Detailed explanation of JavaScript Promise and Async/Await

Table of contents Overview Four examples Example ...

Detailed explanation of Angular routing sub-routes

Table of contents 1. Sub-route syntax 2. Examples...

How to display div on object without being blocked by object animation

Today I made a menu button. When you move the mous...

Summary of some small issues about MySQL auto-increment ID

The following questions are all based on the Inno...

Vue project @change multiple parameters to pass multiple events

First, there is only one change event. changeleve...

Mysql solves the database N+1 query problem

Introduction In orm frameworks, such as hibernate...