From 6d0430e5edd0a8419ad9c1576c1d3c7992cbb4fb Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sat, 3 May 2025 21:31:42 +0100 Subject: [PATCH] Add Dockerfile and start script for GitHub Actions runner setup --- .github/runner/Dockerfile | 30 ++++++++++++++++++++++++++++++ .github/runner/start.sh | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/runner/Dockerfile create mode 100644 .github/runner/start.sh diff --git a/.github/runner/Dockerfile b/.github/runner/Dockerfile new file mode 100644 index 0000000..fecddb5 --- /dev/null +++ b/.github/runner/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:latest + +ARG RUNNER_VERSION="2.323.0" + +# Prevents installdependencies.sh from prompting the user and blocking the image creation +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt update -y && apt upgrade -y && useradd -m docker +RUN apt install -y --no-install-recommends \ + curl jq build-essential libssl-dev libffi-dev python3 python3-venv python3-dev python3-pip \ + # dot net core dependencies + libicu74 libssl3 libkrb5-3 zlib1g libcurl4 + + +RUN cd /home/docker && mkdir actions-runner && cd actions-runner \ + && curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \ + && tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz + +RUN chown -R docker ~docker && /home/docker/actions-runner/bin/installdependencies.sh + +COPY start.sh start.sh + +# make the script executable +RUN chmod +x start.sh + +# since the config and run script for actions are not allowed to be run by root, +# set the user to "docker" so all subsequent commands are run as the docker user +USER docker + +ENTRYPOINT ["./start.sh"] \ No newline at end of file diff --git a/.github/runner/start.sh b/.github/runner/start.sh new file mode 100644 index 0000000..97e8609 --- /dev/null +++ b/.github/runner/start.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +REPOSITORY=$REPO +ACCESS_TOKEN=$GH_TOKEN +LABELS=$RUNNER_LABELS + +# echo "REPO ${REPOSITORY}" +# echo "ACCESS_TOKEN ${ACCESS_TOKEN}" + +REG_TOKEN=$(curl -X POST -H "Authorization: token ${ACCESS_TOKEN}" -H "Accept: application/vnd.github+json" https://api.github.com/repos/${REPOSITORY}/actions/runners/registration-token | jq .token --raw-output) + +cd /home/docker/actions-runner + +./config.sh --url https://github.com/${REPOSITORY} --token ${REG_TOKEN} --labels ${LABELS} + +cleanup() { + echo "Removing runner..." + ./config.sh remove --unattended --token ${REG_TOKEN} +} + +trap 'cleanup; exit 130' INT +trap 'cleanup; exit 143' TERM + +./run.sh & wait $! \ No newline at end of file