Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 314
dmallory42 Avatar asked Jan 29 '19 09:01

dmallory42


People also ask

Where does GitLab runner execute?

Gitlab Runner is an application that works with GitLab CI/CD to run the job in a pipeline. It is open-source and written in Go Language. It can also be run inside the Docker container or it can be deployed into a Kubernetes cluster.

What does GitLab runner run do?

In GitLab CI, Runners run your yaml. A runner is an isolated (virtual) machine that picks up builds through the coordinator API of GitLab CI. A runner can be specific to a certain project or serve any project in GitLab CI. A runner that serves all projects is called a shared runner.

Does GitLab runner run as root?

Summary. GitLab runner's pwsh shell runs as the root user on linux systems, not gitlab-runner user like the rest of the shell executors.

Where does GitLab run pipeline?

CI configuration The stages, pipelines, and jobs configurations are made in the file . gitlab-ci. yml in the root of the repository. I recommend editing the configuration with GitLab's build-in Pipeline editor as it automatically checks for accuracy during editing.


2 Answers

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.

like image 166
Jakub Kania Avatar answered Oct 06 '22 20:10

Jakub Kania


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.

like image 36
Laci R Avatar answered Oct 06 '22 20:10

Laci R