silly-queen-7197
04/18/2026, 3:26 AMsilly-queen-7197
04/18/2026, 3:56 AMsilly-queen-7197
04/18/2026, 4:06 AMhappy-kitchen-89482
04/18/2026, 8:32 PMwide-midnight-78598
04/19/2026, 12:07 AMsilly-queen-7197
04/19/2026, 3:18 AMsilly-queen-7197
04/19/2026, 3:19 AMwide-midnight-78598
04/19/2026, 3:32 AMcache-to fields?silly-queen-7197
04/19/2026, 3:44 AM"""Plugin to add extra_cache_to field to docker_image targets.
Pants models cache_to as a single dict (DictStringToStringField), but BuildKit
supports multiple --cache-to flags (since v0.11 / Buildx v0.10 / Docker 24.0,
moby/buildkit#3024). This plugin registers an additional list-of-dict field that
produces extra --cache-to flags, discovered automatically by get_build_options()
via the DockerBuildOptionFieldListOfMultiValueDictMixin inheritance.
"""
from pants.backend.docker.target_types import (
DockerBuildKitOptionField,
DockerBuildOptionFieldListOfMultiValueDictMixin,
DockerImageTarget,
)
from pants.engine.target import ListOfDictStringToStringField
class DockerImageExtraCacheToField(
DockerBuildOptionFieldListOfMultiValueDictMixin,
ListOfDictStringToStringField,
DockerBuildKitOptionField,
):
alias = "extra_cache_to"
docker_build_option = "--cache-to"
default = ()
help = "Additional --cache-to destinations for docker buildx build."
def rules():
return [
DockerImageTarget.register_plugin_field(DockerImageExtraCacheToField),
]
I feel like I should have been able to write that.wide-midnight-78598
04/19/2026, 3:48 AMbillions-sundown-65740
04/20/2026, 8:53 AMARG keyword in Dockerfiles) but not the options of the build itself (it is basically the --build-arg option). This pull request https://github.com/pantsbuild/pants/pull/23250 should hopefully allow you to do the things you want to do by allowing you to pass generic build options to docker/podman. In future, we should drop the weird hardcoded options in the docker_image target and only allow the generic build_extra_options field.silly-queen-7197
04/20/2026, 4:30 PM