docker-github-runner icon indicating copy to clipboard operation
docker-github-runner copied to clipboard

[Feature] Use container name as runner name

Open tdamsma opened this issue 2 years ago • 3 comments

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

  • leave the runner name empty and get a random name asigned
  • use copy/paste in the docker compose instead of the scale functionality

tdamsma avatar Jul 08 '21 18:07 tdamsma

... 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 avatar Jul 09 '21 07:07 tdamsma

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.

tdamsma avatar Jul 09 '21 10:07 tdamsma