characteristic
- Open source: CI/CD is part of the open source GitLab Community Edition and the proprietary GitLab Enterprise Edition. (polar fox)
- Easy to learn: the official has detailed learning operation documents.
- Seamless integration: CI/CD is a part of GitLab. It supports planning to deployment and has an excellent user experience.
- Extensible: you can add any number of build nodes as needed* (in terms of architecture, there are gitlab server and gitlab runner, which are similar to slave construction nodes)
- Faster results: each build can be split into multiple jobs that can run in parallel on multiple computers.
- Optimized for delivery: multiple phases, manual deployment, environment and variables.
Click an item to see the CI/CD pipeline information of the pipeline, including the pipeline status, the pipeline ID, followed by the branch, who triggered it, and the status of each step of the pipeline.
You can see that gitlab comes with the CI/CD function, and no additional installation is required. Gitlab provides complete CI/CD functions without additional installation tool chains. If the company does not have many projects, gitlab can be used, there is no need to install too many tool chains to reduce operation and maintenance costs.
GitLab deployment
Version: 14.0.0 0
RPM reference documentation: https://www.yuque.com/zeyangli/bqsigl/rgdrnw
## Download Image docker pull gitlab/gitlab-ce:14.0.0-ce.0 ## Create data directory mkdir -p /data/cicd/gitlab/{config,logs,data} chmod 777 -R /data/cicd/gitlab/ ## function docker run -d -p 443:443 -p 80:80 -p 222:22 --name gitlab \ --restart always \ -v /data/cicd/gitlab/config:/etc/gitlab \ -v /data/cicd/gitlab/logs:/var/log/gitlab \ -v /data/cicd/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce:14.0.0-ce.0
- 222 port ssh protocol
- Port 80 http port
- 443 port https port
FAQ
[root@zeyang-nuc-service ~]# git clone http://927c154cfffa/devops/demo-hello-service.git Cloning into 'demo-hello-service'... fatal: unable to access 'http://927c154cfffa/devops/demo-hello-service.git/': Could not resolve host: 927c154cfffa [root@zeyang-nuc-service ~]# docker ps | grep gitlab 927c154cfffa gitlab/gitlab-ce:13.10.0-ce.0 "/assets/wrapper" 21 minutes ago Up 21 minutes (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:222->22/tcp gitlab [root@zeyang-nuc-service ~]#
resolvent
docker exec -it gitlab bash root@927c154cfffa:/# vi /etc/gitlab/gitlab.rb
root@927c154cfffa:/# gitlab-ctl reconfigure
GitLab Runner configuration management
Gitlab is a project, and gitlab runner is also a separate project. The runner is similar to Jenkins' slave node. It is also the server to schedule and then allocate jobs.
- GitLab Runner is an open source project that runs jobs and sends the results back to GitLab.
- Combined with GitLabCI, GitLabCI is an open source continuous integration service for coordinating jobs attached to GitLab.
- GitLab Runner is written in Go and can run on Linux,macOS and Windows operating systems.
- The latest Docker version is required for container deployment. GitLab Runner requires a minimum of Docker v1 13.0.
- The GitLab Runner version should be synchronized with the GitLab version. (avoid differentiation caused by inconsistent versions)
- Any number of runners can be configured as needed.
Type
- Shared type. All jobs running the entire platform project (gitlab click Menu - > admin) can be seen that the tokens obtained in the background are basically shared type tokens
- The group item group type runs the jobs (groups) of all items under a specific group. This is to register a group level token, which is the runner of the group and cannot be used by other groups
- specific project type, running the specified project job (project)
state
- Locked: locked, unable to run project job
- paused: suspended. New jobs will not be accepted temporarily
Steps:
- Install gitlab runner tool
- Register the Runner node with GitLab Server using gitlab Runner tool.
Runner deployment package download: https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7-x86_64/
[root@gitlab-dockerhub ~]# ls gitlab-runner-14.0.0-1.x86_64.rpm [root@gitlab-dockerhub ~]# rpm -ivh gitlab-runner-14.0.0-1.x86_64.rpm warning: gitlab-runner-14.0.0-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 35dfa027: NOKEY error: Failed dependencies: git is needed by gitlab-runner-14.0.0-1.x86_64 [root@gitlab-dockerhub ~]# yum install git -y [root@gitlab-dockerhub ~]# rpm -ivh gitlab-runner-14.0.0-1.x86_64.rpm warning: gitlab-runner-14.0.0-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 35dfa027: NOKEY Preparing... ################################# [100%] Updating / installing... 1:gitlab-runner-14.0.0-1 ################################# [100%] GitLab Runner: creating gitlab-runner... Home directory skeleton not used Runtime platform arch=amd64 os=linux pid=7771 revision=3b6f852e version=14.0.0 gitlab-runner: the service is not installed Runtime platform arch=amd64 os=linux pid=7781 revision=3b6f852e version=14.0.0 gitlab-ci-multi-runner: the service is not installed Runtime platform arch=amd64 os=linux pid=7811 revision=3b6f852e version=14.0.0 Runtime platform arch=amd64 os=linux pid=7847 revision=3b6f852e version=14.0.0 Check and remove all unused containers (both dangling and unreferenced) including volumes. ------------------------------------------------------------------------------------------ Total reclaimed space: 0B #/etc/gitlab-runner/config.toml this is its configuration file [root@gitlab-dockerhub ~]# ps aux | grep -v grep | grep runner root 7857 0.0 0.2 151960 17388 ? Ssl 10:27 0:00 /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user gitlab-runner
Runner registration configuration
- Get the gitlab address and the Runner registration token (similar to Jenkins, download a general jar package, and then pass it. If there is no key information, you can start a different slave). Now you need to find the gitlab token
1ssCE2ri76RiinkMGKgj
When registering, there are a series of commands. The registration process is an interactive process, and some information needs to be filled in
gitlab url address ----- "token -----" remarks, that is, description information
The tag information is like Jenkins
[root@gitlab-dockerhub ~]# cat /etc/gitlab-runner/config.toml concurrent = 1 check_interval = 0 [session_server] session_timeout = 1800 [root@gitlab-dockerhub ~]# gitlab-runner register Runtime platform arch=amd64 os=linux pid=22183 revision=3b6f852e version=14.0.0 Running in system-mode. Enter the GitLab instance URL (for example, https://gitlab.com/): http://139.198.166.235:81 Enter the registration token: 1ssCE2ri76RiinkMGKgj Enter a description for the runner: [gitlab-dockerhub]: devops01 Enter tags for the runner (comma-separated): build,k8sbuild,go,java Registering runner... succeeded runner=1ssCE2ri Enter an executor: docker-ssh, virtualbox, docker-ssh+machine, shell, ssh, docker+machine, kubernetes, custom, docker, parallels:
Now it's still locked, so the runner can register. The concept of executor is similar to that of Jenkins. The executor helps us run jobs. There are many types of gitlab executors, including docker types as follows:
Enter an executor: docker-ssh, virtualbox, docker-ssh+machine, shell, ssh, docker+machine, kubernetes, custom, docker, parallels:
- Docker type: when a job comes and runs on the docker type runner, you will be asked to enter an ID like, such as the image of maven. At this time, when running the job, a container will be created with the set image, and then built in the container
- Shell type: execute shell commands
- kubernetes type: start a pod
Select the shell type actuator here
Enter tags for the runner (comma-separated): build,k8sbuild,go,java Registering runner... succeeded runner=1ssCE2ri Enter an executor: docker-ssh, virtualbox, docker-ssh+machine, shell, ssh, docker+machine, kubernetes, custom, docker, parallels: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
You can see that the actuator is registered
[root@gitlab-dockerhub ~]# gitlab-runner list Runtime platform arch=amd64 os=linux pid=26860 revision=3b6f852e version=14.0.0 Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml devops01 Executor=shell Token=Tt2yusRjFFFDPQ87Rvsd URL=http://139.198.166.235:81
Check the current status
Indications why this runner can pick jobs without Tags: a tag will be assigned when running the job. This tag will specify which runner to execute on, but the job does not specify this tag. If you want it to execute, just check it.
Because it is a shared type runner, those jobs can use this runner, which can be enabled here
The registration process of runner is completed one by one.