Jenkins builds Docker images and pushes them to Harbor warehouse

Jenkins builds Docker images and pushes them to Harbor warehouse

The spring boot project uses Jenkins to build a Docker image, push it to the harbor repository, start the container, and then pull the image to the local running container.

Dockerfile

Location: in the root directory, at the same level as src

FROM java:8
 # Author: MAINTAINER zhaoyc
VOLUME /tmp
#ARG JAR_FILE
#Add the jar package to the container and rename it to app.jar
ADD target/*.jar app.jar
RUN bash -c 'touch /app.jar'
ENV TZ=Asia/Shanghai
#RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
EXPOSE 81
#CMD ["-jar", "/app.jar"] "nohup" "&"
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

pom.xml

To specify the Maven version number as 1.4.2, other versions have not been tested, otherwise the main-class cannot be found

<plugins>
 <!-- mavn jar package startup plug-in -->
	<plugin>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-maven-plugin</artifactId>
		<version>1.4.2.RELEASE</version>
	</plugin>
</plugins>

Jenkins Configuration

System settings configuration docker – need to install Docker plugin

insert image description here

Create a new Maven project configuration parameter build

insert image description here

Project git repository configuration

insert image description here

mvn build buile configuration

insert image description here

Build the Docker image and push it to the repository configuration

insert image description here

Execute the script after pushing to the repository

#!/bin/bash
#IMAGE=${module_filename}
#TAG=${Tag}
IMAGE=$1
TAG=$2
PULL_IMAGE=192.168.1.100:81/project/${IMAGE}:${TAG}
# Calculate subtraction and output with 0 in front of the decimal point, such as 0.3-0.1=0.2
CURRENT_IAMGE=`echo "$TAG - 0.1" | bc | awk '{printf "%.1f", $0}'`

echo '================Start logging into Harbor warehouse================'
docker login http://192.168.1.100:81 -u admin -p Harbor12345

if [ $? -eq 0 ]; then
    echo '================Login successful================='
else
    echo '================Login failed================='
    return 1
fi

echo '================Start pulling image================'
docker pull ${PULL_IMAGE}
echo '================End of pulling image================'

# Update container operation echo '================Stop running the image================'
docker stop ${IMAGE}_${CURRENT_IAMGE}
echo "wait 10 seconds"
sleep 10

echo '================Start starting mirror================'
#if [ ${IMAGE} == "java-demo" ]; then
# docker run -d --name ${IMAGE}_${TAG} -p 9001:9001 ${PULL_IMAGE}
#elif [ ${IMAGE} == "spring-cloud-eureka-client-demo" ]; then
# docker run -d --name ${IMAGE}_${TAG} -p 9012:9012 ${PULL_IMAGE}
#fi
docker run -d --name ${IMAGE}_${TAG} -p 9001:9001 ${PULL_IMAGE}
if [ $? -eq 0 ]; then
    echo '================Mirroring started successfully================'
else
    echo '================Mirror startup failed================'
    return 1
fi

This is the end of this article about how Jenkins builds Docker images and pushes them to the Harbor repository. For more information about how Jenkins builds Docker images, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to use Docker buildx to build multi-platform images and push them to private repositories
  • Use Docker to build a Git image using the clone repository
  • How to use domestic image warehouse for Docker
  • docker-maven-plugin packages the image and uploads it to a private warehouse
  • How to use Docker image repository
  • Alibaba Cloud deployment steps for Docker private image repository
  • Docker container practice image warehouse

<<:  Prometheus monitors MySQL using grafana display

>>:  HTML form application includes the use of check boxes and radio buttons

Recommend

Summary of some common writing methods that cause MySQL index failure

Preface Recently, I have been busy dealing with s...

js implements the pop-up login box by clicking the pop-up window

This article shares the specific code of js to re...

mysql-8.0.16 winx64 latest installation tutorial with pictures and text

I just started learning about databases recently....

How to manage users and groups when running Docker

Docker is a management tool that uses processes a...

Summary of shell's method for determining whether a variable is empty

How to determine whether a variable is empty in s...

An example of the difference between the id and name attributes in input

I have been making websites for a long time, but I...

Tutorial on installing mysql5.7.36 database in Linux environment

Download address: https://dev.mysql.com/downloads...

A quick solution to the first login failure in mysql5.7.20

First, we will introduce how (1) MySQL 5.7 has a ...

TypeScript Mapping Type Details

Table of contents 1. Mapped Types 2. Mapping Modi...

CSS3+HTML5+JS realizes the shrinking and expanding animation effect of a block

When I was working on a project recently, I found...

Solve MySQL deadlock routine by updating different indexes

The previous articles introduced how to debug loc...

Overview of the basic components of HTML web pages

<br />The information on web pages is mainly...

mysql-8.0.17-winx64 deployment method

1. Download mysql-8.0.17-winx64 from the official...