Explain
This paper briefly introduces Gitlab CI, including Gitlab Runner, related concepts in Gitlab CI and common configuration of. gitlab-ci.yml.
Deploying GitLab
Please refer to Docker compose deployment of Chinese version of gitlab
What is GitLab CI
GitLab CI is a built-in tool for continuous integration of gitlab. You only need to create the. gitlab-ci.yml file in the warehouse root directory and configure gitlab runner. Every time you submit it, gitlab will automatically recognize the. gitlab-ci.yml file and execute the script using gitlab runner.
Gitlab Runner
Gitlab Runner is a tool for executing. gitlab-ci.yml scripts. It can be understood that Runner is like a conscientious worker. Gitlab CI is the center of managing workers. All workers should register in gitlab Ci and indicate which project they are serving. When the corresponding project changes, gitlab CI informs the corresponding worker to execute the corresponding script.
Runner type
Gitlab runner can be classified into two types: Shared Runner and Specific Runner.
(1) Shared Runner: all projects can be used, and only the system administrator can create them.
(2) Specific Runner: only specific projects can be used.
Runner build
There are two methods (docker is used this time):
(1)For RHEL/CentOS
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
(2) Using docker
#Get gitlab runner image docker pull gitlab/gitlab-runner #Start gitlab runner docker run -d \ -p 2443:443 \ -p 5678:5678 \ -p 2222:22 \ --name gitlab-runner \ --restart always \ -v /data/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest
#Enter the Runner container docker exec -it gitlab-runner bash
Get Runner registration Token
After the Runner is installed, you need to register with Gitlab. To register the Runner, you need the url and token of Gitlab CI. You can register and select the type of Runner you want according to your needs.
Get the Shared Runner registration Token: log in with the administrator user and enter the admin area > overview > runners interface.
Get Specific Runner registration Token: project warehouse - > Settings - > CI / CD interface
Registered Runner
#Enter the Runner container docker exec -it gitlab-runner bash #Run the following command gitlab-runner register #Enter the address of the Gitlab instance #Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): http://192.168.246.194 #Input token #Please enter the gitlab-ci token for this runner zN6snSbddCQkJ7y_ef39 #Enter a description of the Runner #Please enter the gitlab-ci description for this runner: [6c011be28cd8]: ci-test apply #Enter the label associated with the Runner #Please enter the gitlab-ci tags for this runner (comma separated): ci-test-tag #Enter the performer of the Ruuner #Please enter the executor: custom, ssh, virtualbox, docker-ssh+machine, kubernetes, docker, docker-ssh, parallels, shell, docker+machine: docker #If the above executor is docker, you need to specify the docker version in. gitlab-ci.yml #Please enter the default Docker image (e.g. ruby:2.6): alpine:latest
After passing the above command, you can see the newly created runner in gitlab:
Modify Runner profile
vim /data/gitlab-runner/config/config.toml #Find the volumes configuration and modify it as follows: mount the docker of the host and configure the cache of Maven to improve efficiency volumes = ["/cache","/var/run/docker.sock:/var/run/docker.sock","/data/.m2/:/.m2/"] #Add a line of configuration under the volumes configuration to prevent the Runner from repeatedly pulling the image pull_policy = "if-not-present" #Restart the Runner docker restart gitlab-runner