Is there any way to add some kind of template for ...
# general
t
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
c
b
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
Itโ€™s Python, not ish, just that theyโ€™re sandboxed that makes them a bit like ish. ๐Ÿ˜‰
b
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
Oh, the distinction ๐Ÿ™ˆ
๐Ÿ˜‚ 1
t
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
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
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.