From d92561f7452f2949f4e344da58e4b8be4291ccc0 Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Sat, 27 May 2023 16:31:37 +0200 Subject: [PATCH] Added a first draft of a github runner --- runner/.gitignore | 1 + runner/Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ runner/docker-compose.yaml | 14 ++++++++++++++ runner/start.sh | 20 ++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 runner/.gitignore create mode 100644 runner/Dockerfile create mode 100644 runner/docker-compose.yaml create mode 100644 runner/start.sh diff --git a/runner/.gitignore b/runner/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/runner/.gitignore @@ -0,0 +1 @@ +.env diff --git a/runner/Dockerfile b/runner/Dockerfile new file mode 100644 index 0000000..bd6f3b8 --- /dev/null +++ b/runner/Dockerfile @@ -0,0 +1,36 @@ +# base +FROM ubuntu:latest + +# set the github runner version +ARG RUNNER_VERSION="2.304.0" +ARG ARCHITECTURE=arm + +# update the base packages and add a non-sudo user +RUN apt-get update -y && apt-get upgrade -y && useradd -m docker + +# install python and the packages the your code depends on along with jq so we can parse JSON +# add additional packages as necessary +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + curl jq build-essential libssl-dev libffi-dev python3 python3-venv python3-dev python3-pip nano vim + +# cd into the user directory, download and unzip the github actions runner +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-${ARCHITECTURE}-${RUNNER_VERSION}.tar.gz \ + && tar xzf ./actions-runner-linux-${ARCHITECTURE}-${RUNNER_VERSION}.tar.gz \ + && rm *.tar.gz + +# install some additional dependencies +RUN chown -R docker ~docker && /home/docker/actions-runner/bin/installdependencies.sh + +# copy over the start.sh script +COPY 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 + +# set the entrypoint to the start.sh script +CMD ["./start.sh"] diff --git a/runner/docker-compose.yaml b/runner/docker-compose.yaml new file mode 100644 index 0000000..8a7c4ff --- /dev/null +++ b/runner/docker-compose.yaml @@ -0,0 +1,14 @@ +version: '3' +services: + runner: + build: + context: . + dockerfile: Dockerfile + args: + - ARCHITECTURE=${ARCHITECTURE} + environment: + - ORGANIZATION=${ORGANIZATION} + - ACCESS_TOKEN=${ACCESS_TOKEN} + - TZ=DE + hostname: ${HOSTNAME} + restart: unless-stopped diff --git a/runner/start.sh b/runner/start.sh new file mode 100644 index 0000000..368646b --- /dev/null +++ b/runner/start.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +ORGANIZATION=$ORGANIZATION +ACCESS_TOKEN=$ACCESS_TOKEN + +REG_TOKEN=$(curl -sX POST -H "Authorization: token ${ACCESS_TOKEN}" https://api.github.com/orgs/${ORGANIZATION}/actions/runners/registration-token | jq .token --raw-output) + +cd /home/docker/actions-runner + +./config.sh --url https://github.com/${ORGANIZATION} --token ${ACCESS_TOKEN} + +cleanup() { + echo "Removing runner..." + ./config.sh remove --unattended --token ${ACCESS_TOKEN} +} + +trap 'cleanup; exit 130' INT +trap 'cleanup; exit 143' TERM + +./run.sh & wait $!