anpanman
Published on

GitLab CI/CD — runner

Table of Contents

Runner & Executor

When the code is pushed to the GitLab repository, the GitLab runner will call the executor to execute the job. The runner is like a commander, it will assign the job to the executor. The executor(docker images) is like a soldier, it will do the job assigned to it by the commander.

GitLab runner

Where are the GitLab runners?

They are in the Settings > General > runners, then you can see the list of runners.

GitLab runner

Two types of GitLab runners

There are two types of runners, shared runners and private runners. Shared runners are the runners that are shared by all projects. Private runners are the runners that are only used by the project that they belong to.

Register a specific runner

If you want to register a specific runner, follow the steps below.

  1. Go to the Install GitLab runner page to install gitlab-runner.exe.

  2. Add a new folder C:\GitLab Runner folder

  3. Paste the gitlab-runner.exe file into the C:\GitLab Runner folder

  4. Open the command prompt and cd to the C:\GitLab Runner folder

  5. Run the command

    gitlab-runner.exe register
    
  6. Enter some information about the runner, the information is as follows:

    • Enter the GitLab instance URL: https://gitlab.com/
    • Enter the registration token: your registration token
    • Enter the description for the runner: your runner name
    • Enter the tags for the runner (comma separated): your tags
    • Enter the executor: pwsh
    • Enter the default Docker image (e.g. ruby:2.6): your docker image
  7. Run the command

    gitlab-runner.exe start
    
  8. Go to the Settings > General > runners page to see if the runner is registered successfully.

    GitLab runner
  9. Run the command

    gitlab-runner.exe run
    

    so that the runner can start to work.

Register a Docker runner on EC2

If you want to register a runner on EC2, follow the steps below.

Install Docker on EC2 Install Docker on Amazon Linux 2

  1. Apply pending updates using the yum command:
    sudo yum update -y
    
  2. Search for Docker package:
    sudo yum search docker
    
  3. Get version information:
    sudo yum info docker
    
  4. Install docker, run:
    sudo yum install docker
    
  5. Add group membership for the default ec2-user so you can run all docker commands without using the sudo command:
    sudo usermod -a -G docker ec2-user
    id ec2-user
    newgrp docker
    
  6. Start Docker service:
    sudo systemctl enable docker.service
    
  7. Start the Docker service:
    sudo systemctl start docker.service
    

Need docker-compose too? Try this following command:

wget https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)
sudo mv docker-compose-$(uname -s)-$(uname -m) /usr/local/bin/docker-compose
sudo chmod -v +x /usr/local/bin/docker-compose

Install GitLab runner on EC2 Install GitLab runner on Amazon Linux 2

  1. Add the official GitLab repository:
    curl -L "https://packages.gitlab.com/install/repositories/runner/2023-01-08_gitlab-cicd-runner/script.rpm.sh" | sudo bash
    
  2. Install the latest version of GitLab Runner, or skip to the next step to install a specific version:
    sudo yum install gitlab-runner
    
  3. To install a specific version of GitLab Runner:
    yum list gitlab-runner --showduplicates | sort -r
    sudo yum install gitlab-runner-10.0.0-1
    
  4. Register the runner
    gitlab-runner register
    
  5. After registered, you have to start the runner and run it, so that the job can be executed.
    gitlab-runner start
    gitlab-runner run