Skip to content

Commit b6b748a

Browse files
committed
Support organization-level runners
1 parent eec7229 commit b6b748a

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ For now, there is only a Debian Buster image, but I may add more variants in the
1010

1111
## Important notes
1212

13-
GitHub [recommends](https://help.github.com/en/github/automating-your-workflow-with-github-actions/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories) that you do **NOT** use self-hosted runners with public repositories, for security reasons.
13+
* GitHub [recommends](https://help.github.com/en/github/automating-your-workflow-with-github-actions/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories) that you do **NOT** use self-hosted runners with public repositories, for security reasons.
14+
* Organization level self-hosted runners are supported (see environment variables), but be advised that the GitHub API for organization level runners is still in public beta and subject to changes.
1415

1516
## Usage
1617

@@ -49,6 +50,7 @@ services:
4950
environment:
5051
RUNNER_NAME: "my-runner"
5152
RUNNER_REPOSITORY_URL: ${RUNNER_REPOSITORY_URL}
53+
#RUNNER_ORGANIZATION_URL: ${RUNNER_ORGANIZATION_URL}
5254
GITHUB_ACCESS_TOKEN: ${GITHUB_ACCESS_TOKEN}
5355
volumes:
5456
- /var/run/docker.sock:/var/run/docker.sock
@@ -57,22 +59,33 @@ services:
5759
You can create a `.env` to provide environment variables when using docker-compose :
5860
```
5961
RUNNER_REPOSITORY_URL=https://github.com/your_url/your_repo
62+
# or RUNNER_ORGANIZATION_URL=https://github.com/your-organization
6063
GITHUB_ACCESS_TOKEN=the_runner_token
6164
```
6265
6366
## Environment variables
6467
6568
The following environment variables allows you to control the configuration parameters.
6669
67-
| Name | Description | Default value |
70+
| Name | Description | Required/Default value |
6871
|------|---------------|-------------|
69-
| RUNNER_REPOSITORY_URL | The runner will be linked to this repository URL | Required |
70-
| GITHUB_ACCESS_TOKEN | Personal Access Token created on [your settings page](https://github.com/settings/tokens) with `repo` scole. Used to dynamically fetch a new runner token (recommended). | Required if `RUNNER_TOKEN` is not provided.
72+
| RUNNER_REPOSITORY_URL | The runner will be linked to this repository URL | Required if `RUNNER_ORGANIZATION_URL` is not provided |
73+
| RUNNER_ORGANIZATION_URL | The runner will be linked to this organization URL. *(Self-hosted runners API for organizations is currently in public beta and subject to changes)* | Required if `RUNNER_REPOSITORY_URL` is not provided |
74+
| GITHUB_ACCESS_TOKEN | Personal Access Token. Used to dynamically fetch a new runner token (recommended, see below). | Required if `RUNNER_TOKEN` is not provided.
7175
| RUNNER_TOKEN | Runner token provided by GitHub in the Actions page. These tokens are valid for a short period. | Required if `GITHUB_ACCESS_TOKEN` is not provided
7276
| RUNNER_WORK_DIRECTORY | Runner's work directory | `"_work"`
7377
| RUNNER_NAME | Name of the runner displayed in the GitHub UI | Hostname of the container
7478
| RUNNER_REPLACE_EXISTING | `"true"` will replace existing runner with the same name, `"false"` will use a random name if there is conflict | `"true"`
7579
80+
## Runner Token
81+
82+
In order to link your runner to your repository/organization, you need to provide a token. There is two way of passing the token :
83+
84+
* via `GITHUB_ACCESS_TOKEN` (recommended), containing a [Personnal Access Token](https://github.com/settings/tokens). This token will be used to dynamically fetch a new runner token, as runner tokens are valid for a short period of time.
85+
* For a single-repository runner, your PAT should have `repo` scopes.
86+
* For an organization runner, your PAT should have `admin:org` scopes.
87+
* via `RUNNER_TOKEN`. This token is displayed in the Actions settings page of your organization/repository, when opening the "Add Runner" page.
88+
7689
## Runner auto-update behavior
7790
7891
The GitHub runner (the binary) will update itself when receiving a job, if a new release is available.

debian-buster/entrypoint.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ if [[ -z $RUNNER_TOKEN && -z $GITHUB_ACCESS_TOKEN ]]; then
1919
exit 1
2020
fi
2121

22-
if [[ -z $RUNNER_REPOSITORY_URL ]]; then
23-
echo "Error : You need to set the RUNNER_REPOSITORY_URL environment variable."
22+
if [[ -z $RUNNER_REPOSITORY_URL && -z $RUNNER_ORGANIZATION_URL ]]; then
23+
echo "Error : You need to set the RUNNER_REPOSITORY_URL (or RUNNER_ORGANIZATION_URL) environment variable."
2424
exit 1
2525
fi
2626

@@ -36,23 +36,31 @@ fi
3636
if [[ -f ".runner" ]]; then
3737
echo "Runner already configured. Skipping config."
3838
else
39+
if [[ ! -z $RUNNER_ORGANIZATION_URL ]]; then
40+
SCOPE="orgs"
41+
RUNNER_URL="${RUNNER_ORGANIZATION_URL}"
42+
else
43+
SCOPE="repos"
44+
RUNNER_URL="${RUNNER_REPOSITORY_URL}"
45+
fi
46+
3947
if [[ -n $GITHUB_ACCESS_TOKEN ]]; then
40-
echo "Exchanging the GitHub Access Token with a Runner Token..."
41-
_PROTO="$(echo "${RUNNER_REPOSITORY_URL}" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
42-
_URL="$(echo "${RUNNER_REPOSITORY_URL/${_PROTO}/}")"
48+
49+
echo "Exchanging the GitHub Access Token with a Runner Token (scope: ${SCOPE})..."
50+
51+
_PROTO="$(echo "${RUNNER_URL}" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
52+
_URL="$(echo "${RUNNER_URL/${_PROTO}/}")"
4353
_PATH="$(echo "${_URL}" | grep / | cut -d/ -f2-)"
44-
_ACCOUNT="$(echo "${_PATH}" | cut -d/ -f1)"
45-
_REPO="$(echo "${_PATH}" | cut -d/ -f2)"
4654

4755
RUNNER_TOKEN="$(curl -XPOST -fsSL \
4856
-H "Authorization: token ${GITHUB_ACCESS_TOKEN}" \
4957
-H "Accept: application/vnd.github.v3+json" \
50-
"https://api.github.com/repos/${_ACCOUNT}/${_REPO}/actions/runners/registration-token" \
58+
"https://api.github.com/${SCOPE}/${_PATH}/actions/runners/registration-token" \
5159
| jq -r '.token')"
5260
fi
5361

5462
./config.sh \
55-
--url $RUNNER_REPOSITORY_URL \
63+
--url $RUNNER_URL \
5664
--token $RUNNER_TOKEN \
5765
--name $RUNNER_NAME \
5866
--work $RUNNER_WORK_DIRECTORY \

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
environment:
77
RUNNER_NAME: "my-runner"
88
RUNNER_REPOSITORY_URL: ${RUNNER_REPOSITORY_URL}
9+
#RUNNER_ORGANIZATION_URL: ${RUNNER_ORGANIZATION_URL}
910
GITHUB_ACCESS_TOKEN: ${GITHUB_ACCESS_TOKEN}
1011
volumes:
1112
- /var/run/docker.sock:/var/run/docker.sock

0 commit comments

Comments
 (0)