Merge pull request #226 from minrk/postamble

add appendix
pull/176/head^2
Yuvi Panda 2018-02-16 16:46:04 -08:00 zatwierdzone przez GitHub
commit f069a7b99d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 38 dodań i 5 usunięć

Wyświetl plik

@ -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'))

Wyświetl plik

@ -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):

Wyświetl plik

@ -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 = {

Wyświetl plik

@ -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:

Wyświetl plik

@ -62,7 +62,11 @@ class LocalRepo(pytest.File):
def collect(self):
yield Repo2DockerTest(
self.fspath.basename, self,
args=[self.fspath.dirname, './verify'],
args=[
'--appendix', 'RUN echo "appendix" > /tmp/appendix',
self.fspath.dirname,
'./verify',
],
)

Wyświetl plik

@ -2,5 +2,8 @@
# Verify that the default just provides a py3 environment with jupyter
import sys
assert sys.version_info[:2] == (3, 6)
assert sys.version_info[:2] == (3, 6), sys.version
import jupyter
with open('/tmp/appendix') as f:
assert f.read().strip() == 'appendix'