https://pantsbuild.org/ logo
#general
Title
# general
t

thousands-plumber-33255

07/07/2022, 1:51 PM
Is there any way to add some kind of template for the
instructions
field of
docker_image
and then reuse it for multiple applications? E.g.
Copy code
instructions=[
    "FROM python:${VARIANT}"
    "COPY ${DYNAMIC_DIR} /app",
  ]
Background: the Dockerfile for a lot of services looks almost the same.
b

bitter-ability-32190

07/07/2022, 2:00 PM
c

curved-television-6568

07/07/2022, 2:00 PM
b

bitter-ability-32190

07/07/2022, 2:01 PM
Although, personally, macros aren't my favorite for some things because they ar eopt-in which means devs have to know to use them.
__defaults__
is another angle. Also if the targets are in the same
BUILD
, remember
BUILD
files are just Python(-ish)
โœ… 1
c

curved-television-6568

07/07/2022, 2:02 PM
Itโ€™s Python, not ish, just that theyโ€™re sandboxed that makes them a bit like ish. ๐Ÿ˜‰
b

bitter-ability-32190

07/07/2022, 2:03 PM
Using a template is great, though. John showed me https://pex.readthedocs.io/en/latest/recipes.html?highlight=container#pex-app-in-a-container which speeds up container startup. Fixed all of our containers with one change
๐Ÿ’ฏ 1
Python the language, not Python-the-full-runtime
c

curved-television-6568

07/07/2022, 2:03 PM
Oh, the distinction ๐Ÿ™ˆ
๐Ÿ˜‚ 1
t

thousands-plumber-33255

07/08/2022, 6:26 AM
Okay, so for the macro I can see from the docs that "A macro can take new parameters to generate the target dynamically", which should work in that case. But I am not getting how the
__defaults__
feature can be utilized here. Can you give an example?
@bitter-ability-32190 Could you provide some boilerplate code from your template macro?
b

bitter-ability-32190

07/08/2022, 10:37 AM
So using a macro would be completely separate from using the defaults target. When I'm on my desktop I can whip up an example
Copy code
def my_docker_image(...):
    return docker_image(
        instructions=[
            "...",
            f"{foobar}",
...
๐Ÿ‘€ 1
c

curved-television-6568

07/08/2022, 12:16 PM
I am not getting how the
__defaults__
feature can be utilized here. Can you give an example?
Ah, I somehow overlooked the dynamic nature of the default template you asked for @thousands-plumber-33255. So
__defaults__
would not be a fit for that case.
3 Views