gitlabgitlab-cigitlab-ci-runnergitlab-ce

How do I set up a new runner with EC2 auto scaling?


I have set up Gitlab runners to auto scale based on the demand. The documentation from Gitlab is here: https://docs.gitlab.com/runner/configuration/runner_autoscale_aws/

TL;DR - there is a server, let's call it runner_manager, with Docker+Machine installed which spins up new EC2 servers and they're used as my runners. The runner_manager is used to just connect to Gitlab and spin up these runners but it doesn't run any builds directly.

Now, there is a need to have another set of runners needed which will be quite different but I am not sure where to start. What I am trying to avoid is having another runner_manager server set up.

Here is my config.toml file on my runner_manager server:

concurrent = 10
check_interval = 30

[[runners]]
  name = "runner-manager"
  limit = 3
  url = "https://git.someURL.com"
  id = 18
  token = "xxxxxxxxxxxxxxxxxxxx"
  token_obtained_at = 2023-01-12T06:08:06Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker+machine"
  [runners.docker]
    tls_verify = false
    image = "alpine"
    privileged = true
    oom_kill_disable = false
    shm_size = 0
  [runners.machine]
    IdleCount = 1
    IdleScaleFactor = 0.0
    IdleCountMin = 0
    IdleTime = 1800
    MachineDriver = "amazonec2"
    MachineName = "runners-%s"
    MachineOptions = [
      "amazonec2-region=us-east-1",
      "amazonec2-vpc-id=vpc-xxxxxxxxxxxxxxxxxx",
      "amazonec2-subnet-id=subnet-xxxxxxxxxxxxxxxxxx",
      "amazonec2-ami=ami-xxxxxxxxxxxxxxxxxx",
      "amazonec2-security-group=runner-sg",
      "amazonec2-instance-type=t3.large",
      "amazonec2-root-size=100",
    ]
  [[runners.machine.autoscaling]]
    Periods = ["* * 1-17 * * mon-fri *"]
    IdleCount = 1
    IdleTime = 3600
    Timezone = "UTC"
  [[runners.machine.autoscaling]]
    Periods = ["* * * * * sat,sun *"]
    IdleCount = 0
    IdleTime = 3600
    Timezone = "UTC"

My ideal outcome is to have 1 runner_manager which spins up two sets of auto-scaled runners (with their own configurations), I just don't know how. In Gitlab admin section, I can only connect to this one runner_manager.


Solution

  • Figured it out.

    First, you have to register the 2nd runner in the CLI. Something like:

    sudo gitlab-runner register
    

    You then need to provide the token, tags etc.

    Once you do that, it will create another section in the config.toml. You can then modify as you please. See below and notice that there are not two sections for [[runners]]

    concurrent = 10
    check_interval = 30
    
    [[runners]]
      name = "runner-manager"
      limit = 3
      url = "https://git.someURL.com"
      id = 18
      token = "xxxxxxxxxxxxxxxxxxxx"
      token_obtained_at = 2023-01-12T06:08:06Z
      token_expires_at = 0001-01-01T00:00:00Z
      executor = "docker+machine"
      [runners.docker]
        tls_verify = false
        image = "alpine"
        privileged = true
        oom_kill_disable = false
        shm_size = 0
      [runners.machine]
        IdleCount = 1
        IdleScaleFactor = 0.0
        IdleCountMin = 0
        IdleTime = 1800
        MachineDriver = "amazonec2"
        MachineName = "runners-%s"
        MachineOptions = [
          "amazonec2-region=us-east-1",
          "amazonec2-vpc-id=vpc-xxxxxxxxxxxxxxxxxx",
          "amazonec2-subnet-id=subnet-xxxxxxxxxxxxxxxxxx",
          "amazonec2-ami=ami-xxxxxxxxxxxxxxxxxx",
          "amazonec2-security-group=runner-sg",
          "amazonec2-instance-type=t3.large",
          "amazonec2-root-size=100",
        ]
      [[runners.machine.autoscaling]]
        Periods = ["* * 1-17 * * mon-fri *"]
        IdleCount = 1
        IdleTime = 3600
        Timezone = "UTC"
      [[runners.machine.autoscaling]]
        Periods = ["* * * * * sat,sun *"]
        IdleCount = 0
        IdleTime = 3600
        Timezone = "UTC"
    [[runners]]
      name = "runner-manager-2"
      limit = 3
      url = "https://git.someURL.com"
      id = 18
      token = "xxxxxxxxxxxxxxxxxxxx"
      token_obtained_at = 2023-01-12T06:08:06Z
      token_expires_at = 0001-01-01T00:00:00Z
      executor = "docker+machine"
      [runners.docker]
        tls_verify = false
        image = "alpine"
        privileged = true
        oom_kill_disable = false
        shm_size = 0
      [runners.machine]
        IdleCount = 0
        IdleScaleFactor = 0.0
        IdleCountMin = 0
        IdleTime = 1800
        MachineDriver = "amazonec2"
        MachineName = "runners-2-%s"
        MachineOptions = [
          "amazonec2-region=us-east-1",
          "amazonec2-vpc-id=vpc-xxxxxxxxxxxxxxxxxx",
          "amazonec2-subnet-id=subnet-xxxxxxxxxxxxxxxxxx",
          "amazonec2-ami=ami-xxxxxxxxxxxxxxxxxx",
          "amazonec2-security-group=runner-sg",
          "amazonec2-instance-type=t3.large",
          "amazonec2-root-size=100",
        ]
    

    PS: I did try to add this to the config.toml directly but the token seems to be encrypted - as in, it's not the one you get from the Gitlab UI.

    Hope this helps someone someday.