def get_or_build_image(self, name: str, tag: str, dockerfile: Union[str, Callable[..., str]], *,<EOL>pull=True, build_context: Optional[Path]=None):
if self.image_exists(name, tag):<EOL><INDENT>logger.info("<STR_LIT>", name, tag)<EOL>return<EOL><DEDENT>elif pull:<EOL><INDENT>logger.info("<STR_LIT>", name, tag)<EOL>try:<EOL><INDENT>self.client.images.pull(name, tag=tag)<EOL>logger.info("<STR_LIT>", name, tag)<EOL>return<EOL><DEDENT>except docker.errors.APIError:<EOL><INDENT>logger.info("<STR_LIT>", name, tag)<EOL><DEDENT><DEDENT>if callable(dockerfile):<EOL><INDENT>dockerfile = dockerfile()<EOL><DEDENT>try:<EOL><INDENT>if build_context is None:<EOL><INDENT>fileobj = BytesIO(bytes(dockerfile, "<STR_LIT:utf-8>"))  <EOL>self.client.images.build(<EOL>fileobj=fileobj,<EOL>tag=f"<STR_LIT>"<EOL>)<EOL><DEDENT>else:<EOL><INDENT>dockerfile_file = build_context / "<STR_LIT>"<EOL>dockerfile_file.write_text(dockerfile)<EOL>self.client.images.build(<EOL>path=str(build_context.resolve()),<EOL>dockerfile=dockerfile_file.name,<EOL>tag=f"<STR_LIT>"<EOL>)<EOL>dockerfile_file.unlink()<EOL><DEDENT><DEDENT>except docker.errors.BuildError as e:<EOL><INDENT>for line in e.build_log:<EOL><INDENT>if isinstance(line, dict) and line.get("<STR_LIT>") and line["<STR_LIT>"].get("<STR_LIT:code>") in {<NUM_LIT>, <NUM_LIT>}:<EOL><INDENT>raise BuildTimeoutError(f"<STR_LIT>"<EOL>f"<STR_LIT>")<EOL><DEDENT><DEDENT>logger.exception(e)<EOL>raise BuildError("<STR_LIT>", extra_info={<EOL>"<STR_LIT>": e.build_log<EOL>})<EOL><DEDENT>
A proxy for commonly built images, returns them from the local system if they exist, tries to pull them if
pull isn't disabled, otherwise builds them by the definition in ``dockerfile``.

:param name: Name of the image
:param tag: Image tag
:param dockerfile: Dockerfile text or a callable (no arguments) that produces Dockerfile text
:param pull: If the image is not present locally, allow pulling from registry (default is ``True``)
:param build_context: A path to a folder. If it's provided, docker will build the image in the context
    of this folder. (eg. if ``ADD`` is needed)