Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Updated for arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
djthorpe committed Oct 6, 2021
1 parent f9d813a commit e7c2697
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 49 deletions.
43 changes: 39 additions & 4 deletions .github/workflows/build-arm.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Release
on:
release:
types: [ created ]
types: [ created, edited ]
jobs:
build-arm:
runs-on: [self-hosted,linux,arm]
runs-on: [self-hosted, linux, arm]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set tags
id: tags
run: |
echo ::set-output name=arch::arm
echo ::set-output name=runner::2.283.3
echo ::set-output name=image::ghcr.io/${{ github.repository_owner }}/runner-image-arm
echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}
- name: Login
Expand All @@ -24,9 +26,42 @@ jobs:
docker build \
--tag ${{ steps.tags.outputs.image }}:latest \
--tag ${{ steps.tags.outputs.image }}:${{ steps.tags.outputs.tag }} \
--build-arg RUNNER_VERSION=${{ steps.tags.outputs.runner }} \
--build-arg RUNNER_ARCH=${{ steps.tags.outputs.arch }} \
--file Dockerfile \
.
- name: Push
run: |
docker push --all-tags ${{ steps.tags.outputs.image }}
docker push ${{ steps.tags.outputs.image }}:latest
docker push ${{ steps.tags.outputs.image }}:${{ steps.tags.outputs.tag }}
build-arm64:
runs-on: [self-hosted, linux, arm64]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set tags
id: tags
run: |
echo ::set-output name=arch::arm
echo ::set-output name=runner::2.283.3
echo ::set-output name=image::ghcr.io/${{ github.repository_owner }}/runner-image-arm
echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}
- name: Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: |
docker build \
--tag ${{ steps.tags.outputs.image }}:latest \
--tag ${{ steps.tags.outputs.image }}:${{ steps.tags.outputs.tag }} \
--build-arg RUNNER_VERSION=${{ steps.tags.outputs.runner }} \
--build-arg RUNNER_ARCH=${{ steps.tags.outputs.arch }} \
--file Dockerfile \
.
- name: Push
run: |
docker push ${{ steps.tags.outputs.image }}:latest
docker push ${{ steps.tags.outputs.image }}:${{ steps.tags.outputs.tag }}
19 changes: 8 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# base
FROM ubuntu:20.04

# set the github runner version
ARG RUNNER_VERSION="2.283.1"
ARG RUNNER_ARCH="arm"
ARG RUNNER_ARCH
ARG RUNNER_VERSION

# update the base packages and add a non-sudo user
ENV DEBIAN_FRONTEND="noninteractive" TZ="Europe/Berlin"
Expand All @@ -27,24 +26,22 @@ RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | g
# Note we use the bionic version of docker as it's not available for focal
# https://github.com/docker/for-linux/issues/1035
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
&& echo "deb [arch=armhf signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu bionic stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu bionic stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
&& apt-get update -y && apt-get install -y docker-ce docker-ce-cli containerd.io

# install pkg-config libsqlite3-dev libmosquitto-dev
RUN apt-get update -y && apt-get install -y pkg-config libsqlite3-dev libmosquitto-dev
# install pkg-config libmosquitto-dev
RUN apt-get update -y && apt-get install -y pkg-config libmosquitto-dev

# 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-${RUNNER_ARCH}-${RUNNER_VERSION}.tar.gz \
&& tar xzf ./actions-runner-linux-${RUNNER_ARCH}-${RUNNER_VERSION}.tar.gz
&& curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-$RUNNER_ARCH-$RUNNER_VERSION.tar.gz \
&& tar xzf ./actions-runner-linux-$RUNNER_ARCH-$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 over the start.sh script, make it executable
COPY start.sh start.sh

# make the script executable
RUN chmod +x start.sh

# set the entrypoint to the start.sh script
Expand Down
76 changes: 44 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,91 @@
# docker-action-runner

