stale-waitress-56895
03/11/2025, 11:26 AMcache_to and cache_from without having to specify them manually? I find lots of chats but nothing conclusive?wide-midnight-78598
03/11/2025, 12:50 PMstale-waitress-56895
03/11/2025, 1:38 PMdocker_image, I need to manually fill in these values, and I haven't found a way to parametrize them
docker_image(
name="dev",
source="Dockerfile.dev",
cache_from=[
{
"type": "registry",
"ref": "europe-docker.pkg.dev/xxxxx/infra/base-images/images/coder/dev:cache-{{build_args.DOCKER_TAG_BRANCH}}",
},
{
"type": "registry",
"ref": "europe-docker.pkg.dev/xxxxx/infra/base-images/images/coder/dev:main",
},
],
cache_to={
"type": "registry",
"ref": "europe-docker.pkg.dev/xxxxx/infra/base-images/images/coder/dev:cache-{{build_args.DOCKER_TAG_BRANCH}},mode=max",
},
)stale-waitress-56895
03/11/2025, 1:39 PM__defaults__(
dict(
docker_image=dict(
source="Dockerfile",
build_platform=["linux/amd64"],
secrets={"gcp": env("GOOGLE_APPLICATION_CREDENTIALS")},
image_tags=[
"{pants.hash}",
"{build_args.DOCKER_TAG_BRANCH}",
"{build_args.DOCKER_TAG_BRANCH_COMMIT}",
"{build_args.DOCKER_TAG_COMMIT}",
],
)
)
)
and I wish I could do the same with cache_from and cache_towide-midnight-78598
03/11/2025, 1:43 PMstale-waitress-56895
03/11/2025, 1:44 PMstale-waitress-56895
03/11/2025, 1:45 PMrepository = "xxxxx/xxxxx{full_directory}/{name}"
and I don't think you get these interpolations in the macrostale-waitress-56895
03/11/2025, 1:45 PMwide-midnight-78598
03/11/2025, 1:46 PMwide-midnight-78598
03/11/2025, 1:47 PMstale-waitress-56895
03/11/2025, 1:48 PMstale-waitress-56895
03/11/2025, 1:48 PMsquare-psychiatrist-19087
03/11/2025, 4:25 PMdef my_image(name: str, ...):
docker_image(
name=name,
cache_to=f"repo/{build_file_dir()}/{name}"
...
)better-library-16357
03/11/2025, 4:27 PMstale-waitress-56895
03/11/2025, 5:08 PM# helpers/pants-plugins/macros/docker_image.py
original_docker_image = docker_image
def docker_image(**kwargs):
cache_tag = "cache-{build_args.DOCKER_TAG_BRANCH}"
name = kwargs["name"]
repository = f"xxxxxxxx/{build_file_dir()}/{name}"
cache_from=[
{
"type": "registry",
"ref": repository + ":cache-{{build_args.DOCKER_TAG_BRANCH}}",
},
{
"type": "registry",
"ref": repository + ":main",
},
]
cache_to={
"type": "registry",
"ref": repository + ":cache-{{build_args.DOCKER_TAG_BRANCH}},mode=max",
}
kwargs.setdefault("cache_from", cache_from)
kwargs.setdefault("cache_to", cache_to)
original_docker_image(**kwargs)
and in pants.toml
build_file_prelude_globs = [
"helpers/pants-plugins/macros/docker_image.py"
]stale-waitress-56895
03/11/2025, 5:08 PMsquare-psychiatrist-19087
03/11/2025, 5:38 PM