fresh-continent-76371
02/10/2024, 12:42 PMpants.toml
IN the [docker] section, I have found the following variables available for the "repository" field build_args, default_repository, directory, name, pants, parent_directory, tags, target_repository
It does not seem that there is a "full_directory" variable available.
Context - I want to "auto" name the docker images - as some-registry.internal/xyz/path/to/name:1.2.3
where fictionally, registry address =some-registry.internal/xyz
path/to is the root path in the mono repo. to the BUILD file
and name is the default "name" in the docker_image(name=...)
like ..
[docker.registries.our-internal-registry]
address = "some-registry.internal/xyz"
default = true
# build_args, default_repository, directory, name, pants, parent_directory, tags, target_repository
repository = "{full_directory}/{name}"
of course full_directory does not exist as a variable.
I am aware of the repository parameter available in the docker_image(... repository="somevaluehere", )
but I was hoping I would have either in the BUILD file, or the pants.toml a variable for the full/path/to/build/ BUILD file
directory is == to the name of the BUILD file
parent_directory, as name suggests is one up.fresh-continent-76371
02/12/2024, 7:44 AMsome/path/to/tgt:my_docker_image) -> some/path/to/tgtbroad-processor-92400
02/12/2024, 9:09 AMbuild_file_dir() which returns a pathlib.Path that can be used in an f-string or similar. You’ll have to use a macro to set this automatically for every docker_image.
It seems reasonable to have a pants.toml level substitution for the full path to be able to set the default more easily. Do you want to open a feature request or maybe a pull request? (Happy to provide pointers.)fresh-continent-76371
02/12/2024, 9:14 AMfresh-continent-76371
02/12/2024, 9:15 AMpants.toml are the vars available both
• globally (across ALL sections)
• section contextual - in the case of docker default_repository is docker specificbroad-processor-92400
02/12/2024, 9:17 AMformat_repository in https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/docker/goals/package_image.pyfresh-continent-76371
02/12/2024, 9:17 AMBUILD file is using the new 2.19 parametrize() expansion.
Very nice.
#
# Python base containers with TLS internal CA certs
#
docker_image(
name="images-python",
registries=["@acme-library-registry"],
source="Dockerfile.python",
dependencies=["common/pki:acme_tls_internal_CA_certs"],
**parametrize("py310deb", repository="python", image_tags=["3.10-slim"], extra_build_args=["BASE_IMAGE=python:3.10-slim","DIST_TYPE=debian:12"]),
**parametrize("py311deb", repository="python", image_tags=["3.11-slim"], extra_build_args=["BASE_IMAGE=python:3.11-slim","DIST_TYPE=debian:12"]),
**parametrize("py312deb", repository="python", image_tags=["3.12-slim"], extra_build_args=["BASE_IMAGE=python:3.12-slim","DIST_TYPE=debian:12"]),
**parametrize("py310alpine", repository="python", image_tags=["3.10-alpine"], extra_build_args=["BASE_IMAGE=python:3.10-alpine", "DIST_TYPE=alpine:3"]),
**parametrize("py311alpine", repository="python", image_tags=["3.11-alpine"], extra_build_args=["BASE_IMAGE=python:3.11-alpine", "DIST_TYPE=alpine:3"]),
**parametrize("py312alpine", repository="python", image_tags=["3.12-alpine"], extra_build_args=["BASE_IMAGE=python:3.12-alpine", "DIST_TYPE=alpine:3"]),
)
#
# scratch based images
#
docker_image(
name="images-alpine-and-scratch",
registries=["@acme-library-registry"],
source="Dockerfile.scratch",
dependencies=["common/pki:acme_tls_internal_CA_certs"],
**parametrize("busybox", repository="busybox",image_tags=["1.36"], extra_build_args=["BASE_IMAGE=busybox:1.36"]),
**parametrize("prom_prometheus", repository="prom/prometheus", image_tags=["v2.49.1"], extra_build_args=["BASE_IMAGE=prom/prometheus:v2.49.1"]),
**parametrize("prom_node_exporter", repository="prom/node-exporter", image_tags=["v1.7.0"], extra_build_args=["BASE_IMAGE=prom/node-exporter:v1.7.0"]),
**parametrize("prom_alertmanager", repository="prom/alertmanager", image_tags=["v0.26.0"], extra_build_args=["BASE_IMAGE=prom/alertmanager:v0.26.0"]),
**parametrize("gcr_io_cadvisor_cadvisor", repository="<http://gcr.io/cadvisor/cadvisor|gcr.io/cadvisor/cadvisor>", image_tags=["v0.47.2"], extra_build_args=["BASE_IMAGE=<http://gcr.io/cadvisor/cadvisor:v0.47.2%22|gcr.io/cadvisor/cadvisor:v0.47.2">]),
**parametrize("grafana_grafana_enterprise", repository="grafana/grafana-enterprise", image_tags=["10.3.1"], extra_build_args=["BASE_IAGE=grafana/grafana-enterprise:10.3.1"]),
**parametrize("bitnami_minio", repository="bitnami/minio", image_tags=["2024.2.9"], extra_build_args=["BASE_IMAGE=bitnami/minio:2024.2.9"]),
)fresh-continent-76371
02/12/2024, 9:18 AMfresh-continent-76371
02/12/2024, 10:08 AMbroad-processor-92400
02/12/2024, 10:11 AMbuild_file_path mimicking the function?fresh-continent-76371
02/12/2024, 10:25 AMfresh-continent-76371
02/12/2024, 11:12 AM{
"name": "Python 3",
"image": "<http://mcr.microsoft.com/devcontainers/python:1-3.9-bookworm|mcr.microsoft.com/devcontainers/python:1-3.9-bookworm>",
"features": {
"<http://ghcr.io/devcontainers/features/rust:1|ghcr.io/devcontainers/features/rust:1>": {}
},
"postCreateCommand": "apt update && apt-get install -y protobuf-compiler; curl --proto '=https' --tlsv1.2 -fsSL <https://static.pantsbuild.org/setup/get-pants.sh> | bash; pants --version",
}
Not sure if this is wanted by anyone elsefresh-continent-76371
02/12/2024, 11:34 AMnutritious-hair-72580
02/13/2024, 2:29 AMdirectory is the name of the BUILD file - never used it, but from the docs:
The default placeholders are:
{directory}: The directory the docker_image's BUILD file is in.
Wondering if it's a bug.fresh-continent-76371
02/13/2024, 4:36 AMsome/path/to/parent/folder/BUILD
| |
| `---------- {directory} == "folder"
`----------------- {parent_directory} == "parent"
there is no access to "some/path/to"