This guide explains how to set up an ephemeral Buildkite agent in an Orka by MacStadium environment.
The ephemeral agent is used to run a single Buildkite job in a Buildkite pipeline.
The agent is created before the job execution and deleted once the job completes.
This is achieved by overwriting the Buildkite agent bootstrap command of the registered agent.
This way we create a proxy agent that instead of executing the Buildkite job locally, spins up an Orka VM and delegates the job to that VM.
- Set up an Orka VM base image. The image must have SSH enabled and contain an installed Buildkite agent.
- Set up an Orka VM config using the base image from Step 1. The Orka VM config is the container template that the proxy agent will use to spin up the ephemeral agent.
- Set up the proxy agent.
The Orka VM used as an ephemeral agent needs to have the Buildkite agent installed locally. This is needed to allow the delegation of Buildkite jobs from the proxy agent.
If your Orka environment does not provide a base image pre-configured with a Buildkite agent, you need to create one yourself.
You will later use this base image to create a VM config (a container template) for the ephemeral agent.
- Set up a new Orka VM. You can set up an Orka VM using the Orka CLI or REST API. For more information, see the Orka quick start guide.
- Connect to the Orka VM using VNC.
Note: The VM IP and VNC ports are displayed once the VM is deployed in Orka. - Verify that Homebrew is installed on the VM. To install Homebrew, see here.
- Install the Buildkite agent on the VM by running:
brew tap buildkite/buildkite brew install buildkite-agent
- Verify that SSH login with a private key is enabled. SSH login is used by the proxy agent to communicate with the ephemeral agent.
- On your local machine, run
orka image save
. The command saves the base image in Orka.
To allow the proxy agent to spin up ephemeral agents in Orka, create an Orka VM config (a container template) that uses the Buildkite-enabled base image you just created.
You can create an Orka VM config using the Orka CLI or REST API. For more information, see the Orka quick start guide.
The recommended way to set up a proxy agent is to use the provided Dockerfile.
On the machine where you want to run the proxy agent container:
- Navigate to the Dockerfile directory.
- Build a Docker image by running
docker build . -t orka-buildkite
. Note: By default the Dockerfile uses the latest Buildkite docker image. If you want to specify another version, use theBASE_VERSION
build argument:docker build . -t orka-buildkite --build-args BASE_VERSION=3
. - Run a container using the docker image you built and pass your Buildkite token as a variable.
Verify that the private SSH key for connecting to the ephemeral agent is mounted in the
buildkite-secrets
folder on the container. This key was created earlier during the Orka base image setup.
Verify that the private SSH keys for the code repositories used by the build job are mounted in thebuildkite-secrets
folder on the container.
The above is done by runningdocker run -v {folder-containing-all-ssh-keys}:/buildkite-secrets -e BUILDKITE_AGENT_TOKEN="{your-token}" orka-buildkite
. - Verify that the container has network visibility to the Orka environment. If the machine, running the container, is part of the Orka environment, skip this step. You can use any VPN client to connect to the Orka environment. For more information, see your Orka IP Plan.
Note If you want to set up the proxy agent manually, see here.
The provided scripts expect the following environment variables to be set:
ORKA_TOKEN
- The authentication token to use.ORKA_ENDPOINT
- The Orka endpoint. Usually, it ishttp://10.221.188.20
ORKA_CONFIG_NAME
- The name of the VM config to be deployed. This should match the VM config created earlierORKA_VM_NAME_PREFIX
- The prefix used to generate the runner VM's name. Defaults tobuildkite-agent
.ORKA_VM_USER
- User used to SSH to the VM. Defaults toadmin
.
For more information about the advanced settings you can use, see here.
Once the setup of the Buildkite agent is finished, you can run your CI/CD pipelines in Orka.
The communication between an ephemeral Buildkite agent and the Buildkite server is instantiated from the agent.
This means your Orka environment must have visibility to the Buildkite server.
Visibility from the Buildkite server to the Orka environment is not required.
The Orka environment is behind a firewall.
This means your proxy agent must have visibility to the Orka environment. You can use any VPN client to connect to the Orka environment. For more information, see your Orka IP Plan.
The ephemeral agent accepts the following optional environment variables:
BUILDKITE_AGENT_ACCESS_TOKEN_SUBAGENT
BUILDKITE_BUILD_PATH_SUBAGENT
BUILDKITE_HOOKS_PATH_SUBAGENT
BUILDKITE_PLUGINS_PATH_SUBAGENT
BUILDKITE_PLUGINS_ENABLED_SUBAGENT
BUILDKITE_PLUGINS_ENABLED_SUBAGENT
BUILDKITE_PLUGIN_VALIDATION_SUBAGENT
BUILDKITE_LOCAL_HOOKS_ENABLED_SUBAGENT
BUILDKITE_SSH_KEYSCAN_SUBAGENT
BUILDKITE_AGENT_DEBUG_SUBAGENT
All of the above override the respective Buildkite environment variables without the _SUBAGENT
suffix.
For example: BUILDKITE_AGENT_ACCESS_TOKEN_SUBAGENT
overwrites BUILDKITE_AGENT_ACCESS_TOKEN
.
For more information about Buildkite environment variables, see here.