Description
Proposed change
Currently the base template is defined as a global and used by name in BasePack.render()
. As such, there's no easy way of modifying it without duplicating a lot of code. I'd like to propose a modification to BasePack.render()
or BasePack
class so that it can be instantiated with an arbitrary template.
Alternative options
Any implementation of the proposal will be a noop for repo2docker, as it will be still using the same template.
Who would use this feature?
Anyone wanting to slightly modify the basic template, or anyone wanting to reuse the logic from BasePack.render()
on their custom template.
How much effort will adding it take?
It should be a fairly straight forward to change current behavior of BuildPack to initialize it with template as an attribute or pass template to .render() as arg/kwarg.
Who can do this work?
I'll provide PR upon reaching consensus.
Example implementation
diff --git a/repo2docker/buildpacks/base.py b/repo2docker/buildpacks/base.py
index 89c31d5..b79cae7 100644
--- a/repo2docker/buildpacks/base.py
+++ b/repo2docker/buildpacks/base.py
@@ -200,6 +200,8 @@ class BuildPack:
self.log = logging.getLogger('repo2docker')
self.appendix = ''
self.labels = {}
+ self.template = TEMPLATE
+ self.entrypoint_file = ENTRYPOINT_FILE
if sys.platform.startswith('win'):
self.log.warning("Windows environment detected. Note that Windows "
"support is experimental in repo2docker.")
@@ -453,7 +455,7 @@ class BuildPack:
"""
Render BuildPack into Dockerfile
"""
- t = jinja2.Template(TEMPLATE)
+ t = jinja2.Template(self.template)
build_script_directives = []
last_user = 'root'
@@ -554,7 +556,7 @@ class BuildPack:
dest_path, src_path = self.generate_build_context_filename(src)
tar.add(src_path, dest_path, filter=_filter_tar)
- tar.add(ENTRYPOINT_FILE, "repo2docker-entrypoint", filter=_filter_tar)
+ tar.add(self.entrypoint_file, "repo2docker-entrypoint", filter=_filter_tar)
tar.add('.', 'src/', filter=_filter_tar)
Activity