Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
feat: Dynamic root directory to workaround clashing docker labels (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
lholota authored Jun 6, 2023
1 parent 98b4a5e commit e890301
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 11 additions & 4 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e890301

Please sign in to comment.