This is an old revision of the document!


Run GitLab CI Runner with Docker

  1. Run docker run -it –rm gitlab/gitlab-runner:ubuntu-v9.0.2 register
    # docker run -it --rm gitlab/gitlab-runner:ubuntu-v9.0.2 register
    Running in system-mode.
     
    Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
    https://git.EXAMPLE.com/
    Please enter the gitlab-ci token for this runner:
    EXAMPLE # find at https://git.EXAMPLE.com/admin/runners
    Please enter the gitlab-ci description for this runner:
    [EXAMPLE00000]: digitalocean-auto-nyc3
    Please enter the gitlab-ci tags for this runner (comma separated):
    digitalocean,digitalocean-nyc3,linux
    Whether to run untagged builds [true/false]:
    [false]: true
    Whether to lock Runner to current project [true/false]:
    [false]: false
    Registering runner... succeeded                     runner=EXAMPLE0
    Please enter the executor: parallels, kubernetes, ssh, virtualbox, docker+machine, docker-ssh+machine, docker, docker-ssh, shell:
    shell # skip the following interactive setup as we have to configure it manually
    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
  2. Create /srv/gitlab-ci-runner/digitalocean-auto-nyc3/config/config.toml
    /srv/gitlab-ci-runner/digitalocean-auto-nyc3/config/config.toml
    concurrent = 5
     
    [[runners]]
      name = "digitalocean-auto-nyc3"
      url = "https://git.EXAMPLE.com/ci"
      token = "FIND_AT https://git.EXAMPLE.com/admin/runners/EXAMPLE"
      executor = "docker+machine"
      [runners.docker]
        image = "ubuntu:xenial"
        tls_verify = false
        privileged = true
        disable_cache = true
      [runners.cache]
        Insecure = false
      [runners.machine]
        IdleCount = 0
        IdleTime = 1200
        MachineDriver = "digitalocean"
        MachineName = "orzgit-%s"
        MachineOptions = [
          "digitalocean-image=ubuntu-14-04-x64",
          "digitalocean-ssh-user=root",
          "digitalocean-access-token=EXAMPLE_EXAMPLE_EXAMPLE",
          "digitalocean-region=nyc3",
          "digitalocean-size=2gb",
          "digitalocean-private-networking"
        ]
  3. Save systemd configuration
    /etc/systemd/system/gitlab-ci-runner@.service
    [Unit]
    Description=GitLab CI Runner (%i)
    After=docker.service
    Requires=docker.service
    BindsTo=docker.service
     
    [Service]
    SyslogIdentifier=gitlab-ci-runner@%i.service
    ExecStart=/usr/bin/systemd-docker run \
      --rm \
      --name gitlab-ci-runner.%i.service \
      --volume /srv/gitlab-ci-runner/%i/config:/etc/gitlab-runner \
      --volume /srv/gitlab-ci-runner/%i/home:/home/gitlab-runner \
      --volume /srv/gitlab-ci-runner/%i/home:/root \
      gitlab/gitlab-runner:ubuntu-v9.0.2
    Restart=always
    RestartSec=30s
    Type=notify
    NotifyAccess=all
    TimeoutStartSec=120
    TimeoutStopSec=30
     
    [Install]
    WantedBy=multi-user.target
  4. Enable and start service
    # systemctl enable gitlab-ci-runner@digitalocean-auto-nyc3.service
    # systemctl start gitlab-ci-runner@digitalocean-auto-nyc3.service

See Alsos