Move template rendering to separate method

This commit is contained in:
Mikhail Gordeev 2023-02-03 01:59:31 +03:00
parent 88f75c091b
commit 9bd9973c34

View File

@ -116,6 +116,23 @@ class DockerBuilder:
if kwargs["dockerfile"].exists(): if kwargs["dockerfile"].exists():
kwargs["dockerfile"].unlink() kwargs["dockerfile"].unlink()
def render_template(self, template: str, branch: str, install_pakages=None) -> str:
if self.registry:
registry = self.registry.rstrip("/") + "/"
alt_image = "alt/alt"
else:
registry = ""
alt_image = "alt"
rendered = Template(template).render(
alt_image=alt_image,
branch=branch,
install_pakages=install_pakages,
organization=self.organization,
registry=registry,
)
return rendered
@forall_images(consume_result=True) @forall_images(consume_result=True)
def render_dockerfiles(self, branch, **kwargs): def render_dockerfiles(self, branch, **kwargs):
def install_pakages(*names): def install_pakages(*names):
@ -139,19 +156,10 @@ class DockerBuilder:
install_command = textwrap.indent(install_command, " " * 4) install_command = textwrap.indent(install_command, " " * 4)
return update_command + install_command return update_command + install_command
if kwargs["dockerfile_template"].exists(): dockerfile_template = kwargs["dockerfile_template"]
if self.registry: if dockerfile_template.exists():
registry = self.registry.rstrip("/") + "/" rendered = self.render_template(
alt_image = "alt/alt" dockerfile_template.read_text(), branch, install_pakages
else:
registry = ""
alt_image = "alt"
rendered = Template(kwargs["dockerfile_template"].read_text()).render(
alt_image=alt_image,
branch=branch,
install_pakages=install_pakages,
organization=self.organization,
registry=registry,
) )
kwargs["dockerfile"].write_text(rendered + "\n") kwargs["dockerfile"].write_text(rendered + "\n")