kopia lustrzana https://github.com/jupyterhub/repo2docker
add appendix
supports adding arbitrary build steps to the end of Dockerfilepull/226/head
rodzic
2485e9836c
commit
c857f438b3
|
@ -149,6 +149,16 @@ class Repo2Docker(Application):
|
||||||
"""
|
"""
|
||||||
return pwd.getpwuid(os.getuid()).pw_name
|
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):
|
def fetch(self, url, ref, checkout_path):
|
||||||
try:
|
try:
|
||||||
for line in execute_cmd(['git', 'clone', '--recursive', url, checkout_path],
|
for line in execute_cmd(['git', 'clone', '--recursive', url, checkout_path],
|
||||||
|
@ -309,6 +319,11 @@ class Repo2Docker(Application):
|
||||||
default=[]
|
default=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--appendix',
|
||||||
|
type=str,
|
||||||
|
help=self.traits()['appendix'].help,
|
||||||
|
)
|
||||||
return argparser
|
return argparser
|
||||||
|
|
||||||
def json_excepthook(self, etype, evalue, traceback):
|
def json_excepthook(self, etype, evalue, traceback):
|
||||||
|
@ -329,6 +344,8 @@ class Repo2Docker(Application):
|
||||||
self.log_level = logging.DEBUG
|
self.log_level = logging.DEBUG
|
||||||
|
|
||||||
self.load_config_file(args.config)
|
self.load_config_file(args.config)
|
||||||
|
if args.appendix:
|
||||||
|
self.appendix = args.appendix
|
||||||
|
|
||||||
if os.path.exists(args.repo):
|
if os.path.exists(args.repo):
|
||||||
# Let's treat this as a local directory we are building
|
# Let's treat this as a local directory we are building
|
||||||
|
@ -559,6 +576,8 @@ class Repo2Docker(Application):
|
||||||
else:
|
else:
|
||||||
picked_buildpack = self.default_buildpack()
|
picked_buildpack = self.default_buildpack()
|
||||||
|
|
||||||
|
picked_buildpack.appendix = self.appendix
|
||||||
|
|
||||||
self.log.debug(picked_buildpack.render(),
|
self.log.debug(picked_buildpack.render(),
|
||||||
extra=dict(phase='building'))
|
extra=dict(phase='building'))
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,11 @@ USER ${NB_USER}
|
||||||
RUN ./{{ s }}
|
RUN ./{{ s }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
||||||
|
{% if appendix -%}
|
||||||
|
# Appendix:
|
||||||
|
{{ appendix }}
|
||||||
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DOC_URL = "http://repo2docker.readthedocs.io/en/latest/samples.html"
|
DOC_URL = "http://repo2docker.readthedocs.io/en/latest/samples.html"
|
||||||
|
@ -136,6 +141,7 @@ class BuildPack:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.log = logging.getLogger('repo2docker')
|
self.log = logging.getLogger('repo2docker')
|
||||||
|
self.appendix = ''
|
||||||
|
|
||||||
def get_packages(self):
|
def get_packages(self):
|
||||||
"""
|
"""
|
||||||
|
@ -309,6 +315,7 @@ class BuildPack:
|
||||||
build_script_files=self.get_build_script_files(),
|
build_script_files=self.get_build_script_files(),
|
||||||
base_packages=sorted(self.get_base_packages()),
|
base_packages=sorted(self.get_base_packages()),
|
||||||
post_build_scripts=self.get_post_build_scripts(),
|
post_build_scripts=self.get_post_build_scripts(),
|
||||||
|
appendix=self.appendix,
|
||||||
)
|
)
|
||||||
|
|
||||||
def build(self, image_spec, memory_limit, build_args):
|
def build(self, image_spec, memory_limit, build_args):
|
||||||
|
|
|
@ -15,7 +15,7 @@ class DockerBuildPack(BuildPack):
|
||||||
def render(self):
|
def render(self):
|
||||||
Dockerfile = self.binder_path('Dockerfile')
|
Dockerfile = self.binder_path('Dockerfile')
|
||||||
with open(Dockerfile) as f:
|
with open(Dockerfile) as f:
|
||||||
return f.read()
|
return '\n'.join([f.read(), self.appendix, ''])
|
||||||
|
|
||||||
def build(self, image_spec, memory_limit, build_args):
|
def build(self, image_spec, memory_limit, build_args):
|
||||||
limits = {
|
limits = {
|
||||||
|
|
|
@ -8,7 +8,7 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
|
||||||
|
|
||||||
dockerfile = '._binder.Dockerfile'
|
dockerfile = '._binder.Dockerfile'
|
||||||
|
|
||||||
dockerfile_appendix = dedent(r"""
|
legacy_appendix = dedent(r"""
|
||||||
USER root
|
USER root
|
||||||
COPY . /home/main/notebooks
|
COPY . /home/main/notebooks
|
||||||
RUN chown -R main:main /home/main/notebooks
|
RUN chown -R main:main /home/main/notebooks
|
||||||
|
@ -27,7 +27,7 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
with open('Dockerfile') as f:
|
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):
|
def build(self, image_spec, memory_limit, build_args):
|
||||||
with open(self.dockerfile, 'w') as f:
|
with open(self.dockerfile, 'w') as f:
|
||||||
|
|
Ładowanie…
Reference in New Issue