当前位置:网站首页>Jenkins build image automatic deployment
Jenkins build image automatic deployment
2022-07-27 05:46:00 【Code world of super Duoduo and Liu baobao】
List of articles
Preface
This article is after installation jenkins And other environments . So we need to make sure that jenkins There is... On the server maven,jdk, relation git Wait for the operation . If you need to search other documents
One 、Jenkins What is it? ?
Baidu Encyclopedia :
jenkins It's an open source software project , Is based on Java A continuous integration tool for development , Used to monitor continuous repetitive work , To provide an open and easy-to-use software platform , Enable continuous integration of software projects
Two 、 Three construction methods
1. New free style software project
It is recommended that front-end software applications use free style to build projects .( No, pom.xml file )
2.maven style
1) Build and push jar package
I use it as back-end code generation , It's also the method I use now , Use jenkins+sh The script completes the micro service construction .

hook git project , And find a valid user in the voucher , This user must participate in the management of this project . Otherwise, the project cannot be pulled .

In the parent of wechat pom Under the document , perform clean test packet Packing command , The code will be packaged one by one jar file , Position in target Under the folder .

The built operation can add multiple , Because I am a micro service, here is a specific step .
send build artifacts over ssh Pattern
Pass the constructed image through ssh send out server The server , You can select the target server .
transfers
The meaning of carrying
source files Under the workspace jar The path address of the package
Remove prefix Remove prefix , Equivalent to not generating other packages under the path
Remote directory Folders on the remote server
Exec command Final executed shell command
What I pull in my configuration is under a micro service jar Package to the specified file under the specified server , Complete my execution order , The command is cd Go to the target folder and execute sh Script
2 shell The script completes the deployment
stay exec command perform shell command , I complete automated builds by executing scripts
I use docker Running jar package , therefore , At every jar After sending to each file under the target server , By matching dockerfile To carry out bulid Mirror image . Before dockerfile I have already explained , Now just write sh Script .
step :1. Declare variables
2. Create folders and backup folders
3. Stop containers that need to be replaced
4. Delete the container that needs to be replaced
5. Delete the image that needs to be replaced 、
6. Building a new mirror
7. Save the built image to the backup folder
8. Manage the number of backups
9. Run the new container
The actual code :
#/bin/bash
dir=/data/images_bak/file-parent
name=file-parent
logs=/data/logs/file-parent
port=9003
# The above is the declared variable
if [ ! -d "$dir" ];then
mkdir -p $dir
else
echo "xxxx"
fi
if [ ! -d "$logs" ];then
mkdir -p $logs
fi
#if Determine whether the folder exists -d Decide if it's a folder
date=`date +%Y%m%d%H%M%S`
# Declare variables
docker stop `docker ps -a|grep $name|awk '{print $1}'`
docker rm `docker ps -a|grep $name|awk '{print $1}'`
docker rmi `docker images|grep $name|awk '{print $1}'`:`docker images|grep $name|awk '{print $2}'`
# Stop container remove container and image
docker build -t $name:$date .
# Build a mirror image
docker save > $dir/$name-$date.tar `docker images|grep $name|awk '{print $1}'`:`docker images|grep $name|awk '{print $2}'`
# Take the image as tar Save to the corresponding directory The name is imageName:tag
ls -t $dir/*.tar |awk 'NR>3'|xargs rm -f
docker run -itd -p $port:$port -v $logs:/logs --name $name $name:$date bash
# Start the image mapping port mount directory and declare the container name
understand :
linux Next shell in if Of “-e,-d,-f” What does that mean?
File expression
-e filename If filename There is , It is true
-d filename If filename Directory , It is true
-f filename If filename For general file , It is true
-L filename If filename Is symbolic link , It is true
-r filename If filename Can be read , It is true
-w filename If filename Can write , It is true
-x filename If filename Executable , It is true
-s filename If the file length is not 0, It is true
-h filename If the file is a soft link , It is true
filename1 -nt filename2 If filename1 Than filename2 new , It is true .
filename1 -ot filename2 If filename1 Than filename2 used , It is true .
summary
jenkis Automated build is not a way to build , Need to learn more , If you are an operation and maintenance personnel, you can continue to understand , Developers personally feel that knowing a construction method is enough to meet their daily work
边栏推荐
- Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
- Maintain login and route jump
- NFT新范式,OKALEIDO创新NFT聚合交易生态
- 攻防世界-mfw
- 选择国企背景的期货公司开户
- The business logic of face brushing changed significantly, and merchants vied for war smoke to rise again
- dirsearch[目录扫描工具]
- MOVE PROTOCOL推出测试版,更可“0撸”参与P2E
- Read and understand the advantages of the LAAS scheme of elephant swap
- Edit delete user
猜你喜欢

Seektiger's okaleido has a big move. Will the STI of ecological pass break out?

Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径

Permission display - dynamic list on the left

原油期货开户条件和流程是什么?

Mysql5.7版本如何实现主从同步

「PHP基础知识」布尔型的使用

How to open a general commodity futures account

一文读懂Elephant Swap的LaaS方案的优势之处

哪个期货公司手续费低高交返?

期货开户怎么选择好的期货公司 ?
随机推荐
jenkins构建镜像自动化部署
Minimum handling charges and margins for futures companies
Differences among apply, call, and bind in JS
刷脸商业逻辑重大改变商户争抢烽烟再起
How can I get the lowest handling charge for opening a futures account?
Sealem Finance-基于Web3的全新去中心化金融平台
Edit delete user
Prototype and prototype chain in JS
DeFi 2.0的LaaS协议Elephant,或许是你熊市下为数不多的获利手段
「PHP基础知识」PHP语句和语句块
How to apply for the return of futures account opening company?
You can't even do a simple function test well. What do you take to talk about salary increase with me?
How can seektiger go against the cold air in the market?
攻防世界-lottery
Sealem Finance - a new decentralized financial platform based on Web3
期货公司的评级和查询详情
Face brushing payment is more in line with Alipay's concept of always being ecological
「PHP基础知识」PHP中的注释
In the future, face brushing payment can occupy a lot of market share
基于PG-Oracle和MySQL的三库通用sql代码开发