This repository contains code to create a docker image for a github action runner,
and instructions for using it. The most useful guide I found was [here](https://testdriven.io/blog/github-actions-docker/) and this repository is based on that.
and instructions for using it. The most useful guide I found was
[here](https://testdriven.io/blog/github-actions-docker/) and this repository is based on that.

I am targetting ARM 32-bit (armhf) here as the environment for the runner, my use case is
to be able to run GitHub Actions on ARM (which are not supported by default). The environment that is
built:
I am targetting ARM 32-bit (armhf) and 64-bit (arm64), my use case is
to be able to run GitHub Actions on ARM (which are not supported by default).
The environment that is built into docker images is:

* Architecture armhf (32-bit)
* Architecture armhf (32-bit) and arm64
* Ubuntu 20.04
* Github Action Runner 2.283.1
* Additional packages `git`, `gh`, `docker-compose`, `pkg-config`, `libsqlite3-dev` and `libmosquitto-dev`
* Github Action Runner 2.283.3
* Additional packages `git`, `gh`, `docker-compose`, `pkg-config` and `libmosquitto-dev`

## Setup

In order to create the image the first time, you'll need to install docker, as per
[this guide](https://docs.docker.com/engine/install/ubuntu/). Then download the repository
and build the image, assuming you are on ARM:
and build the image, assuming you are on `arm64`. The ARCH value of `arm` is also possible
if you are on ARM 32-bit:

```bash
[bash] git clone [email protected]:mutablelogic/docker-action-runner.git
[bash] cd docker-action-runner
[bash] docker build --tag runner-image-arm .
[bash] docker image ls runner-image-arm
[bash] ARCH=arm64; docker build --tag runner-image-${ARCH} --build-arg RUNNER_VERSION="2.283.3" --build-arg RUNNER_ARCH="${ARCH}" .
```

Re-tag the image for uploading to docker (or whatever other registry service you're using)
and push to that registry:
and push to that registry once you know it's worked:

```bash
[bash] ORGANIZATION="mutablelogic"
[bash] REGISTRY="ghcr.io/${ORGANIZATION}"
[bash] VERSION=`git describe --tags`
[bash] ARCH="arm64" ORGANIZATION="mutablelogic" REGISTRY="ghcr.io/${ORGANIZATION}" IMAGE="runner-image-${ARCH}" VERSION=`git describe --tags`
[bash] echo "Push: ${REGISTRY}/${IMAGE}:${VERSION#v}"
[bash] docker login "${REGISTRY}"
[bash] docker tag runner-image-arm "${REGISTRY}/runner-image-arm:${VERSION#v}"
[bash] docker push "${REGISTRY}/runner-image-arm:${VERSION#v}"
[bash] docker tag runner-image-arm "${REGISTRY}/runner-image-arm:latest"
[bash] docker push "${REGISTRY}/runner-image-arm:latest"
[bash] docker image rm runner-image-arm:latest
[bash] docker tag "${IMAGE}" "${REGISTRY}/${IMAGE}:${VERSION#v}" && docker tag "${IMAGE}" "${REGISTRY}/${IMAGE}:latest"
[bash] docker push "${REGISTRY}/${IMAGE}:${VERSION#v}" && docker push "${REGISTRY}/${IMAGE}" && docker image rm "${IMAGE}"
```

At this point you would have your images in the registry ready for use. If you receive an error and you're
on a Raspberry Pi, then I also made the following changes:
At this point you would have your images in the registry ready for use. I also made the following changes:

* I added `cgroup_enable=memory` to the file `/boot/cmdline.txt` and rebooted, so that nomad (see below)
can use the memory cgroups support. You need to reboot the Raspberry Pi to make the changes take effect;
* I downloaded and installed `libseccomp2_2.5.1-1_armhf.deb` from [here](http://ftp.us.debian.org/debian/pool/main/libs/libseccomp/libseccomp2_2.5.1-1_armhf.deb) which fixed an issue with building the container on ARM.

## Creating a manifest

If you have a number of images with different architectures you want to combine, use `docker manifest`. For example,

```bash
[bash] ORGANIZATION="mutablelogic" REGISTRY="ghcr.io/${ORGANIZATION}" MANIFEST="runner-image" VERSION=`git describe --tags`
[bash] docker pull "${REGISTRY}/${MANIFEST}-arm:${VERSION#v}" && docker pull "${REGISTRY}/${MANIFEST}-arm64:${VERSION#v}"
[bash] docker manifest create "${REGISTRY}/${MANIFEST}:${VERSION#v}" \
--amend "${REGISTRY}/${MANIFEST}-arm:${VERSION#v}" \
--amend "${REGISTRY}/${MANIFEST}-arm64:${VERSION#v}"
[bash] echo "Push: ${REGISTRY}/${MANIFEST}:${VERSION#v}"
[bash] docker push "${REGISTRY}/${MANIFEST}:${VERSION#v}"
```

## Running the runner

You then have a choice of running directly with docker or using an orchestration tool like [Nomad](https://www.nomadproject.io/). The environment variables you need to set in order to manage the runner environment are:
You then have a choice of running directly with docker or using an orchestration tool like [Nomad](https://www.nomadproject.io/).
The environment variables you need to set in order to manage the runner environment are:

* `ORGANIZATION`: Where you're storing the runner image in the registry and the organization attached to the runner;
* `ACCESS_TOKEN`: Create a personal access token in GitHub [here](https://github.com/settings/tokens). The token should have `admin:org` permissions.
* `NAME`: The name of the runner, which is used to identify it GitHub;
* `LABELS`: Comma-separated labels for the runner. Generally `self-hosted, linux, arm`;
* `NAME`: The name of the runner, which is used to identify it on GitHub (optional);
* `LABELS`: Comma-separated labels for the runner (optional). Generally `self-hosted, linux, arm` or similar;
* `GROUP`: The runner group. Set to 'Default' if not otherwise set.

### Docker

You then need to create a runner action process, which will run the image
and attach to GitHub Actions. Create a personal access token in GitHub [here](https://github.com/settings/tokens). The token should have `admin:org` permissions. The token should be set as an environment variable `ACCESS_TOKEN`.
If you're using Docker to create a runner action process, create a personal access token in GitHub [here](https://github.com/settings/tokens).
The token should have `admin:org` permissions. The token should be set as an environment variable `ACCESS_TOKEN`.

```bash
[bash] ORGANIZATION="mutablelogic"
[bash] REGISTRY="ghcr.io/${ORGANIZATION}"
[bash] ACCESS_TOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
[bash] docker run --detach \
[bash] ARCH="arm64" ORGANIZATION="mutablelogic" REGISTRY="ghcr.io/${ORGANIZATION}" ACCESS_TOKEN="XXXXXXX"
[bash] docker run --detach --name action-runner \
--env ORGANIZATION="${ORGANIZATION}" --env ACCESS_TOKEN="${ACCESS_TOKEN}" \
--env NAME="" --env LABELS="" --env GROUP="" \
--name action-runner "${REGISTRY}/runner-image-arm:latest"
"${REGISTRY}/runner-image-${ARCH}"
[bash] docker logs -f action-runner
```

(If you have a previously running container, you can remove it first with `docker stop action-runner && docker rm action-runner`).

When you see the line "Listening for Jobs" you can then scoot over to the GitHub Actions page to see that the runner is working. The page will be `https://github.com/organizations/${ORGANIZATION}/settings/actions/runners`
When you see the line "Listening for Jobs" you can then scoot over to the GitHub Actions page to see that the runner is working.
The page will be `https://github.com/organizations/${ORGANIZATION}/settings/actions/runners`

### Nomad

Expand Down Expand Up @@ -144,4 +154,6 @@ Here are some references I found useful:
* https://testdriven.io/blog/github-actions-docker/
* https://docs.docker.com/engine/install/ubuntu/
* https://github.com/myoung34/docker-github-actions-runner
* https://github.com/actions/runner/releases


3 changes: 1 addition & 2 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

if [ "${ORGANIZATION}" == "" ] ; then
echo "Please set the ORGANIZATION environment variable"
exit -1
Expand Down Expand Up @@ -29,7 +28,7 @@ cleanup() {
}

# Deregister runner on exit
trap cleanup SIGINT SIGQUIT SIGTERM INT TERM QUIT
trap 'kill ${!}; cleanup' SIGUSR1 SIGINT SIGQUIT SIGTERM SIGKILL

# Set the docker permissions
echo "Setting docker permissions..."
Expand Down

0 comments on commit e7c2697

Please sign in to comment.