You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 36
Next »
Page about kubernetes clusters ad-build and ad-build-dev
Runs on hardware in s3df
Allocatable:
cpu: 64
ephemeral-storage: 152933498761
hugepages-1Gi: 0
hugepages-2Mi: 2816Mi
memory: 259679512Ki
pods: 220
System Info:
Machine ID: 92faa81e90af4e65ba73d3007e42519e
System UUID: ce9ba000-5727-11ed-8000-3cecefd8e38e
Boot ID: 96386228-b4ab-4836-b764-b22d4dfc0cda
Kernel Version: 4.18.0-372.32.1.el8_6.x86_64
OS Image: Red Hat Enterprise Linux 8.6 (Ootpa)
Operating System: linux
Architecture: amd64
Container Runtime Version: containerd://1.6.31
Kubelet Version: v1.28.8
Kube-Proxy Version: v1.28.8
- ad-build-dev is used for build system development, while ad-build is the production build system for users.
How to access
ad-build-dev cluster: https://k8s.slac.stanford.edu/ad-build-dev
ad-build cluster: https://k8s.slac.stanford.edu/ad-build
- After following the commands in those links, you will need to request access to the cluster from Claudio.
- Recommended to install k9s tool https://k9scli.io/topics/install/
Other Notes
- 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
- TODO: Create a yaml that'll create the runner containers (with options to create multiple), and deletes with a grace period.
- 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
- work on cli - refer to CLI Tool
- while wait for claudio tomorrow to figure out build backend orchestration
- Figure out what we need to pass in from the runner to the backend to start the build container
- Possible things we need to start the build container
- repo name
- organization
- branch
- user
- filepath to where the repo is checked out
- Think about where we are going to store the builds, where the build container is doing the builds, we may want to seperate by user like /sdf/group/ad/user1/component_name/branch
- Then we also want to think about where to keep the 'scripts' for building somewhere on s3df, so we don't have to bake the scripts into the images.
- Possible scripts we need (this can be one or multiple scripts):
- script to start the make or buildInstructions and enter the right filepath
- script to log what part of the build system workflow are we in (Used for build system developers to debug failed builds due to build system)
- Create a deployment file for the build containers (may be minimal)
- Create a simple hello world project,
- DONE Add to Jira - we can use this as the test project, upload it to github, add it to the component db
- try this with the mongodb for us to view - https://www.mongodb.com/products/tools/compass
- create a basic build environment with a 'build.sh' script copied over. Push this image, and add its url to hello world component. This build environment can be used by both developers and the build system.
- DONE - use the basic.yml workflow from the BuildSystem/ (which will be the workflow all 400 something repos under ad will have)
- See we can move the workflow to BuildSystem repo and all other repos can call it from there, like 'actions/checkout' can do like 'adbuild/build' this way any updates we roll out any repo can easily receive it
- the workflow should eventually do a GET request to the db, to get the build environment image,
- then spin up that new build environment image, 3 options to get the actual repo itself onto the new image
- (ideal) Runner does an actions/checkout onto a certain directory on s3df which will be accessible to all pods
- Runner does an actions/checkout and passes in the actual repo through a 'kubectl cp',
- or probably pass in the url to the repo which it can then clone - issue with git authorization
- Then signal to the new environment container to do a 'make', then we have 3 options
- Have the environment container copy over a 'build.sh' script which does not get invoked when the container is spun up, but when it is explicitly called with 'kubectl exec'
- when you do 'kubectl exec' it can wait until the make is finished, then report back to actions that the build finished
- it can signal the make, but report back to actions that the build continued at a certain container.
- CAVEATS: we can assume that if there are no additional instructions on the component entry in the db, then we just do a vanilla make. (Which is what most apps here do to build, at least for the iocs its true)
- Then we also want the simple project packed up as a package (src code and executable).
- Make sure we get the build output available to users, either to github actions, or point them to the container output (we may make a cli command for it?)
- Figure out the authentication automation for the runners. (at the moment i get the blob of config from https://k8s.slac.stanford.edu/ad-build-dev: new solution: we are going to have only a couple 'orchestrator' containers that will do the kubectl commands, so only those need to be authenticated)
- Eventually we will need the runner have access to s3df, so we can build on /scratch. Then check kaniko?
- Try to get a dockerfile for buildroot going, most of the building will be in the dockerfile (copying over files, then running make), then the gh workflow will just call docker build and start the process, and can push the image anywhere (Local registry, docker registry, github registry)
- Get the build system container running on the kluster 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)
# 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
#!/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
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
# 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
REMEMBER IF STOPPING THE CONTAINER, give it a grace period so it has some time to remove itself and from the organization
kubectl delete --grace-period=15 pod gh-runner1
Sample request - but refer to the api docs (https://accel-webapp-dev.slac.stanford.edu/api-doc/?urls.primaryName=Core%20Build%20System)
# gets component list
curl -X 'GET' \
'https://accel-webapp-dev.slac.stanford.edu/api/cbs/v1/component' \
-H 'accept: application/json'
- 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.
Other Basic
Deployment of an image (running container) ex: Using kubectl to Create a Deployment | Kubernetes
pnispero@PC100942:~$ kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
deployment.apps/kubernetes-bootcamp created
pnispero@PC100942:~$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
kubernetes-bootcamp 1/1 1 1 6s
pnispero@PC100942:~$ kubectl delete deployment kubernetes-bootcamp
deployment.apps "kubernetes-bootcamp" deleted
pnispero@PC100942:~$ kubectl get deployments
No resources found in default namespace.
pnispero@PC100942:~$