dmallory42
dmallory42

Reputation: 129

Where should the GitLab Runner actually run?

I'm trying to set up a Continuous Integration/Deployment pipeline using GitLab CI, and I'm struggling to understand (and not really finding any information in the documentation) about where a GitLab Runner should actually live. Should I run one on my local machine? Should there be a server that just hosts the Runner?

From my understanding, the purpose of the runner is to execute the jobs which are triggered by a commit. Upon commit, the GitLab Runner will try and execute the jobs defined in the .gitlab-ci.yml file.

I am aware that these jobs can do numerous things, but as a starting point, I would simply like to SSH into a server, and deploy my code.

My confusion comes from not understanding what the recommended place the Runner should actually live and run is? It seems potentially problematic to store it on my local machine as this would rely on my machine being on and available for deployments to work. Does this mean we'd require another server just for the runner itself?

Upvotes: 11

Views: 5499

Answers (2)

Laci R
Laci R

Reputation: 31

As documentation says, GitLab runners are isolated (virtual) machines that pick up jobs through the coordinator API of GitLab CI. They can be installed in every distribution. Before configuring obtain runner token from admin/runners page. Then register with

sudo gitlab-runner register

You can use GitLab Runner in docker image on you VPS, e.g. AWS. This is example of runners-machine. Driver is set to amazonec2, there are multiple options like access-key, region, sec-group.

  [runners.machine]
    IdleCount = 1
    IdleTime = 1800
    MaxBuilds = 10
    OffPeakPeriods = [
      "* * 0-9,18-23 * * mon-fri *",
      "* * * * * sat,sun *"
    ]
    OffPeakIdleCount = 0
    OffPeakIdleTime = 1200
    MachineDriver = "amazonec2"
    MachineName = "gitlab-docker-machine-%s"
    MachineOptions = [
      "amazonec2-access-key=XXXX",
      "amazonec2-secret-key=XXXX",
      "amazonec2-region=us-central-1",
      "amazonec2-vpc-id=vpc-xxxxx",
      "amazonec2-subnet-id=subnet-xxxxx",
      "amazonec2-zone=x",
      "amazonec2-use-private-address=true",
      "amazonec2-tags=runner-manager-name,gitlab-aws-autoscaler,gitlab,true,gitlab-runner-autoscale,true",
      "amazonec2-security-group=xxxxx",
      "amazonec2-instance-type=m4.2xlarge",
    ]

In the [runners.docker] section set default Docker image.

See documentation: https://docs.gitlab.com/runner/configuration/autoscale.html

Upvotes: 2

Jakub Kania
Jakub Kania

Reputation: 16467

Where? Well, whenever you want. Gitlab runner operate in pull mode, that is the runner contacts the web api of the server and checks for jobs, it also contacts the server to upload all the logs. That means that the gitlab runner can be behind NAT or it can be very dynamic.

The SSH executor runs by connection over SSH from the runner to the target. That means that the machine with the runner has to have a route to the target server.

As for where you should run the runners? Well, that's up to you. Maybe you need to occasionally run it on your laptop to connect to local VM, maybe you need a beefy machine in the cloud, maybe you want to run a cheap machine on old server in your basement. Maybe all three.

Upvotes: 7

Related Questions