...
- Kubernetes cluster is intended to be just for build system.
- Can use local machine or nodes in the kubernetes cluster to create docker images (Don't need access to s3df/afs filesystem if all modules/dependencies are uploaded to GitHub, as they should be)
- Docker can be ran on local machine, but not on s3df, it is intended to use apptainer instead, if build enviornment wants to be passed around. So when this build system is finished, developers/users won't use docker directly, instead will use apptainer and pull docker images from artifact storage (if needed)
Current status
- We have a self-hosted runner image built: pnispero/gh-runner-image - Docker Image | Docker Hub (Temporary location)
- Can use that image to deploy to kubernetes cluster
- TODO: create formal instructions from below on how to deploy the image
- This is good for now, don't need to dynamically scale since the runner(s) takes minimal resources while idle (Waiting for a request)
Current Tasks
- Get the build system container running on the kluster , see if you can use the actions/actions-runner-controller: Kubernetes controller for GitHub Actions self-hosted runners Deploying Self-Hosted GitHub Actions Runners with Docker | TestDriven.io (Altered to fit our situation)
- Lets do it vanilla first (running build system container)
- Create the image using base image: Package actions-runner (github.com)
- push the docker image to a registry so anyone can pull it
- From where the dockerfile is
- 'docker build --tag pnispero/gh-runner-image:latest .'
- This step may change (make a docker account, then create a access token, which will allow you to login on your shell)
- 'docker push pnispero/gh-runner-image:latest'
- Output: pnispero/gh-runner-image - Docker Image | Docker Hub
Dockerfile (Here temporarily, these are the only 2 files you need to get this to work)
Code Block |
---|
# base
FROM ubuntu:22.04
# set the github runner version
ARG RUNNER_VERSION="2.316.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"] |
start.sh
Code Block |
---|
#!/bin/bash
ORGANIZATION=$ORGANIZATION
ACCESS_TOKEN=$ACCESS_TOKEN
# Generate organization registration token
REG_TOKEN=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
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 $! |
- do 'docker image ls' to ensure its there
- Then you must be an organization administrator, and make a personal access token with the "admin:org" and "repo" scope to create a registration token for an organization (REST API endpoints for self-hosted runners - GitHub Docs)
- Copy the token, and use it in the next step
Run the docker image
Code Block |
---|
docker run \
--env ORGANIZATION=<ORG> \
--env ACCESS_TOKEN=<PERSONAL-TOKEN> \
--name runner1 \
runner-image |
Replace <ORG> with the organization name
Replace <PERSONAL-TOKEN> with the token you created above
- And now your runner should be registered and running
- When done testing make sure to 'ctrl+c' and 'stop' and 'remove' the container
- Start the image using kubectl for our ad-build kubernetes cluster you created above
Code Block |
---|
# Start the image with environment variables
kubectl run gh-runner1 --image=pnispero/gh-runner-image --env="ORGANIZATION=<ORG>" --env="ACCESS_TOKEN=<PERSONAL-TOKEN>" |
Replace <ORG> with the organization name
Replace <PERSONAL-TOKEN> with the token you created above
- Then we can use that for building buildroot. One of the workflows will be it checking out on /scratch/ in s3df, then build, and output results there.
Resource (Slightly altered its files): How to containerize a GitHub Actions self-hosted runner | by Alessandro Baccini | Medium
Deployment of an image (running container) ex: Using kubectl to Create a Deployment | Kubernetes
...