add appendix
supports adding arbitrary build steps to the end of Dockerfile
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -149,6 +149,16 @@ class Repo2Docker(Application):
"""
return pwd.getpwuid(os.getuid()).pw_name
+ appendix = Unicode(
+ config=True,
+ help="""
+ Appendix of Dockerfile commands to run at the end of the build.
+
+ Can be used to customize the resulting image after all
+ standard build steps finish.
+ """
+ )
+
def fetch(self, url, ref, checkout_path):
try:
for line in execute_cmd(['git', 'clone', '--recursive', url, checkout_path],
@@ -309,6 +319,11 @@ class Repo2Docker(Application):
default=[]
)
+ argparser.add_argument(
+ '--appendix',
+ type=str,
+ help=self.traits()['appendix'].help,
+ )
return argparser
def json_excepthook(self, etype, evalue, traceback):
@@ -329,6 +344,8 @@ class Repo2Docker(Application):
self.log_level = logging.DEBUG
self.load_config_file(args.config)
+ if args.appendix:
+ self.appendix = args.appendix
if os.path.exists(args.repo):
# Let's treat this as a local directory we are building
@@ -559,6 +576,8 @@ class Repo2Docker(Application):
else:
picked_buildpack = self.default_buildpack()
+ picked_buildpack.appendix = self.appendix
+
self.log.debug(picked_buildpack.render(),
extra=dict(phase='building'))

MODIFY
repo2docker/buildpacks/base.py
repo2docker/buildpacks/base.py
@@ -112,6 +112,11 @@ USER ${NB_USER}
RUN ./{{ s }}
{% endfor %}
{% endif -%}
+
+{% if appendix -%}
+# Appendix:
+{{ appendix }}
+{% endif %}
"""
DOC_URL = "http://repo2docker.readthedocs.io/en/latest/samples.html"
@@ -136,6 +141,7 @@ class BuildPack:
def __init__(self):
self.log = logging.getLogger('repo2docker')
+ self.appendix = ''
def get_packages(self):
"""
@@ -309,6 +315,7 @@ class BuildPack:
build_script_files=self.get_build_script_files(),
base_packages=sorted(self.get_base_packages()),
post_build_scripts=self.get_post_build_scripts(),
+ appendix=self.appendix,
)
def build(self, image_spec, memory_limit, build_args):

MODIFY
repo2docker/buildpacks/docker.py
repo2docker/buildpacks/docker.py
@@ -15,7 +15,7 @@ class DockerBuildPack(BuildPack):
def render(self):
Dockerfile = self.binder_path('Dockerfile')
with open(Dockerfile) as f:
- return f.read()
+ return '\n'.join([f.read(), self.appendix, ''])
def build(self, image_spec, memory_limit, build_args):
limits = {

MODIFY
repo2docker/buildpacks/legacy.py
repo2docker/buildpacks/legacy.py
@@ -8,7 +8,7 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
dockerfile = '._binder.Dockerfile'
- dockerfile_appendix = dedent(r"""
+ legacy_appendix = dedent(r"""
USER root
COPY . /home/main/notebooks
RUN chown -R main:main /home/main/notebooks
@@ -27,7 +27,7 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
def render(self):
with open('Dockerfile') as f:
- return f.read() + self.dockerfile_appendix
+ return '\n'.join([f.read(), self.legacy_appendix, self.appendix, ''])
def build(self, image_spec, memory_limit, build_args):
with open(self.dockerfile, 'w') as f:

add appendix

supports adding arbitrary build steps to the end of Dockerfile