Skip to content

Instantly share code, notes, and snippets.

@cprivitere
Last active May 24, 2023 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cprivitere/3aad99f18a7f53ccf56f5a1b4b75bac4 to your computer and use it in GitHub Desktop.
Save cprivitere/3aad99f18a7f53ccf56f5a1b4b75bac4 to your computer and use it in GitHub Desktop.
Self-hosted GitHub runners on Equinix Metal
  • Get an Equinix Metal API account and API key
  • Downlaod metal-cli
  • Fork metal-cli to your own github
  • Disable the actions on your fork for now till we're ready for them. :)
  • Deploy a new machine on Equinix Metal
    • On stream we'll use the GUI, but the CLI will also work
    • metal device create -p $METAL_PROJECT_ID -P c3.medium.x86 -m da -H github-runner-test -O ubuntu_22_04
  • Requirements for runners
  • How to add a runner
  • Navigate to your metal-cli fork, for me it's https://github.com/cprivitere/metal-cli
  • Go to the 'settings' tab
  • On the left bar, click 'actions', then 'runners'
  • Click the 'new self-hosted runner' button
  • Select the correct OS options, for our demo it's Linux x64.
  • You should now see instructions for downloading, configuring, and using the github runner software.
  • SSH to the machine you created earlier
  • Install gcc, create a new user, and switch to it, the Github runner won't allow itself to be run as root
    apt update
    apt install build-essential gcc
    useradd -m ghrunner -s /bin/bash
    su - ghrunner
  • Copy and paste the download and configure sections from the 'Add New Runner' page
    • Take the defaults by just pressing enter when it asks for the group, name, labels, and work folder
    • Don't forget to run ./run.sh
    • If you were doing this as a long lived runner in production this would be better executed as a systemctl service...but long lived runners are actually not recommended, so just running ./run.sh inline is fine for today.
  • Your runner should now say it's 'Listening for Jobs'
  • Let's go back to our fork of metal-cli.
  • Click on 'Settings' -> 'Actions' -> 'Runners' again in the repo and you should see your new self-hosted runner
  • Now we go edit our github actions workflow to use a self-hosted runner
  • Edit metal-cli/.github/workflows/test.yml and replace the line:
        runs-on: ubuntu-latest
    with
        runs-on: self-hosted
  • Also add
      workflow_dispatch:
    underneath the on: line
  • You test.yml file should now look like:
    name: Go Tests
    on:
      pull_request:
      workflow_dispatch:
    jobs:
      test:
        runs-on: self-hosted
        timeout-minutes: 10
        steps:
        - name: Set up Go
          uses: actions/setup-go@v4.0.0
          with:
            go-version: '1.19'
        - name: Check out code into the Go module directory
          uses: actions/checkout@v3
        - name: Get dependencies
          run: go mod download
        - name: Build
          run: go build -v ./...
        - name: TF tests
          run: go test -v -cover -parallel 4 ./...
  • Commit your changes
  • Go back to 'Settings' -> 'Actions' -> 'General' and Allow all actions and reusable workflows.
  • Now click on Actions and click on 'Go Tests' on the left side.
  • Click the 'Run workflow' drop down on the right side and run it for the main branch.
  • Now watch the output on your github runner and the output inside github.
  • Running job: test should appear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment