持续集成与持续交付CI/CD

CI/CD 是指持续集成(Continuous Integration)和持续部署(Continuous Deployment)或持续交付(Continuous Delivery)

持续集成(Continuous Integration)

持续集成是一种软件开发实践,团队成员频繁地将他们的工作集成到共享的代码仓库中。其主要特点包括:

  1. 频繁提交代码:开发人员可以每天多次提交代码,确保代码库始终保持最新状态。
  2. 自动化构建:每次提交后,自动触发构建过程,包括编译、测试、静态分析等。
  3. 快速反馈:如果构建失败或测试不通过,能够快速地向开发人员提供反馈,以便及时修复问题。

持续部署(Continuous Deployment)

持续部署是在持续集成的基础上,将通过所有测试的代码自动部署到生产环境中。其特点如下:

  1. 自动化流程:从代码提交到生产环境的部署完全自动化,无需人工干预。
  2. 高频率部署:可以实现频繁的部署,使得新功能能够快速地提供给用户。
  3. 风险控制:需要有强大的测试和监控体系来确保部署的稳定性和可靠性。

持续交付(Continuous Delivery)

持续交付与持续部署类似,但不一定自动部署到生产环境,而是随时可以部署。其重点在于确保软件随时处于可发布状态。

CI/CD 的好处包括:

  1. 提高开发效率:减少手动操作和等待时间,加快开发周期。
  2. 尽早发现问题:通过频繁的集成和测试,问题能够在早期被发现和解决。
  3. 降低风险:减少了大规模部署时可能出现的问题,提高了软件的质量和稳定性。
  4. 增强团队协作:促进团队成员之间的沟通和协作,提高团队的整体效率。
bash 复制代码
#下载
[root@gitlab ~]# dnf install git -y
# 初始化
[root@gitlab luo]# git init
# 查看
[root@gitlab luo]# ls -a
.  ..  .git

建立用户信息

bash 复制代码
[root@gitlab luo]# git config --global user.name "luo"
[root@gitlab luo]# git config --global user.email "[email protected]"

未提交状态

提交后状态

追加内容,右M,在工作区被修改,但没提交

bash 复制代码
[root@gitlab luo]# echo >> README.md

提交后左绿,提交到暂存区

bash 复制代码
[root@gitlab luo]# git add README.md 

提交到工作区

bash 复制代码
[root@gitlab luo]# git commit -m "README.md v2"


git status -s 无任何显示,标识已经提交到版本库

当再次修改

bash 复制代码
[root@gitlab luo]# vim README.md

右红M表示文件在工作区被修改

撤销修改

bash 复制代码
[root@gitlab luo]# git checkout -- README.md
[root@gitlab luo]# cat README.md 
luo

重新修改

bash 复制代码
[root@gitlab luo]# echo luoluo > README.md
[root@gitlab luo]# git add README.md 
[root@gitlab luo]# git status -s
M  README.md

从暂存区撤销

bash 复制代码
[root@gitlab luo]# git restore --staged README.md
[root@gitlab luo]# git status -s
 M README.md

重新提交

bash 复制代码
[root@gitlab luo]#  git add README.md
[root@gitlab luo]# git status -s
M  README.md

更新

bash 复制代码
[root@gitlab luo]# git commit -m "update v1"
[master f126628] update v1
 1 file changed, 1 insertion(+), 2 deletions(-)
[root@gitlab luo]# git status -s

更新文件

bash 复制代码
[root@gitlab luo]# echo luo1 >> README.md
[root@gitlab luo]# git add README.md
[root@gitlab luo]# echo luo1 >> README.md 
[root@gitlab luo]# git status -s
MM README.md


MM表示有一部分在暂存区,还有一部分没有提交
如果现在提交只能提交在暂存区中的部分

bash 复制代码
[root@gitlab luo]# git commit -m "update v2"
[master c155d30] update v2
 1 file changed, 1 insertion(+)
[root@gitlab luo]# git status -s
 M README.md

查看已暂存和未暂存的修改变化

bash 复制代码
[root@gitlab luo]# echo luo >> README.md 
[root@gitlab luo]# git diff
diff --git a/README.md b/README.md
index a700f83..6240833 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,4 @@
 luoluo
 luo1
+luo1
+luo

跳过使用暂存区,只能在提交过的在版本库中存在的文件使用如果文件状态是"??"不能用此方法

撤销工作区中删除动作

bash 复制代码
[root@gitlab luo]# touch luo.txt
[root@gitlab luo]# git add luo.txt 
[root@gitlab luo]# git commit  -m "add luo.txt"
[master aa037c1] add luo.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 luo.txt
 [root@gitlab luo]# rm -rf luo.txt 
 [root@gitlab luo]# git status -s
 D luo.txt

右D 表示文件在工作区被删除

git 对文件忽略

bash 复制代码
[root@gitlab luo]# mkdir dir1
[root@gitlab luo]# touch dir1/.file2
[root@gitlab luo]# git status -s
?? dir1/

gitlab代码仓库

部署gitlab

bash 复制代码
# 在安装包之前需配置好软件仓库来解决依赖性
[root@gitlab luo]# yum install -y curl policycoreutils-python-utils openssh-server perl

修改配置文件

