From e890301b118bb1bb8e1d173b330a79001baaaff2 Mon Sep 17 00:00:00 2001 From: LH Date: Tue, 6 Jun 2023 11:13:13 +0200 Subject: [PATCH] feat: Dynamic root directory to workaround clashing docker labels (#13) --- Dockerfile | 3 +++ docker-compose.yml | 5 +++-- start.sh | 15 +++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index af4b036..aae28de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,9 @@ RUN apt-get update && \ chown -R github-runner /var/lib/github-runner && \ /var/lib/github-runner/bin/installdependencies.sh && \ chmod a+x /var/lib/github-runner/start.sh && \ + # Create directory for runner root dirs + mkdir /var/lib/github-runner-instance && \ + chown -R github-runner /var/lib/github-runner-instance && \ # Install Docker CLI apt-get install -y --no-install-recommends \ ca-certificates=20210119 \ diff --git a/docker-compose.yml b/docker-compose.yml index f2e24c4..1b14148 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,13 @@ version: "3.7" services: github-runner: build: . - image: homecentr/github-runner + image: homecentr/github-runner:local restart: unless-stopped environment: GH_OWNER: homecentr GH_TOKEN: ${GH_TOKEN} RUNNER_NAME: "Test runner" - RUNNER_DIR: "/var/lib/github-runner/runner1" volumes: - /var/run/docker.sock:/var/run/docker.sock + extra_hosts: + - "host.docker.internal:host-gateway" diff --git a/start.sh b/start.sh index 96689a7..4a74fa8 100644 --- a/start.sh +++ b/start.sh @@ -3,19 +3,26 @@ GH_OWNER=$GH_OWNER GH_TOKEN=$GH_TOKEN -CONTAINER_ID=$(head -1 /proc/self/cgroup | cut -d/ -f3 | cut -c1-5) -RUNNER_NAME="$RUNNER_NAME-$CONTAINER_ID" +export CONTAINER_ID=$(head -1 /proc/self/cgroup | cut -d/ -f3 | cut -c1-5) +export RUNNER_NAME="${RUNNER_NAME}-${CONTAINER_ID}" + +echo "Container ID: $CONTAINER_ID" + +# Create a root directory symlink to get a different Docker instance id hash +ROOT_DIR="/var/lib/github-runner-instance/$CONTAINER_ID" +ln -s "$PWD" "$ROOT_DIR" +cd "$ROOT_DIR" echo "Connecting to GitHub org: $GH_OWNER" echo "Runner name: $RUNNER_NAME" REG_TOKEN=$(curl -sX POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${GH_TOKEN}" https://api.github.com/orgs/${GH_OWNER}/actions/runners/registration-token | jq .token --raw-output) -./config.sh --unattended --url https://github.com/${GH_OWNER} --token ${REG_TOKEN} --name ${RUNNER_NAME} +./config.sh --unattended --url "https://github.com/${GH_OWNER}" --token "${REG_TOKEN}" --name "${RUNNER_NAME}" cleanup() { echo "Removing runner..." - ./config.sh remove --unattended --token ${REG_TOKEN} + ./config.sh remove --unattended --token "${REG_TOKEN}" } trap 'cleanup; exit 130' INT