Build System
Container image building for customer deployments
The build system supports two deployment paths: GitHub-triggered builds and CLI deployments with pre-built images.
GitHub-Triggered Builds
When a customer pushes to a GitHub repository connected to their Unkey project, the following process occurs:
GitHub sends a webhook to the control plane, which validates the signature and maps the repository to an Unkey project. The control plane creates a deployment record and triggers the deploy workflow.
The deploy workflow uses BuildKit's native git context support to build directly from GitHub. BuildKit fetches the repository at the specified commit SHA, authenticated via a GitHub App installation token. This eliminates the need for intermediate storage (S3) and provides efficient builds with automatic layer caching through Depot.
Depot provisions an isolated BuildKit machine, fetches the repository directly from GitHub, executes the Docker build, and pushes the resulting image to its registry. The image name is returned to the control plane.
With the built image ready, the control plane creates deployment topologies for target regions. Krane agents pull these changes and create the necessary Kubernetes resources. The control plane polls for instance readiness, registers instances in the database, and finally assigns domains via the routing service.
CLI Deployments (Pre-built Images)
For CLI deployments, customers provide pre-built Docker images directly. This bypasses the build system entirely:
Build Backend: Depot
Depot.dev provides isolated, cached, and high-performance container builds:
- Fast builds: Persistent layer caching across builds
- Isolated environments: Each customer project gets its own cache
- No local Docker daemon: Builds run on remote BuildKit machines
- Multi-architecture support: Build for both amd64 and arm64
- Native git context: BuildKit fetches repositories directly from GitHub
- Built-in registry: Images pushed directly to Depot's registry
Location: svc/ctrl/worker/deploy/build.go
GitHub Authentication
For private repositories, BuildKit authenticates using GitHub App installation tokens:
- The control plane creates a JWT signed with the GitHub App's private key
- Exchanges the JWT for an installation token via GitHub API
- Passes the token to BuildKit via the
GIT_AUTH_TOKEN.github.comsecret - BuildKit uses the token for HTTPS authentication when fetching the repository
Installation tokens are short-lived (~1 hour) and scoped to repositories where the GitHub App is installed.
Location: svc/ctrl/worker/github/client.go
Depot Project Management
Each Unkey project gets a corresponding Depot project for caching: