config.yaml is the declarative surface for everything your model bundles, builds, and pulls. Use it to include custom Python packages, run shell commands during the build, swap in a custom Docker base image, and authenticate to private registries.
Python packages
Truss lets you include custom modules or third-party packages not available on PyPI using two methods:- The
packagesdirectory: for bundling small, Truss-specific packages. - The
external_package_dirsconfiguration: for sharing packages across multiple Trusses.
Use the packages directory
Each Truss includes a packages/ directory where you place Python modules to include at build time. Use this method for lightweight, Truss-specific packages.
Example directory structure:
Project structure
model.py:
model.py
Use external_package_dirs
If multiple Trusses need access to the same external package, define external_package_dirs in config.yaml. A package here refers to an importable directory with Python source code.
Example directory structure:
Project structure
external_package_dirs in config.yaml:
config.yaml
model.py:
model.py
Build commands
Thebuild_commands feature runs 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.
Run build commands in config.yaml
Add build_commands to your config.yaml:
config.yaml
Create directories
Usebuild_commands to create directories directly in the container. This is useful for large codebases requiring additional structure.
config.yaml
Cache model weights efficiently
For smaller weights, usewget in build_commands:
config.yaml
Run any shell command
build_commands runs any shell command at build time and caches the result, so it doesn’t re-run on every cold start.
Base images
Use a custom base image when you need specific system packages or a different runtime than the default Truss image provides.Set a base image in config.yaml
Specify a custom base image in config.yaml:
config.yaml
image: the Docker image to use.python_executable_path: the path to the Python binary inside the container.
NVIDIA NeMo model
Use a custom image to deploy the NVIDIA NeMo TitaNet model:config.yaml
Use private base images
If your base image is private, configure your model to use a private registry.Create a custom base image
Build a new base image using Truss’s base images as a foundation. Available images are listed on Docker Hub.Customize a Truss base image
Dockerfile
Build and push your custom image
Ensure Docker is installed and running. Then build, tag, and push your image:Terminal
Private registries
When deploying a custom base image or custom server from a private registry, grant Baseten access to pull the image.AWS Elastic Container Registry (ECR)
AWS supports three authentication methods: OIDC (recommended), IAM service accounts, and access tokens.AWS OIDC (Recommended)
OIDC provides short-lived, narrowly scoped tokens for secure authentication without managing long-lived credentials.- Configure AWS to trust the Baseten OIDC provider and create an IAM role with ECR permissions.
-
Add the OIDC configuration to your
config.yaml:
config.yaml
No secrets needed. The
aws_oidc_role_arn and aws_oidc_region are not sensitive and can be committed to your repository.AWS IAM service accounts
To use an IAM service account for long-lived access, use theAWS_IAM authentication method in Truss.
-
Get an
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYfrom the AWS dashboard. -
Add these as secrets in Baseten. Name them
aws_access_key_idandaws_secret_access_key. -
Configure
docker_authin yourconfig.yaml:
config.yaml
registry value must match the hostname portion of the image URL.
To use different secret names, configure the aws_access_key_id_secret_name and aws_secret_access_key_secret_name options under docker_auth:
config.yaml
Access token
- Get the Base64-encoded secret:
Terminal
-
Add a new secret to Baseten named
DOCKER_REGISTRY_<aws-account-id>.dkr.ecr.<region>.amazonaws.comwith the Base64-encoded secret as the value. -
Add the secret name to the
secretssection ofconfig.yaml:
config.yaml
Google Cloud Artifact Registry
GCP supports three authentication methods: OIDC (recommended), service accounts, and access tokens.All three methods also work with Google Container Registry (
gcr.io, <region>.gcr.io).GCP OIDC (Recommended)
OIDC provides short-lived, narrowly scoped tokens for secure authentication without managing long-lived credentials.- Configure GCP Workload Identity to trust the Baseten OIDC provider and grant Artifact Registry permissions.
-
Add the OIDC configuration to your
config.yaml:
config.yaml
No secrets needed. The service account and workload identity provider are not sensitive and can be committed to your repository.
Service account
- Get your service account key as a JSON key blob.
-
Add a new secret to Baseten named
gcp-service-account(or similar) with the JSON key blob as the value. -
Add the secret name to the
secretssection ofconfig.yaml:
config.yaml
- Configure the
docker_authsection of yourbase_imageto use service account authentication:
config.yaml
secret_name must match the secret you created in step 2.
Access token
- Get your access token.
-
Add a new secret to Baseten named
DOCKER_REGISTRY_<region>-docker.pkg.devwith the Base64-encoded secret as the value. -
Add the secret name to the
secretssection ofconfig.yaml:
config.yaml
Docker Hub
- Get the Base64-encoded secret:
Terminal
- Add a new secret to Baseten named
DOCKER_REGISTRY_https://index.docker.io/v1/with the Base64-encoded secret as the value.
- Add the secret name to the
secretssection ofconfig.yaml:
config.yaml
GitHub Container Registry (GHCR)
-
Create a GitHub Personal Access Token with the
read:packagesscope. Use a classic token, not fine-grained. - Get the Base64-encoded secret:
Terminal
- Add a new secret to Baseten named
DOCKER_REGISTRY_ghcr.iowith the Base64-encoded secret as the value.
- Add the secret name to the
secretssection ofconfig.yaml:
config.yaml
NVIDIA NGC
- Generate an NGC API Key from your NVIDIA NGC account.
- Get the Base64-encoded secret:
Terminal
The username
$oauthtoken is a literal string, not a variable. Use it exactly as shown.- Add a new secret to Baseten named
DOCKER_REGISTRY_nvcr.iowith the Base64-encoded secret as the value.
- Add the secret name to the
secretssection ofconfig.yaml:
config.yaml
Next steps
Configuration
The full set of
config.yaml options for packages, resources, and the build environment.Secrets
Store and reference API keys and registry credentials securely.
Custom servers
Run your own server image instead of the default Truss server.
Private registry access
Set up OIDC for short-lived, credential-free registry authentication.