GitLab ci / cd deployment environment to build

Explanation

Under brief article Gitlab CI, comprising Gitlab Runner, the concepts and Gitlab CI .gitlab-ci.yml common configuration.

Deployment GitLab

Please refer to Docker-compose deployment gitlab Chinese version

What is GitLab CI

GitLab CI is GitLab built-in continuous integration tools, only need to create in the repository root directory .gitlab-ci.ymlfiles, and configuration GitLab Runner; each time submitted, gitlab will automatically recognize the .gitlab-ci.ymlfile and use Gitlab Runner execute the script.

Gitlab Runner

GitLab-Runner is a tool used to .gitlab-ci.yml script execution. Can be understood as, like workers Runner serious work, GitLab-CI is the management center workers, all workers must be registered in GitLab-CI inside, and showed himself to which of project services. When the corresponding item changes, GitLab-CI will notify the appropriate workers to perform 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.

(2) Specific Runner: Only certain items can be used.

Runner build

Both methods provided herein (present use docker):

(1)For RHEL/CentOS

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash

(2) use of docker

#获取gitlab-runner 镜像
docker pull gitlab/gitlab-runner
#启动 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
#进入Runner容器内
docker exec -it gitlab-runner bash

Gets Runner Registration Token

After installing Runner, are required to register Gitlab, registration required GitLab-CI Runner's url and token. Runner registration required type can be selected according to demand.

Get Shared Runnerregistered Token: using the administrator user logs into the Admin Area-> OverView-> Runners interface.

87nJZd.jpg

Get Specific Runnerregistered Token: warehouse project -> settings-> CI / CD interface
87K3Ed.jpg

Registration Runner

#进入Runner容器内
docker exec -it gitlab-runner bash
#运行以下命令
gitlab-runner register
#输入Gitlab实例的地址
#Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.246.194
#输入token
#Please enter the gitlab-ci token for this runner
zN6snSbddCQkJ7y_ef39
#输入Runner的描述
#Please enter the gitlab-ci description for this runner:
[6c011be28cd8]: ci-test apply
#输入与Runner关联的标签
#Please enter the gitlab-ci tags for this runner (comma separated):
ci-test-tag
#输入Ruuner的执行者
#Please enter the executor: custom, ssh, virtualbox, docker-ssh+machine, kubernetes, docker, docker-ssh, parallels, shell, docker+machine:
docker
#如果上面执行者为docker,需要你在.gitlab-ci.yml中指定docker版本
#Please enter the default Docker image (e.g. ruby:2.6):
alpine:latest

After the above command, you can view gitlab into this runner just created:

87lDVe.jpg

Runner modify configuration files

vim /data/gitlab-runner/config/config.toml
#找到volumes配置,修改为如下,分别是挂载了宿主机的docker和配置Maven的缓存,提高效率
volumes = ["/cache","/var/run/docker.sock:/var/run/docker.sock","/data/.m2/:/.m2/"]
#在volumes配置下方增加一行配置,防止Runner重复拉取镜像
pull_policy = "if-not-present"
#重启Runner即可
docker restart gitlab-runner

Reference Documents

Guess you like

Origin blog.51cto.com/wutengfei/2481114