Setup & Dependencies
Custom build commands
How to run your own docker commands during the build stage
The build_commands
feature allows you to run custom Docker commands during the build stage, enabling advanced caching, dependency management, and environment setup.
Use Cases:
- Clone GitHub repositories
- Install dependencies
- Create directories
- Pre-download model weights
1. Using Build Commands in config.yaml
Add build_commands
to your config.yaml
:
What happens?
- The GitHub repository is cloned.
- The specified commit is checked out.
- Dependencies are installed.
- Everything is cached at build time, reducing deployment cold starts.
2. Creating Directories in Your Truss
Use build_commands
to create directories directly in the container.
Useful for large codebases requiring additional structure.
3. Caching Model Weights Efficiently
For large weights (10GB+), use
model_cache
or external_data
.For smaller weights, use wget
in build_commands
:
Why use this?
- Reduces startup time by preloading model weights during the build stage.
- Ensures availability without runtime downloads.
4. Running Any Shell Command
The build_commands
feature lets you execute any shell command as if running it locally, with the benefit of caching the results at build time.
Key Benefits:
- Reduces cold starts by caching dependencies & data.
- Ensures reproducibility across deployments.
- Optimizes environment setup for fast execution.