tcardonne / docker-github-runner

Run GitHub Actions on self-hosted runner using Docker.
MIT License
297 stars 124 forks source link

[Feature] Use container name as runner name #48

Open tdamsma opened 3 years ago

tdamsma commented 3 years ago

When setting up a bunch of runners with docker-compose up --scale runner=10 is is not possible (as far as I know) to give each container a unique value for the RUNNER)NAME, so i the runners each have a unique container name, and it would be great if that could be used as the runner name.

The workarounds i saw are

tdamsma commented 3 years ago

... and looking into the entrpoint this isalready exactly how it works

if [[ -z $RUNNER_NAME ]]; then
    echo "RUNNER_NAME environment variable is not set, using '${HOSTNAME}'."
    export RUNNER_NAME=${HOSTNAME}
fi
tdamsma commented 3 years ago

I thought the hostname ws the container name but it is not. The container name can be retreived with $(docker inspect -f "{{ .Name }}" ${HOSTNAME} | cut -c 2-). I changed the entrypoint.sh for my uses with:

if [[ -z $RUNNER_NAME ]]; then
    export RUNNER_NAME=$(docker inspect -f "{{ .Name }}" ${HOSTNAME} | cut -c 2-)
    echo "RUNNER_NAME environment variable is not set, using '${RUNNER_NAME}' derived from the container name."
fi

This allows me to use docker-compose up --scale runner=10 and get predictable runner names, so that if I recreate the docker-compose environment I get the same runner names.

beeb commented 1 year ago

this is supported with this (actively maintained) image: https://github.com/myoung34/docker-github-actions-runner