Method of realizing automated deployment based on Docker+Jenkins

Method of realizing automated deployment based on Docker+Jenkins

Use Code Cloud to build a Git code storage warehouse

https://gitee.com/login

  • Use Code Cloud to create a private git repository
  • Upload the local springboot project to the git repository

Install Jenkins environment based on Docker

1. Install Jenkins using Docker

docker run -p 8080:8080 -p 50000:50000 -v jenkins_data:/var/jenkins_home jenkinsci/blueocean

2. Access Jenkins address 8080

Note: When starting for the first time, it will take about 3-10 minutes for Jenkins to load.

3. Unlock Jenkins

docker exec -it 7f485bd95c3b /bin/bash enter the jenkins container cat /var/jenkins_home/secrets/initialAdminPassword 

It takes about 3-10 minutes to wait

Create a new user

Jenkins global tool configuration

Enter the jenkins container and echo $JAVA_HOME to get the java environment installation address

JDK environment installation

Maven environment installation

Install the Jenkins corresponding Maven plugin

Find "System Management" - "Install Plugin", click "Optional Plugin", and find the following Maven plugin version

Plugin NameMaven Integration

Jenkins implements Springboot project automatic deployment to create a new release task

Configure the task git account and password

3. Project packaging

clean install

Click Build Now

The first build may take a long time because you need to download some related dependent jar packages

Execute the shll script after Jenkins starts successfully

#!/bin/bash
#Service name SERVER_NAME = springboot
# Source jar path, after mvn packaging is completed, the jar package name in the target directory can also be selected as a war package. The war package can be moved to the webapps directory of Tomcat for operation. Here, the jar package is used and the java -jar command is used to execute JAR_NAME=springboot-0.0.1-SNAPSHOT
# Source jar path #/usr/local/jenkins_home/workspace--->jenkins working directory #demo project directory #target package generated jar package directory JAR_PATH=/var/jenkins_home/workspace/springboot/target
# After packaging is completed, move the jar package to the directory where the jar package is run--->work_daemon. The work_daemon directory needs to be created in advance JAR_WORK_PATH=/var/jenkins_home/workspace/springboot/target
 
echo "Query process id-->$SERVER_NAME"
PID=`ps -ef | grep "$SERVER_NAME" | awk '{print $2}'`
echo "Get process ID: $PID"
echo "End process"
for id in $PID
do
kill -9 $id 
echo "killed $id" 
done
echo "End process completed"
 
#Copy the jar package to the execution directory echo "Copy the jar package to the execution directory: cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH"
cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH
echo "Complete jar package copy"
cd $JAR_WORK_PATH
#Change file permissions chmod 755 $JAR_NAME.jar
Nohub java -jar $JAR_NAME.jar

Adding nohub means running in the background, or using nohub &

Container maps port 8081

1. Restart the container

systemctl restart docker

2. Clear non-running containers

docker rm $(sudo docker ps -a -q)
docker run -p 8080:8080 -p 8081:8081 -p 50000:50000 -v jenkins_data:/var/jenkins_home jenkinsci/blueocean

This is the end of this article about automated deployment based on Docker+Jenkins. For more information about automated deployment based on Docker+Jenkins, 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:
  • Jenkins+Docker+Gitee+SpringBoot automated deployment
  • Automated front-end deployment based on Docker, Nginx and Jenkins
  • Docker+gitlab+jenkins builds automated deployment from scratch
  • How to build docker+jenkins+node.js automated deployment environment from scratch
  • Docker builds Jenkins and automates the steps of packaging and deploying projects

<<:  Detailed tutorial on deploying Jenkins based on docker

>>:  JavaScript implements an input box component

Recommend

Native js to achieve seamless carousel effect

Native js realizes the carousel effect (seamless ...

Detailed explanation of CocosCreator project structure mechanism

Table of contents 1. Project folder structure 1. ...

Linux kernel device driver Linux kernel basic notes summary

1. Linux kernel driver module mechanism Static lo...

The difference between Div and table in HTML (discussed in detail in all aspects)

1: Differences in speed and loading methods The di...

MySQL series: redo log, undo log and binlog detailed explanation

Implementation of transactions The redo log ensur...

Install Kafka in Linux

Table of contents 1.1 Java environment as a prere...

In-depth understanding of umask in new linux file permission settings

Preface The origin is a question 1: If your umask...

Detailed explanation of scp and sftp commands under Linux

Table of contents Preface 1. scp usage 2. Use sft...

A brief discussion on the implementation principle of Webpack4 plugins

Table of contents Preface know Practice makes per...

How to safely shut down MySQL

When shutting down the MySQL server, various prob...

Detailed explanation of 4 common data sources in Spark SQL

Generic load/write methods Manually specify optio...

How to use cc.follow for camera tracking in CocosCreator

Cocos Creator version: 2.3.4 Demo download: https...