From c5214cffed9091603db9b1ff031ba58d332bc3f9 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Tue, 12 May 2020 15:27:08 +1000 Subject: [PATCH] add runner and manifests --- github/actions/self-hosted-runner/dockerfile | 40 +++++++++++++++++++ .../actions/self-hosted-runner/entrypoint.sh | 25 ++++++++++++ .../self-hosted-runner/kubernetes.yaml | 37 +++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 github/actions/self-hosted-runner/dockerfile create mode 100644 github/actions/self-hosted-runner/entrypoint.sh create mode 100644 github/actions/self-hosted-runner/kubernetes.yaml diff --git a/github/actions/self-hosted-runner/dockerfile b/github/actions/self-hosted-runner/dockerfile new file mode 100644 index 000000000..f8c8d0b16 --- /dev/null +++ b/github/actions/self-hosted-runner/dockerfile @@ -0,0 +1,40 @@ +FROM debian:buster + +ARG RUNNER_VERSION="2.169.1" + +ENV GITHUB_PERSONAL_TOKEN "" +ENV GITHUB_OWNER "" +ENV GITHUB_REPOSITORY "" + +RUN apt-get update \ + && apt-get install -y \ + curl \ + sudo \ + git \ + jq \ + tar \ + gnupg2 \ + apt-transport-https \ + ca-certificates \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN useradd -m github && \ + usermod -aG sudo github && \ + echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +#setup docker runner +RUN curl -sSL https://get.docker.com/ | sh +RUN usermod -aG docker github + +USER github +WORKDIR /home/github + +RUN curl -O -L https://github.com/actions/runner/releases/download/v$RUNNER_VERSION/actions-runner-linux-x64-$RUNNER_VERSION.tar.gz +RUN tar xzf ./actions-runner-linux-x64-$RUNNER_VERSION.tar.gz +RUN sudo ./bin/installdependencies.sh + +COPY --chown=github:github entrypoint.sh ./entrypoint.sh +RUN sudo chmod u+x ./entrypoint.sh + +ENTRYPOINT ["/home/github/entrypoint.sh"] \ No newline at end of file diff --git a/github/actions/self-hosted-runner/entrypoint.sh b/github/actions/self-hosted-runner/entrypoint.sh new file mode 100644 index 000000000..ba24b57d0 --- /dev/null +++ b/github/actions/self-hosted-runner/entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/sh +registration_url="https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPOSITORY}/actions/runners/registration-token" +echo "Requesting registration URL at '${registration_url}'" + +payload=$(curl -sX POST -H "Authorization: token ${GITHUB_PAT}" ${registration_url}) +export RUNNER_TOKEN=$(echo $payload | jq .token --raw-output) + +./config.sh \ + --name $(hostname) \ + --token ${RUNNER_TOKEN} \ + --url https://github.com/${GITHUB_OWNER}/${GITHUB_REPOSITORY} \ + --work ${RUNNER_WORKDIR} \ + --unattended \ + --replace + +remove() { + ./config.sh remove --unattended --token "${RUNNER_TOKEN}" +} + +trap 'remove; exit 130' INT +trap 'remove; exit 143' TERM + +./run.sh "$*" & + +wait $! \ No newline at end of file diff --git a/github/actions/self-hosted-runner/kubernetes.yaml b/github/actions/self-hosted-runner/kubernetes.yaml new file mode 100644 index 000000000..673b354d3 --- /dev/null +++ b/github/actions/self-hosted-runner/kubernetes.yaml @@ -0,0 +1,37 @@ +apiVersion: v1 +kind: Secret +metadata: + name: github-secret +type: Opaque +data: + GITHUB_PERSONAL_TOKEN: XXXXXXXXXXXXXXXXXXXXXXXXX +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: github-runner + labels: + app: github-runner +spec: + replicas: 1 + selector: + matchLabels: + app: github-runner + template: + metadata: + labels: + app: github-runner + spec: + containers: + - name: github-runner + image: aimvector/github-runner:latest + env: + - name: GITHUB_OWNER + value: marcel-dempers + - name: GITHUB_REPOSITORY + value: docker-development-youtube-series + - name: GITHUB_PERSONAL_TOKEN + valueFrom: + secretKeyRef: + name: github-secret + key: GITHUB_PERSONAL_TOKEN \ No newline at end of file