Skip to content

Dockerized self hosted runner on Ubuntu

Shivam Mathur edited this page May 13, 2020 · 8 revisions

Dockerfile

You can use this Dockerfile to setup a self hosted runner for GitHub Actions on ubuntu.

FROM shivammathur/node:bionic-slim
# ubuntu:bionic and ubuntu:xenial would also work
# shivammathur/node:bionic-slim is optimised for setup-php

ARG RUNNER_VERSION=ver
ARG RUNNER_URL=https://github.com/foo/bar
ARG RUNNER_TOKEN=tkn

RUN set -ex && apt-get update && apt-get install -y ca-certificates curl sudo --no-install-recommends

RUN adduser --disabled-password --gecos '' runner \
  && usermod -aG sudo runner \
  && mkdir -m 777 -p /home/runner \
  && sed -i 's/%sudo\s.*/%sudo ALL=(ALL:ALL) NOPASSWD : ALL/g' /etc/sudoers

USER runner
WORKDIR /home/runner

RUN sudo curl -o runner.tar.gz -sSL https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
  && sudo tar xf runner.tar.gz \
  && sudo bash ./bin/installdependencies.sh

CMD [ "bash", "-c", "./config.sh --url ${RUNNER_URL} --token ${RUNNER_TOKEN}; ./run.sh; sleep infinity"]

Build

Place the above Dockerfile in a directory and build an image. In the runner installation instructions you can find the RUNNER_VERSION from the curl command. Replace the values in the command below before executing.

docker build -t linuxselfhosted:0.1 --build-arg RUNNER_VERSION=1.2.3 .

Run

In the runner installation instructions you can find the RUNNER_URL and RUNNER_TOKEN from the config command. Replace the values in the command below before executing.

docker run -it -e RUNNER_URL=https://github.com/foo/bar -e RUNNER_TOKEN=ABCDEFGHIJKLNMOPQRSTUVWXYZABC linuxselfhosted:0.1