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]: EXAMPLE-digitalocean-auto-nyc3
    Please enter the gitlab-ci tags for this runner (comma separated):
    EXAMPLE,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/EXAMPLE/config/config.toml
    • DigitalOcean:
      /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"
        environment = ["DOCKER_AUTH_CONFIG={...}"]
        [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"
          ]
      • List all images:
        $ curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer EXAMPLE_YOUR_TOKEN" "https://api.digitalocean.com/v2/images?page=1&per_page=1000&type=application"
    • AWS EC2:
      /srv/gitlab-ci-runner/auto-aws-us-west-1/config/config.toml
      concurrent = 5
       
      [[runners]]
        name = "auto-aws-us-west-1"
        url = "https://git.EXAMPLE.com/ci"
        token = "FIND_AT https://git.EXAMPLE.com/admin/runners/EXAMPLE"
        executor = "docker+machine"
        environment = ["DOCKER_AUTH_CONFIG={...}"]
        [runners.docker]
          image = "ubuntu:xenial"
          tls_verify = false
          privileged = true
          disable_cache = true
        [runners.cache]
          Insecure = false
        [runners.machine]
          IdleCount = 0
          IdleTime = 1200
          MachineDriver = "amazonec2"
          MachineName = "orzgit-%s"
          MachineOptions = [
            "amazonec2-access-key=EXAMPLE",
            "amazonec2-secret-key=EXAMPLE",
            "amazonec2-region=us-west-1",
            "amazonec2-ami=ami-615cb725",
            "amazonec2-ssh-user=ubuntu",
            "amazonec2-instance-type=t2.medium"
          ]
  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

Notes

See Alsos