Continuous integration and continuous delivery

Posted by jimmyt1988 on Thu, 10 Feb 2022 06:37:39 +0100

1. Introduction to Git

Official website learning address
http://git-scm.com/book/zh/v2

Git features:

  • speed
  • Simple design
  • Strong support for nonlinear development mode (allowing thousands of branches of parallel development)
  • Fully distributed
  • Ability to efficiently manage large-scale projects like Linux kernel (speed and data volume)

Since its birth in 2005, Git has become more and more mature and perfect. While it is highly easy to use, it still retains the goals set in the initial stage. It is fast, extremely suitable for managing large projects, and has an incredible nonlinear branch management system.

Git has three statuses: committed, modified, and staged.

  • Modified indicates that the file has been modified but has not been saved to the database.
  • Staged indicates that the current version of a modified file is marked for inclusion in the next committed snapshot.
  • Submitted indicates that the data has been safely stored in the local database.

This will make our Git project have three phases: workspace, staging area and Git directory.

2.git installation and use

install

[root@server1 ~]# yum install git -y
[root@server1 ~]# mkdir demo
[root@server1 ~]# cd demo/
[root@server1 demo]# ls
[root@server1 demo]# git init

[root@server1 demo]# touch README.txt

[root@server1 demo]# git add README.txt  #Track new files
[root@server1 demo]# git status
[root@server1 demo]# git status -s
A  README.txt

Add user
[root@server1 demo]# git config --global user.name "bw"
[root@server1 demo]# git config --global user.email "bw@qq.com"
[root@server1 demo]# git commit -m "add file" ##Submit update
[root@server1 demo]# git log #journal

[root@server1 demo]# vim README.txt 
[root@server1 demo]# cat README.txt 
westos
[root@server1 demo]# git status -s
 M README.txt
[root@server1 demo]# git add README.txt 
[root@server1 demo]# git status -s
M  README.txt
[root@server1 demo]# vim README.txt 
[root@server1 demo]# cat README.txt 
westos
westos
[root@server1 demo]# git status -s
MM README.txt
[root@server1 demo]# git add README.txt 
[root@server1 demo]# git status -s
M  README.txt
[root@server1 demo]# git commit -m "update file"
[root@server1 demo]# git log
[root@server1 demo]# git status -s


Hide file

[root@server1 demo]# vim .gitignore
.*
[root@server1 demo]# git status -s

[root@server1 demo]# touch test.txt
[root@server1 demo]# git add test.txt 
[root@server1 demo]# git commit -m "add test.txt"
[root@server1 demo]# git reflog


Delete file

[root@server1 demo]# rm -f test.txt 
[root@server1 demo]# git reflog
[root@server1 demo]# git status -s


Undo changes to files

[root@server1 demo]# git checkout -- test.txt

[root@server1 demo]# git rm test.txt  
[root@server1 demo]# git status -s
[root@server1 demo]# git commit -m "delete test.txt"
[root@server1 demo]# git status -s
[root@server1 demo]# git reflog


Version fallback

[root@server1 demo]# git reset --hard f58994c
[root@server1 demo]# ls

[root@server1 demo]# git reset --hard 21a3b50
HEAD is now at 21a3b50 delete test.txt
[root@server1 demo]# ls
README.txt

3.gitlab code warehouse

[root@server1 ~]# yum install -y curl policycoreutils-python openssh-server
[root@server1 ~]# rpm -ivh gitlab-ce-13.2.2-ce.0.el7.x86_64.rpm 
[root@server1 ~]# vim /etc/gitlab/gitlab.rb 
external_url 'http://172.25.4.1'
Overload service
[root@server1 ~]# gitlab-ctl  reconfigure

View status

[root@server1 ~]# gitlab-ctl status


172.25.1 access

Reset password user name to root

New project

Secret free

[root@server1 ~]# ssh-keygen
[root@server1 ~]# cat .ssh/id_rsa.pub 




Clone project

[root@server1 ~]# rm -rf demo/
[root@server1 ~]# git clone git@172.25.4.1:root/demo.git
[root@server1 ~]# ls
demo

Push warehouse

[root@server1 ~]# cd demo/
[root@server1 demo]# touch index.html
[root@server1 demo]# echo www.westos.org > index.html
[root@server1 demo]# git add index.html
[root@server1 demo]# git commit -m "add index.html"
[root@server1 demo]# git status -s
[root@server1 demo]# git push -u origin master 


Refresh item view

4.jenkins continuous integration

enkins introduction

  • Jenkins is a leader in open source CI & CD software, providing more than 1000 plug-ins to support construction, deployment and automation to meet the needs of any project.
  • Jenkins is written in Java language and can run in popular servlet containers such as Tomcat or independently.
  • CI(Continuous integration) continuous integration emphasizes that developers immediately build and (unit) test after submitting new code.
  • CD(Continuous Delivery) is based on continuous integration to deploy the integrated code to a more close to the real running environment (similar to production environment).

install

Open a new virtual machine (2g memory)

[root@server2 ~]# rpm -ivh jdk-8u171-linux-x64.rpm
[root@server2 ~]# rpm -ivh jenkins-2.283-1.1.noarch.rpm
[root@server2 ~]# systemctl start jenkins

Visit 172.25.4.2:8080

Enter key

Generate updates file

[root@server2 ~]# vim /var/lib/jenkins/updates/default.json

Modify the first behavior baidu and replace it

:%s/updates.jenkins.io\/download/mirrors.tuna.tsinghua.edu.cn\/jenkins/g

Reload

[root@server2 updates]# systemctl reload jenkins.service 

Refresh the page to continue the installation


use

Install the plug-in gitlab

Create a new freestyle project

[root@server2 ~]# yum install git -y

Add private key to access git warehouse


Add public key to git repository

Select the following without error

Build select execute shell command

Gitlab automatically triggers jenkins (add gitlab plug-in)



[root@server1 demo]# vim index.html 
[root@server1 demo]# git commit -a -m "v1"
[root@server1 demo]# git status -s
[root@server1 demo]# git push -u origin master


Topics: git GitLab jenkins