AI Hints
Home›CI/CD with GitHub Actions Tutorial›Privilege, Runners, and Monorepos
CI/CD with GitHub Actions · Lesson 110 of 138

Self-Hosted Runners

Your own machines.

⏱ 2 min read▶ Video at 2:08:19🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

GitHub's runners are fresh virtual machines, managed for you. But sometimes you need your own. Special hardware like GPUs, access to a private network, or just cheaper minutes. Then you can use a self hosted runner.

Self-Hosted Runners
From the video: Self-Hosted Runners
  • GitHub runners: managed
  • Sometimes you need your own
  • GPUs, private networks

Using one

You install the runner program on your machine, and register it with labels. A job picks it with runs on, and a list of labels. This job needs a runner with all three labels, self hosted, linux, and GPU.

.github/workflows/train.ymlyaml
jobs:
  build:
    runs-on: [self-hosted, linux, gpu]
    steps:
      - uses: actions/checkout@v4
      - run: ./train-model.sh

GitHub-hosted or self-hosted?

GitHub hosted runners are clean every time, and there's nothing to maintain. Self hosted runners can be faster and cheaper, but you patch them, and they may keep leftovers between jobs. Never use self hosted runners on public repositories, because anyone's pull request could run code on your machine.

GitHub-hosted

  • Fresh every job
  • No maintenance
  • Pay per minute

Self-hosted

  • Your hardware
  • You patch it
  • Never for public repos

Summary

Self hosted runners run jobs on your machines, chosen by labels. Keep them private, and patched. Next, pipelines for repositories with many projects.

Key takeaways
  • runs-on: labels
  • Your hardware
  • Not on public repos
Next up: Monorepos — many projects, one repo