Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
BuildKit Rust Client
A full-featured Rust client library and CLI for interacting with moby/buildkit to build container images via gRPC.
Features • Installation • Quick Start • Usage • Documentation • Contributing
Features
- ✅ Complete gRPC Implementation - Direct integration with BuildKit's gRPC API
- 🏗️ Multiple Build Sources - Support for local Dockerfiles and GitHub repositories
- 🔐 Authentication Support - GitHub private repositories and Docker Registry authentication
- 🚀 Advanced Build Options - Build args, target stages, multi-platform builds
- 📊 Real-time Progress - Live build progress and log streaming
- 💾 Cache Management - Support for cache import/export
- 🎯 Registry Push - Automatic push of built images to registries
- 🔄 Session Protocol - Full implementation of BuildKit's bidirectional session protocol
- 🌐 HTTP/2 Tunneling - HTTP/2-over-gRPC for file synchronization
Prerequisites
- Rust 1.70+
- Docker or BuildKit daemon
- Git (for fetching proto files)
Installation
As a Library
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
= "1.0"
As a CLI Tool
Quick Start
0. Initialize Proto Files
First-time setup requires fetching protobuf definitions:
For detailed instructions, see docs/PROTO_SETUP.md
1. Start BuildKit and Registry
This starts:
- BuildKit daemon (port 1234)
- Local Docker Registry (port 5000)
2. Build the Project
3. Run Examples
Health Check
Build Local Dockerfile
Using Build Arguments
Specify Target Stage
Multi-platform Build
Build from GitHub Repository
# Public repository
# Private repository (with environment variable)
Build with Registry Authentication
JSON Output Mode
Usage
Basic Example
use ;
use ConsoleProgressHandler;
async
GitHub Repository Build
use ;
async
Multi-platform Build
use ;
async
Project Structure
buildkit-client/
├── src/
│ ├── main.rs # CLI tool entry point
│ ├── lib.rs # Library entry point
│ ├── client.rs # BuildKit gRPC client
│ ├── builder.rs # Build configuration
│ ├── solve.rs # Build execution logic
│ ├── progress.rs # Progress handling
│ ├── session/ # Session protocol implementation
│ │ ├── mod.rs # Session lifecycle & metadata
│ │ ├── grpc_tunnel.rs # HTTP/2-over-gRPC tunnel
│ │ ├── filesync.rs # File synchronization
│ │ └── auth.rs # Registry authentication
│ └── proto.rs # Protobuf generated code
├── proto/ # BuildKit protobuf definitions
├── examples/ # Sample Dockerfiles
├── tests/ # Comprehensive test suite
├── docker-compose.yml # Test environment setup
└── README.md
BuildKit gRPC API
This project directly uses BuildKit's gRPC API:
Control.Solve- Execute build operationsControl.Status- Stream build status updatesControl.Info- Get BuildKit informationControl.Session- Bidirectional session stream
All protobuf definitions are fetched from the moby/buildkit repository.
Configuration Options
BuildConfig
source- Build source (local or GitHub)dockerfile_path- Path to Dockerfilebuild_args- Build argumentstarget- Target stageplatforms- List of target platformstags- List of image tagsregistry_auth- Registry authentication infocache_from- Cache import sourcescache_to- Cache export destinationssecrets- Build-time secretsno_cache- Disable cachingpull- Always pull base images
ProgressHandler
Three progress handlers are provided:
- ConsoleProgressHandler - Output to console with colors
- JsonProgressHandler - JSON format output
- SilentProgressHandler - Silent mode
Environment Variables
BUILDKIT_ADDR- BuildKit address (default:http://localhost:1234)GITHUB_TOKEN- GitHub authentication tokenRUST_LOG- Log level (trace, debug, info, warn, error)RUST_LOG=info,buildkit_client::session::grpc_tunnel=tracefor protocol debugging
Documentation
- Quick Start Guide - Get up and running quickly
- Proto Setup - Proto file management
- Testing Guide - Complete testing documentation (unit, integration, GitHub builds)
- Development Guide - Architecture and development guide
Troubleshooting
BuildKit Connection Failed
# Check if BuildKit is running
# View BuildKit logs
# Restart services
Registry Push Failed
Ensure the registry allows insecure connections (for localhost):
# docker-compose.yml
services:
buildkitd:
environment:
- BUILDKIT_REGISTRY_INSECURE=true
Proto Compilation Errors
If you encounter protobuf compilation errors:
# Clean proto files and reinitialize
# Or manually
# Clean and rebuild
Development
Using Makefile
The project provides a Makefile to simplify common operations:
Testing
# Unit tests
# Integration tests (requires BuildKit)
# All tests
# GitHub repository tests
GITHUB_TOKEN=your_token
Update Protobuf Definitions
Proto files are automatically managed via scripts:
# Method 1: Using Makefile
# Method 2: Manual execution
# Rebuild
Code Formatting
Benchmarks
Architecture Highlights
Session Protocol
Implements BuildKit's complete session protocol with:
- Bidirectional gRPC streaming
- HTTP/2-over-gRPC tunneling for callbacks
- File synchronization (DiffCopy protocol)
- Registry authentication
HTTP/2 Tunnel
The HTTP/2-over-gRPC tunnel (src/session/grpc_tunnel.rs) is the most complex component:
- Runs a complete gRPC server inside a gRPC stream
- Routes incoming calls to appropriate handlers
- Implements proper gRPC message framing
DiffCopy Protocol
Bidirectional file synchronization protocol:
- Server sends STAT packets (file metadata)
- Client sends REQ packets (file requests)
- Server sends DATA packets (file contents)
- Both send FIN when complete
For detailed architecture documentation, see CLAUDE.md.
License
This project is dual-licensed under MIT OR Apache-2.0.
Acknowledgments
- moby/buildkit - BuildKit project
- tonic - Rust gRPC library
- prost - Protocol Buffers implementation
- h2 - HTTP/2 implementation
Contributing
Contributions are welcome! Please feel free to submit Issues and Pull Requests.
Before submitting a PR:
- Run
cargo fmtandcargo clippy - Ensure all tests pass:
cargo test - Add tests for new features
- Update documentation as needed
Related Links
Made with ❤️ by AprilNEA