前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CICD(一) GitLab的搭建与使用

CICD(一) GitLab的搭建与使用

作者头像
alexhuiwang
发布2020-09-24 16:46:10
9000
发布2020-09-24 16:46:10
举报
文章被收录于专栏:运维博客运维博客

GitLab的搭建与使用

GitLab介绍

  • 开源免费
  • 差异化的版本管理,离线同步机器强大的分支管理功能
  • 便捷的GUIO操作界面以及强大的权限管理
  • 集成度很高,能够集成绝大多数的开发工具
  • 支持内置HA,保证在高并发的情况下实现高可用性

Gitlab的服务构成

  • Nginx: 静态web服务器
  • GitLab-workhourse:轻量级的反向代理服务器
  • Git-shell: 用于处理Git命令以及修稿authorized keys列表
  • logrotate:日志文件管理
  • Postgresql:数据库
  • Redis: 缓存服务器

Gitlab的工作流程

  • 创建并克隆项目
  • 创建项目的Feature分支
  • 编码并提交至本分支
  • 推送项目分支至远程Gitlab服务器
  • 进行代码检查并提交Master主分支合并申请
  • 项目领导审查代码并确认合并申请

GitLab的安装与配置

  • 创建Centos7虚拟机
  • 登录服务器做预配置
    • 关闭firewalld以及开机自启动
    • 禁用Selinux,并重启机器
  • 安装Omnibus Gitlab-ce Package
代码语言:javascript
复制
[root@centos7-node4 ~]# yum -y install curl policycoreutils openssh-server openssh-client postfix vim curl-devel
[root@centos7-node4 ~]# curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
[gitlab@centos7-node4 gitlab]# sudo systemctl start postfix && sudo systemctl enable postfix
[root@centos7-node4 ~]# yum -y install gitlab-ce
  • 证书颁发
代码语言:javascript
复制
[root@centos7-node4 ~]# openssl genrsa -out "/etc/gitlab/ssl/gitlab.yeecall.cn.key" 2048
[root@centos7-node4 ~]# openssl req -new -key "/etc/gitlab/ssl/gitlab.yeecall.cn.key" -out "/etc/gitlab/ssl/gitlab.yeecall.cn.csr"
[root@centos7-node4 ~]# openssl x509 -req -days 3650 -in "/etc/gitlab/ssl/gitlab.yeecall.cn.csr" -signkey "/etc/gitlab/ssl/gitlab.yeecall.cn.key" -out "/etc/gitlab/ssl/gitlab.yeecall.cn.crt"

[root@centos7-node4 ~]# openssl dhparam -out /etc/gitlab/ssl/dhparams.pem 2048
[root@centos7-node4 ~]# chmod 600 /etc/gitlab/ssl/*
-rw------- 1 root root 424 Dec 22 22:44 /etc/gitlab/ssl/dhparams.pem
-rw------- 1 root root 1298 Dec 22 22:42 /etc/gitlab/ssl/gitlab.yeecall.cn.crt
-rw------- 1 root root 1082 Dec 22 22:40 /etc/gitlab/ssl/gitlab.yeecall.cn.csr
-rw------- 1 root root 1675 Dec 22 22:38 /etc/gitlab/ssl/gitlab.yeecall.cn.key
[root@centos7-node4 ~]# vim /etc/gitlab/gitlab.rb 
external_url 'https://gitlab.yeecall.cn'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.yeecall.cn.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.yeecall.cn.key"
nginx['ssl_dhparam'] = "/etc/gitlab/ssl/dhparams.pem"
[root@centos7-node4 ~]# gitlab-ctl reconfigure
[root@centos7-node4 ~]# vim /var/opt/gitlab/nginx/conf/gitlab-http.conf 
server_name gitlab.yeecall.cn;
rewrite ^(.*)$ https://$host$1 permanent;
[root@centos7-node4 ~]# gitlab-ctl restart

Gitlab的使用

CICD(一) GitLab的搭建与使用
CICD(一) GitLab的搭建与使用
代码语言:javascript
复制
wanghuideMBP:Desktop wanghui$ mkdir repo
wanghuideMBP:Desktop wanghui$ cd repo/
wanghuideMBP:repo wanghui$ git -c http.sslVerify=false clone https://gitlab.yeecall.cn/root/test-repo.git
wanghuideMBP:test-repo wanghui$ vim test.py
wanghuideMBP:test-repo wanghui$ git add .
wanghuideMBP:test-repo wanghui$ git commit -m "first commit"wanghuideMBP:test-repo wanghui$ git -c http.sslVerify=false push origin master

Gitlab的应用

  • Gitlab后台管理
  • 开发视角的Gitlab
    • 代码提交
    • 代码合并
  • 运维视角的Gitlab
    • 账户管理
    • 权限管理
    • 资源监控等
  • 演示使用方法
    • 用户创建,密码与权限(dev,lead)
    • 加入代码仓库管理权限
  • dev开发人员提交代码流程
代码语言:javascript
复制
[root@centos7-node3 repo]# git -c ssl.Verify=false clone https://gitlab.yeecall.cn/root/test-repo.git   #使用dev克隆代码
[root@centos7-node3 repo]# cd test-repo/
[root@centos7-node3 test-repo]# git checkout -b release-1.0   #创建分支
[root@centos7-node3 test-repo]# vim test.py    #更改代码
print("this is a test code")
print("this is a test code for release-1.0")
[root@centos7-node3 test-repo]# git add .
[root@centos7-node3 test-repo]# git commit -m "release-1.0"
[root@centos7-node3 test-repo]# git -c http.sslVerify=false push origin release-1.0    #同步代码

用dev用户登陆gitlabweb页面,然后提出merge请求

创建merge请求

lead用户登陆gitlab批准合并请求。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-04-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • GitLab的搭建与使用
    • GitLab介绍
      • Gitlab的服务构成
        • Gitlab的工作流程
          • GitLab的安装与配置
            • Gitlab的使用
              • Gitlab的应用
              相关产品与服务
              云数据库 Redis
              腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档