From 4f2d51374962c5402f81a30a673d7aa2d751e8ec Mon Sep 17 00:00:00 2001 From: Chad Crouch Date: Wed, 1 Jan 2025 11:31:30 +0200 Subject: [PATCH] fix - adjust docker permissions --- Dockerfile | 10 +++++----- dockerd-entrypoint.sh | 15 +++++++++++++++ entrypoint.sh | 14 +++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 dockerd-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index e141273..3aa6f6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,19 +46,19 @@ RUN useradd -m -s /bin/bash runner && \ echo "runner ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers # Create the docker group and add the runner user -RUN getent group docker || groupadd -g 999 docker && \ +RUN getent group docker || groupadd -g 988 docker && \ usermod -aG docker runner RUN chown -R runner:runner /runner +# Copy scripts +COPY dockerd-entrypoint.sh /usr/local/bin/dockerd-entrypoint.sh +RUN chmod +x /usr/local/bin/dockerd-entrypoint.sh + COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh USER runner WORKDIR /runner -# Start Docker daemon in the container -RUN mkdir -p /home/runner/.docker && chmod -R 0700 /home/runner/.docker -CMD ["dockerd-entrypoint.sh"] - ENTRYPOINT ["/entrypoint.sh"] diff --git a/dockerd-entrypoint.sh b/dockerd-entrypoint.sh new file mode 100644 index 0000000..9ec1f2d --- /dev/null +++ b/dockerd-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +# If the first argument is `dockerd`, run the Docker daemon +if [ "$1" = "dockerd" ]; then + # Create necessary directories + mkdir -p /var/lib/docker + mkdir -p /etc/docker + + # Start the Docker daemon + exec "$@" --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 +fi + +# If the command is not `dockerd`, execute it +exec "$@" diff --git a/entrypoint.sh b/entrypoint.sh index 371f9a3..18406df 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,11 +7,6 @@ if [ -z "$GITHUB_URL" ] || [ -z "$RUNNER_TOKEN" ]; then exit 1 fi -# sudo groupadd -g 121 runner -# sudo useradd -mr -d /home/runner -u 1001 -g 121 runner -# sudo usermod -aG sudo runner -# sudo usermod -aG docker runner - # Configure the GitHub Actions runner if [ ! -f .runner ]; then ./config.sh --url "${GITHUB_URL}" --token "${RUNNER_TOKEN}" --name "${RUNNER_NAME}" --unattended --replace @@ -22,5 +17,14 @@ RUNNER_NAME=${RUNNER_NAME:-"default-runner"} # Trap SIGTERM and SIGINT to allow for cleanup trap './config.sh remove --unattended && exit 0' SIGTERM SIGINT +# Start the Docker daemon +/usr/local/bin/dockerd-entrypoint.sh & + +# Wait for Docker daemon to start +while ! docker info > /dev/null 2>&1; do + echo "Waiting for Docker daemon to start..." + sleep 1 +done + # Start the runner ./run.sh