Use gitlab to build docker-based continuous integration (2)

Use gitlab to build docker-based continuous integration (2)


 

 

Centos configure gitlab mirror and start

Create a directory structure on the local machine, and then upload it to the virtual machine to run. The software used is Xshell and Xftp. Remember to bring the CA certificate.

Directory Structure:

gitlab
	config
		ssl
			gitlab.luna.cn.crt
			gitlab.luna.cn.key
	logs
	docker-compose.yml

docker-compose.yml file, it should be noted that the environment variable configuration here can use the configuration in the gitlab configuration file, but the configuration file can also be used later.

version: '3'
services:
    gitlab:
      image: 'twang2218/gitlab-ce-zh:10.6.2'
      restart: unless-stopped
      hostname: 'gitlab.luna.cn'
      container_name: gitlab1062
      environment:
        TZ: 'Asia/Shanghai'
        GITLAB_OMNIBUS_CONFIG: |
          external_url 'http://gitlab.luna.cn/'
          registry_external_url 'https://gitlab.luna.cn'
          gitlab_rails['time_zone'] = 'Asia/Shanghai'
          # gitlab_rails['smtp_enable'] = true
          # gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
          # gitlab_rails['smtp_port'] = 465
          # gitlab_rails['smtp_user_name'] = "[email protected]"
          # gitlab_rails['smtp_password'] = "password"
          # gitlab_rails['smtp_authentication'] = "login"
          # gitlab_rails['smtp_enable_starttls_auto'] = true
          # gitlab_rails['smtp_tls'] = true
          # gitlab_rails['gitlab_email_from'] = '[email protected]'
      ports:
        - '80:80'
        - '443:443'
        - '1022:22'
      volumes:
        - ./data:/var/opt/gitlab
        - ./config:/etc/gitlab
        - ./logs:/var/log/gitlab

Upload to /root folder

 

gitlab folder upload

 

 

Run docker-compose up in Xshell, wait....

Centos configure firewall

I list the commands that need to be used for configuration, mainly open http, https, docker-registry services and port 1022.
Port 1022 is used for ssh.

firewall-cmd --list-ports #查看打开的端口
firewall-cmd --list-services #查看打开的服务
firewall-cmd --get-services  #查看可以打开的服务

firewall-cmd --add-service=xxx --permanent  #添加服务
firewall-cmd --add-port=xx/tcp --permanent #添加端口

firewall-cmd --reload      #打开操作之后要重载

Access gitlab on windows

The domain name is: gitlab.luna.cn can be accessed, indicating that everything is normal.
Then what you need to do is:
1. You need to create an administrator password
2. The administrator account is root, and log in with the set password.
3. If you are using gitlab for the first time, you can look at each menu, and if you are not interested, you can close it.

Configure gitlab-runner on Centos

gitlab-runner is a big pit, I don't know if I can make it clear, I hope you can correct me if I'm wrong.

According to the official installation, the runner needs to be registered first, so that gitlab can recognize the runner and trigger the runner to run the job.

Here I am using the docker image of the runner.

1. First create a folder to put the configuration file of the runner, here is /root/gitlab-runner.
2. Then start the runner image and perform registration. Except for the first and second parameters of the registered parameters, other parameters can be configured later, without too much entanglement.

  #运行镜像
  docker run -d --name gitlab-runner-bate --restart always \
  -v /var/run/docker.sock:/var/run/docker.sock \#这个配置可以让runner联通本机docker
  -v /root/gitlab-runner/config:/etc/gitlab-runner \
  gitlab/gitlab-runner:latest
  
  #执行注册
   docker exec -it gitlab-runner-bate gitlab-runner register

3. After registration, the directory structure should be like this, and then the configuration file should be like this.

gitlab-runner
  config
     config.toml
  docker-compose.yml

config.toml

concurrent = 1
check_interval = 0

[[runners]]
  name = "test"
  url = "http://gitlab.luna.cn/"
  token = "040a9c35d32e1c9a912c006c8a10a6"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0
  [runners.cache]

4. Whether the runner is successfully configured, you can log in to gitlab with the administrator to check. If it is successful, you can see it.
5. Then create a docker-compose to start, you don't need to type such a long docker run command.
docker-compose.yml

version: '3'
services:
    runner:
      image: 'gitlab/gitlab-runner:latest'
      container_name: gitlab-runner
      restart: always 
      volumes: 
        - ./config:/etc/gitlab-runner
        - /var/run/docker.sock:/var/run/docker.sock

Finally, post a few official documents for your reference, and make a note for yourself.

Configuration of gitlab-runner
to run GitLab Runner in a container

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325510066&siteId=291194637