stale-waitress-56895
03/26/2025, 4:58 PMstale-waitress-56895
03/26/2025, 4:58 PMdef image_flavor(**kwargs):
template = kwargs.pop("template", {})
template.update(kwargs)
docker_image(**template)
template=dict(
name="base",
source="Dockerfile",
dependencies = [
":resources",
":reqs"
],
)
image_flavor(template=template, name="python-311", extra_build_args={"PYTHON_VERSION=3.11"})
image_flavor(template=template, name="python-312", extra_build_args={"PYTHON_VERSION=3.12"})
image_flavor(template=template, name="python")
image_flavor(template=template, name="cuda-python-311", source="Dockerfile.cuda", extra_build_args={"PYTHON_VERSION=3.11"})
image_flavor(template=template, name="cuda-python-312", source="Dockerfile.cuda", extra_build_args={"PYTHON_VERSION=3.12"})
image_flavor(template=template, name="cuda-python", source="Dockerfile.cuda")stale-waitress-56895
03/26/2025, 4:59 PMelegant-florist-94385
03/26/2025, 7:58 PMdocker_image directly because you want to pre-bake in some of them (such as dependencies). is that correct?
You might consider something like:
def app1_docker_image(**kwargs):
# you could merge a template of defaults here
# instead of repeated `kwargs.get` below if you prefer
docker_image(
name=kwargs.get("name", "base"),
source=kwargs.get("source", "Dockerfile"),
dependencies = [
":resources",
":reqs",
],
)
then use it like:
app1_docker_image(source="Dockerfile.cuda")stale-waitress-56895
03/27/2025, 8:28 AMextra_build_args for both python (3.11, 3.12, 3.13) and cuda versions (for instance)
something that would make it readable, and simple to expand/add new parametersgorgeous-winter-99296
03/27/2025, 9:41 AMgorgeous-winter-99296
03/27/2025, 9:47 AMdocker_image=dict(
name="base",
source="Dockerfile",
dependencies = [
":resources",
":reqs"
],
**parametrize("python")
**parametrize("python-311", extra_build_args=["PYTHON_VERSION=3.11"]),
**parametrize("python-312", extra_build_args=["PYTHON_VERSION=3.12"]),
**parametrize("cuda-python", source="Dockerfile.cuda")
**parametrize("cuda-python-311", source="Dockerfile.cuda", extra_build_args=["PYTHON_VERSION=3.11"])
**parametrize("cuda-python-312", source="Dockerfile.cuda", extra_build_args=["PYTHON_VERSION=3.12"])
)
Could work. It does seem like doing an itertools.product equivalent macro to generate these parametrizations would be quite useful.stale-waitress-56895
03/27/2025, 9:56 AMextra_build_args=["PYTHON_VERSION=3.11", "PYTHON_VERSION=3.12"])
extra_build_args=["BASE_IMAGE=ubuntu", "BASE_IMAGE=cuda_base_image"])gorgeous-winter-99296
03/27/2025, 10:15 AMdef product(*iterables):
pools = [tuple(pool) for pool in iterables]
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
named_variants={f"{image}-{python}": [f"BASE_IMAGE={image}", "PYTHON={python}"] for image, python in product(["ubuntu", "cuda"], ["python3.10", "python3.11"])}
docker_image(
name="base",
source="Dockerfile",
dependencies = [
":resources",
":reqs"
],
extra_build_args=parametrize(**named_variants)
)stale-waitress-56895
03/27/2025, 10:18 AM