Skip to content

Commit

Permalink
Add a feature to re-use existing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Sep 9, 2024
1 parent 38d45f7 commit caaa3a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ docker compose up -d
- **RUNNER_NAME** - Runner name. Uses a random instance ID.
- **WORK_DIR** - Work directory. Uses `_work`
- **LABELS** - Runner labels (comma separated). Uses `"docker-node,${os_name}-${architecture}"`
- **REUSE_EXISTING** - Re-use existing configuration. Defaults to `false`

> `REUSE_EXISTING` can come in handy when a container restarts due to a problem,
> or when a container is deleted without gracefully shutting down.
## Development

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ services:
RUNNER_NAME: ${RUNNER_NAME}
WORK_DIR: ${WORK_DIR}
LABELS: ${LABELS}
REUSE_EXISTING: true
container_name: github-runner-linux
working_dir: /home/docker
18 changes: 13 additions & 5 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RUNNER_NAME="${RUNNER_NAME:-"$(instance_id)"}"
RUNNER_GROUP="${RUNNER_GROUP:-"default"}"
WORK_DIR="${WORK_DIR:-"_work"}"
LABELS="${LABELS:-"docker-node,$os_name-$architecture"}"
REUSE_EXISTING="${REUSE_EXISTING:-"false"}"

repo_level_runner() {
# https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository
Expand Down Expand Up @@ -61,12 +62,19 @@ org_level_runner() {
--url "https://github.com/${GIT_OWNER}"
}

if [ -n "${GIT_REPOSITORY}" ]; then
echo "Creating a repository level self-hosted runner ['${RUNNER_NAME}'] for ${GIT_REPOSITORY}"
repo_level_runner
if [[ "$REUSE_EXISTING" == "true" || "$REUSE_EXISTING" == "1" ]] &&
[[ -d "/home/docker/actions-runner" ]] &&
[[ -f "/home/docker/actions-runner/config.sh" ]] &&
[[ -f "/home/docker/actions-runner/run.sh" ]]; then
echo "Existing configuration found. Re-using it..."
else
echo "Creating an organization level self-hosted runner '${RUNNER_NAME}'"
org_level_runner
if [[ -n "$GIT_REPOSITORY" ]]; then
echo "Creating a repository level self-hosted runner ['${RUNNER_NAME}'] for ${GIT_REPOSITORY}"
repo_level_runner
else
echo "Creating an organization level self-hosted runner '${RUNNER_NAME}'"
org_level_runner
fi
fi

cleanup() {
Expand Down

0 comments on commit caaa3a1

Please sign in to comment.