GitLab

Gitlab Runner

  • In GitLab CI, Runners run the code defined in .gitlab-ci.yml. They are isolated (virtual) machines that pick up jobs through the coordinator API of GitLab CI. 1

How to add new runner to project?

  1. Follow “Settings -> CI/CD -> Runner” sections on your repository page.

  2. Expand runner section and follow “Set up a specific Runner manually section."

  3. Register your gitlab-runner.

    sudo gitlab-runner register
    
  4. Here is our demo registry steps. Register Runner

  5. If all steps done successfully, you will see your slave under project “Settings -> CI/CD -> Runner” section. Available Runner

  6. [OPTIONAL] Each runner assigned to a gitlab-ci tag so that you have to use right tag in CI file to run CI jobs on specific runner but you can enable runners to run jobs without tag checking. Otherwise, runners will be blocked until right job came.

    Runner Settings

    1. Click edit button which is located besides lock sign.
    2. Activate Run untagged jobs check-box and save changes.
    3. Uncheck “Lock to Current Project” to use same runner with other repositories.

How to configure runners to leverage full docker abilities?

  • After registring a runners, gitlab-runner tool will create a config file at this location.

    sudo cat /etc/gitlab-runner/config.toml
    
    • Here is my config.toml file

      concurrent = 1
      check_interval = 0
      
      [session_server]
      session_timeout = 1800
      
      [[runners]]
          name = "hmenn-macbook-pro"
          url = "https://gitlab.bosphorusiss.com/"
          token = "Dw-L......"
          executor = "docker"
          [runners.custom_build_dir]
          [runners.docker]
              tls_verify = false
              image = "ubuntu:18.04"
              privileged = false
              disable_entrypoint_overwrite = false
              oom_kill_disable = false
              disable_cache = false
              volumes = ["/cache"]
              shm_size = 0
          [runners.cache]
              [runners.cache.s3]
              [runners.cache.gcs]
      
  • Now, Open this file with your favourite text editor then we will add extra configs.

    sudo cat /etc/gitlab-runner/config.toml
    
    • Enable privilaged mode.

    • Add docker socket as volume to support docker in docker(dind).

    • Add pull policy. This config will let runner to download images from registry if not exist on runner machine.

      concurrent = 1
      check_interval = 0
      
      [session_server]
      session_timeout = 1800
      
      [[runners]]
          name = "hmenn-macbook-pro"
          url = "https://gitlab.bosphorusiss.com/"
          token = "Dw-L......"
          executor = "docker"
          [runners.custom_build_dir]
          [runners.docker]
              tls_verify = false
              image = "ubuntu:18.04"
      

    +–> privileged = true disable_entrypoint_overwrite = false oom_kill_disable = false disable_cache = false +–> volumes = ["/var/run/docker.sock:/var/run/docker.sock", “/cache”] shm_size = 0 +–> pull_policy = “if-not-present” [runners.cache] [runners.cache.s3] [runners.cache.gcs] ```

    • Save changes and restart gitlab-runner.

      sudo gitlab-runner restart
      sudo gitlab-runner run
      
    • You should run gitlab-runner at background.