commit 6720a5945182aa304727c47672b0c08ad1f8c951 Author: Alejandro Lembke Barrientos Date: Wed Nov 8 22:31:37 2023 +0000 First Commit for Adding Docker GitHub Action Runner. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..36edef5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# base +FROM ubuntu:22.04 + +# set the github runner version +ARG RUNNER_VERSION="2.311.0" + +# 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 + +# 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-x64-${RUNNER_VERSION}.tar.gz \ + && tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.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 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 +ENTRYPOINT ["./start.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ae648d8 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Docker Github Action Runner + +## Version 1.0.0 \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..7bbed02 --- /dev/null +++ b/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 ${REG_TOKEN} + +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