Skip to content

Commit 94d8daf

Browse files
authored
Merge pull request #588 from sraisl/support-ghe-data-residency
Support GitHub Enterprise Cloud data residency API URLs (*.ghe.com)
2 parents 6eca62c + 099f1bf commit 94d8daf

5 files changed

Lines changed: 70 additions & 10 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ These containers are built via Github actions that [copy the dockerfile](https:/
7171
| `RUNNER_WORKDIR` | The working directory for the runner. Runners on the same host should not share this directory. Default is '/_work'. This must match the source path for the bind-mounted volume at RUNNER_WORKDIR, in order for container actions to access files. |
7272
| `RUNNER_GROUP` | Name of the runner group to add this runner to (defaults to the default runner group) |
7373
| `GITHUB_HOST` | Optional URL of the Github Enterprise server e.g github.mycompany.com. Defaults to `github.com`. |
74+
| `GITHUB_API_HOST` | Optional API host to use for token generation. Useful when the API host differs from `GITHUB_HOST`, e.g. `api.mycompany.ghe.com` for GitHub Enterprise Cloud with data residency. |
75+
| `GITHUB_API_PATH` | Optional API path to use for token generation. Defaults to `/api/v3` for non-`github.com` hosts. Set to `/` when the API host does not use a path. |
7476
| `DISABLE_AUTOMATIC_DEREGISTRATION` | Optional flag to disable signal catching for deregistration. Default is `false`. Any value other than exactly `false` is considered `true`. See [here](https://github.com/myoung34/docker-github-actions-runner/issues/94) |
7577
| `CONFIGURED_ACTIONS_RUNNER_FILES_DIR` | Path to use for runner data. It allows avoiding reregistration each the start of the runner. No default value. |
7678
| `EPHEMERAL` | Optional flag to configure runner with [`--ephemeral` option](https://docs.github.com/en/actions/hosting-your-own-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling). Ephemeral runners are suitable for autoscaling. |
@@ -120,6 +122,8 @@ $ GOSS_VARS=goss_vars.yaml GOSS_FILE=goss_full.yaml GOSS_SLEEP=1 dgoss run --ent
120122
-e RUNNER_WORKDIR=/tmp/a \
121123
-e RUNNER_GROUP=wat \
122124
-e GITHUB_HOST=github.example.com \
125+
-e GITHUB_API_HOST=github.example.com \
126+
-e GITHUB_API_PATH=/api/v3 \
123127
-e DISABLE_AUTOMATIC_DEREGISTRATION=true \
124128
-e EPHEMERAL=true \
125129
-e DISABLE_AUTO_UPDATE=true \

app_token.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,36 @@
1111

1212
set -o pipefail
1313

14-
_GITHUB_HOST=${GITHUB_HOST:="github.com"}
14+
normalize_host() {
15+
local host="${1#http://}"
16+
host="${host#https://}"
17+
echo "${host%%/}"
18+
}
19+
20+
normalize_api_path() {
21+
local path="${1:-}"
22+
if [[ -z ${path} ]] || [[ ${path} == "/" ]]; then
23+
echo ""
24+
return
25+
fi
26+
27+
path="/${path#/}"
28+
echo "${path%/}"
29+
}
30+
31+
_GITHUB_HOST=$(normalize_host "${GITHUB_HOST:="github.com"}")
1532

16-
# If URL is not github.com then use the enterprise api endpoint
17-
if [[ ${GITHUB_HOST} = "github.com" ]]; then
18-
URI="https://api.${_GITHUB_HOST}"
33+
if [[ -n ${GITHUB_API_HOST} ]]; then
34+
_GITHUB_API_HOST=$(normalize_host "${GITHUB_API_HOST}")
35+
_GITHUB_API_PATH=$(normalize_api_path "${GITHUB_API_PATH:-/api/v3}")
36+
elif [[ ${_GITHUB_HOST} = "github.com" ]]; then
37+
_GITHUB_API_HOST="api.${_GITHUB_HOST}"
38+
_GITHUB_API_PATH=$(normalize_api_path "${GITHUB_API_PATH:-/}")
1939
else
20-
URI="https://${_GITHUB_HOST}/api/v3"
40+
_GITHUB_API_HOST="${_GITHUB_HOST}"
41+
_GITHUB_API_PATH=$(normalize_api_path "${GITHUB_API_PATH:-/api/v3}")
2142
fi
43+
URI="https://${_GITHUB_API_HOST}${_GITHUB_API_PATH}"
2244

2345
API_VERSION=v3
2446
API_HEADER="Accept: application/vnd.github.${API_VERSION}+json"

entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ _RUNNER_WORKDIR=${RUNNER_WORKDIR:-/_work/${_RUNNER_NAME}}
7070
_LABELS=${RUNNER_LABELS:-${LABELS:-default}}
7171
_RUNNER_GROUP=${RUNNER_GROUP:-Default}
7272
_GITHUB_HOST=${GITHUB_HOST:="github.com"}
73+
_GITHUB_HOST="${_GITHUB_HOST#http://}"
74+
_GITHUB_HOST="${_GITHUB_HOST#https://}"
75+
_GITHUB_HOST="${_GITHUB_HOST%%/}"
7376
_RUN_AS_ROOT=${RUN_AS_ROOT:="true"}
7477
_START_DOCKER_SERVICE=${START_DOCKER_SERVICE:="false"}
7578
_UNSET_CONFIG_VARS=${UNSET_CONFIG_VARS:="false"}
@@ -187,6 +190,8 @@ unset_config_vars() {
187190
unset RUNNER_WORKDIR
188191
unset RUNNER_GROUP
189192
unset GITHUB_HOST
193+
unset GITHUB_API_HOST
194+
unset GITHUB_API_PATH
190195
unset DISABLE_AUTOMATIC_DEREGISTRATION
191196
unset CONFIGURED_ACTIONS_RUNNER_FILES_DIR
192197
unset EPHEMERAL

goss_full.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
command:
2+
/bin/bash -c 'curl(){ printf %s "{\"token\":\"abc\"}"; }; export -f curl; ACCESS_TOKEN=123 RUNNER_SCOPE=org ORG_NAME=myoung34 GITHUB_HOST=github.example.com GITHUB_API_HOST=api.github.example.com GITHUB_API_PATH=/foo /token.sh':
3+
exit-status: 0
4+
stdout:
5+
- '"full_url": "https://api.github.example.com/foo/orgs/myoung34/actions/runners/registration-token"'
6+
stderr: ""
7+
timeout: 2000
8+
29
/entrypoint.sh something:
310
exit-status: 0
411
stdout:

token.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
#!/bin/bash
22

3-
_GITHUB_HOST=${GITHUB_HOST:="github.com"}
3+
normalize_host() {
4+
local host="${1#http://}"
5+
host="${host#https://}"
6+
echo "${host%%/}"
7+
}
48

5-
# If URL is not github.com then use the enterprise api endpoint
6-
if [[ ${GITHUB_HOST} = "github.com" ]]; then
7-
URI="https://api.${_GITHUB_HOST}"
9+
normalize_api_path() {
10+
local path="${1:-}"
11+
if [[ -z ${path} ]] || [[ ${path} == "/" ]]; then
12+
echo ""
13+
return
14+
fi
15+
16+
path="/${path#/}"
17+
echo "${path%/}"
18+
}
19+
20+
_GITHUB_HOST=$(normalize_host "${GITHUB_HOST:="github.com"}")
21+
22+
if [[ -n ${GITHUB_API_HOST} ]]; then
23+
_GITHUB_API_HOST=$(normalize_host "${GITHUB_API_HOST}")
24+
_GITHUB_API_PATH=$(normalize_api_path "${GITHUB_API_PATH:-/api/v3}")
25+
elif [[ ${_GITHUB_HOST} = "github.com" ]]; then
26+
_GITHUB_API_HOST="api.${_GITHUB_HOST}"
27+
_GITHUB_API_PATH=$(normalize_api_path "${GITHUB_API_PATH:-/}")
828
else
9-
URI="https://${_GITHUB_HOST}/api/v3"
29+
_GITHUB_API_HOST="${_GITHUB_HOST}"
30+
_GITHUB_API_PATH=$(normalize_api_path "${GITHUB_API_PATH:-/api/v3}")
1031
fi
32+
URI="https://${_GITHUB_API_HOST}${_GITHUB_API_PATH}"
1133

1234
API_VERSION=v3
1335
API_HEADER="Accept: application/vnd.github.${API_VERSION}+json"

0 commit comments

Comments
 (0)