BuildContext
Recipe-facing handle for config fields, exported as context.
Usage
BuildContext()Read a registered field as an attribute: context.gpu returns the validated value during a render pass, and None during discovery. Declare fields with register.
Example
from docker_dsl import context as ctx ctx.register(“gpu”, bool) base = “nvidia/cuda:12.4.0-base” if ctx.gpu else “ubuntu:24.04”
Methods
| Name | Description |
|---|---|
| register() | Declare a required config field. |
register()
Declare a required config field.
Usage
register(name, type_)Call this in the recipe body, once per field the recipe accepts. It takes effect only during the discovery pass; on the render pass it is a no-op, so the schema is fixed by what the import declared. pydantic validates the field’s value against type_ before rendering.
Parameters
name: str-
Field name, passed to Dockerfile.render and exposed as
context.<name>. type_: type- The field’s type, used to validate the supplied value.