CICD (1) Construction and use of GitLab

Construction and use of GitLab

Introduction to GitLab

  • Open source free
  • Differentiated version management, offline synchronization machine powerful branch management function
  • Convenient GUIO operation interface and powerful authority management
  • High degree of integration, able to integrate most development tools
  • Support built-in HA to ensure high availability under high concurrency

Gitlab service composition

  • Nginx: static web server
  • GitLab-workhourse: lightweight reverse proxy server
  • Git-shell: used to process Git commands and revise authorized keys list
  • logrotate: log file management
  • Postgresql: database
  • Redis: cache server

Gitlab workflow

  • Create and clone a project
  • Create a feature branch of the project
  • Code and submit to this branch
  • Push the project branch to a remote Gitlab server
  • Conduct code review and submit Master Master branch merger application
  • The project leader reviews the code and confirms the merger application

GitLab installation and configuration

  • Create Centos7 virtual machine
  • Log in to the server for pre-configuration

    • Shutdown firewalldand auto start
    • Disable Selinux and restart the machine
  • Install Omnibus Gitlab-ce Package
[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
  • Certificate issuance
[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

Use of Gitlab

CICD (1) Construction and use of GitLab

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 application

  • Gitlab background management
  • Gitlab from a development perspective

    • Code submission
    • Code merge
  • Gitlab from the perspective of operation and maintenance

    • Account management
    • authority management
    • Resource monitoring, etc.
  • Demonstrate how to use

    • User creation, password and permissions (dev, lead)
    • Add code warehouse management authority
  • Dev developers submit code flow
[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    #同步代码

Log in to the gitlabweb page as the dev user, and then submit a merge request

Create merge request

Lead users log in to gitlab to approve the merge request.

Guess you like

Origin blog.51cto.com/13812615/2488647