bash 复制代码
[root@gitlab luo]# cd /etc/gitlab/
[root@gitlab gitlab]# vim gitlab.rb
[root@gitlab gitlab]# gitlab-ctl reconfigure

使用gitlab-crt生效配置

root@gitlab gitlab\]# gitlab-ctl reconfigure 查看原始密码 \[root@gitlab gitlab\]# cat /etc/gitlab/initial_root_password 登录 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/640a4480bc224439add69f1547d42407.png) 更改密码 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/610c986f07a74cce8d78bc118a6b0bcd.png) ### 在gitlab中新建项目 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/8862a0a2e57341aaadd24676814077ae.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6a88826a105b4b909a46b287d7f61ef4.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/cfe5ed57a1a44f8686d2fdb14ef3bef9.png) 生成sshd密钥 ```bash [root@gitlab gitlab]# ssh-keygen [root@gitlab ~]# cat .ssh/id_rsa.pub ``` ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/4e21a451c64442efb7e3ee9177f964d1.png) 上传公钥到gitlab中 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/54a02150792942f4b601812229f9832b.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/036f4aabcbee406995bf7649b91cbe61.png) 下载项目 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/079cdd085e394f6c9a164326f68b6673.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/d39267e4bbc4493581ef80c6d8521f86.png) ### 部署jenkins ```bash [root@jenkins-node1 ~]# ls 公共 图片 音乐 jenkins-2.462.2-1.1.noarch.rpm 模板 文档 桌面 plugins.tar.gz 视频 下载 anaconda-ks.cfg [root@jenkins-node1 ~]# dnf install jenkins-2.476-1.1.noarch.rpm [root@jenkins-node1 ~]# systemctl enable --now jenkins.service Created symlink /etc/systemd/system/multi-user.target.wants/jenkins.service → /usr/lib/systemd/system/jenkins.service. [root@jenkins-node1 ~]# cat /var/lib/jenkins/secrets/initialAdminPas ``` ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/12a108e5d29242b38168243c967c599b.png) 使用下载好的插件 ```bash [root@jenkins-node1 jenkins]# rm -rf /var/lib/jenkins/* [root@jenkins-node1 jenkins]# cd [root@jenkins-node1 ~]# tar zxf plugins.tar.gz -C /var/lib/jenkins/ [root@jenkins-node1 ~]# cd /var/lib/jenkins/ [root@jenkins-node1 jenkins]# ls plugins [root@jenkins-node1 jenkins]# systemctl restart jenkins.service ``` ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/29ecf512406e4e9d899203d68d195b7b.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/5f4b04a313fc4c8492aaf7eb8ab3a4e6.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/022ecbbd31c24e63b0c688e451ce541d.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/c348331763c44dc7812859a95c31b442.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/4c0aab2472a640888f88188577e7b37f.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/7f7a5a9a314049a0acfdd586cba677b5.png) 设置密码 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/8f4b202b791c4390820a336477c3f104.png) ### jenkins 与gitlab的整合 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6ce25fdb10a847e2854182ce908092fc.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/395ec9718c5d412aa0a19a5079d844ce.png) 添加密钥 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/c9d573084901408991100edf80408fe4.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/608d00147c584b2ea54b46ec6870a1a3.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/bd24be4d7f7141bcb615cf9a4ee40fcd.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/c0ca2047aa7d4140b8aeb9c24b4db0f5.png) ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/a819b9d744a0486f8ec2328f3eba993c.png) 关闭远程登录需要的yes/no ```bash [root@jenkins-node1 ~]# vim /etc/ssh/ssh_config ``` ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/dd112e050cc742efb9fc3660110834dc.png) 更该类型 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/39f65fbbe76548b0abe41e3a8ff85a31.png) 设置计划任务 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/601593c9c09b415188ca14cce48878a7.png) 设置查看有没有建立成功 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/20e82a2860aa41d0a2cb764e46b32f39.png) 点击立刻创建 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/dfc75a738ef1411ca77bf8a69d3255b5.png) 查看 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/0e7d391c96de47a095e6c6e7ed20ff23.png)

相关推荐
alin、m32 分钟前
银河麒麟(Kylin) - V10 SP1桌面操作系统ARM64编译QT-5.15.12版本
大数据·qt·kylin
ASCO1100691 小时前
安全用电基础知识及隐患排查重点
大数据·网络·安全
白鲸开源4 小时前
做到真正0丢失、0重复:Apache SeaTunnel 实现万亿级数据一致性全解密
大数据
OpenVINO生态社区4 小时前
【机器人创新创业成功的三个关键元素及作用?】
大数据·人工智能·机器人
宝哥大数据4 小时前
数据中台、数据湖和数据仓库 区别
大数据·数据仓库·数据湖
龙石数据4 小时前
数据中台(大数据平台)之数据仓库建设
大数据·数据仓库·spark·数据中台
絮落锦乡5 小时前
ES DSL 常用修改语句
大数据·elasticsearch·搜索引擎
-曾牛5 小时前
Git完全指南:从入门到精通版本控制 ------- Git 查看提交历史(8)
大数据·git·学习·elasticsearch·个人开发
·云扬·5 小时前
【技术派后端篇】ElasticSearch 实战指南:环境搭建、API 操作与集成实践
大数据·elasticsearch·搜索引擎
StevenLdh7 小时前
Elasticsearch使用及常见的问题
大数据·elasticsearch·搜索引擎