Skip to content

Instantly share code, notes, and snippets.

@e10101
Last active September 25, 2024 10:31
Show Gist options
  • Save e10101/a777ef5e3da449e2b7924788e28d9fac to your computer and use it in GitHub Desktop.
Save e10101/a777ef5e3da449e2b7924788e28d9fac to your computer and use it in GitHub Desktop.
How to setup multiple Github Runner with Docker command

For Repo

function github-runner {
    org=$(dirname $1)
    repo=$(basename $1)
    token=$2
    index=$3
    tag=${4:-latest}
    runner_group=${5:-Default}
    
    name=github-runner-${org}-${repo}-${index}
    
    docker rm -f $name
    docker run -d --restart=always \
        -e REPO_URL="https://github.com/${org}/${repo}" \
        -e RUNNER_TOKEN="$token" \
        -e RUNNER_NAME="linux-${repo}-${index}" \
        -e RUNNER_WORKDIR="/tmp/github-runner-${repo}-${index}" \
        -e RUNNER_GROUP="$runner_group" \
        -e LABELS="the-runner" \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /tmp/github-runner-${repo}-${index}:/tmp/github-runner-${repo}-${index} \
        --name $name myoung34/github-runner:$tag
}

For example, you can run following command:

github-runner e10101/learn-rust   ARGHANOTHERGITHUBACTIONSTOKEN 1
github-runner e10101/learn-rust   ARGHANOTHERGITHUBACTIONSTOKEN 2 ubuntu-focal
github-runner your-account/some-other-repo ARGHANOTHERGITHUBACTIONSTOKEN ubuntu-focal

For Org

function github-runner-org {
    org=$1
    token=$2
    index=$3
    labels=$4
    tag=${5:-latest}
    runner_group=${6:-Default}
    
    name=github-runner-${org}-${index}
    
    docker rm -f $name
    docker run -d --restart=always \
        -e ORG_NAME="$org" \
        -e RUNNER_SCOPE="org" \
        -e RUNNER_TOKEN="$token" \
        -e RUNNER_NAME="${org}-runner-${index}" \
        -e RUNNER_WORKDIR="/tmp/github-runner-${org}-${index}" \
        -e RUNNER_GROUP="$runner_group" \
        -e LABELS="$labels" \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /tmp/github-runner-${org}-${index}:/tmp/github-runner-${org}-${index} \
        --name $name myoung34/github-runner:$tag
}
# Using default runner group "Default" and latest tag
github-runner-org your-org-name YOUR_ORG_RUNNER_TOKEN 1 "org-runner,linux"

# Specifying a custom runner group and tag
github-runner-org your-org-name YOUR_ORG_RUNNER_TOKEN 2 "org-runner,docker" ubuntu-focal "Custom Group"

# Using default runner group with specific labels and tag
github-runner-org your-org-name YOUR_ORG_RUNNER_TOKEN 3 "org-runner,aws,python" ubuntu-focal

# Specifying labels, tag, and runner group
github-runner-org your-org-name YOUR_ORG_RUNNER_TOKEN 4 "org-runner,gpu" ubuntu-focal "Another Group"

# Example
export $TOKEN=********
github-runner-org tinylink-project $TOKEN 1 "linter" ubuntu-focal "lint"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment