diff --git a/repo2docker/buildpacks/base.py b/repo2docker/buildpacks/base.py index e3a570f01..eb202c8cb 100644 --- a/repo2docker/buildpacks/base.py +++ b/repo2docker/buildpacks/base.py @@ -191,7 +191,7 @@ ENTRYPOINT ["/usr/local/bin/repo2docker-entrypoint"] # Specify the default command to run -CMD ["jupyter", "notebook", "--ip", "0.0.0.0"] +CMD {{ command }} {% if appendix -%} # Appendix: @@ -482,6 +482,14 @@ def get_start_script(self): """ return None + def get_command(self): + """ + The default command to be run by docker. + + This should return a list of strings to be used as Dockerfile `CMD`. + """ + return ["jupyter", "notebook", "--ip", "0.0.0.0"] + @property def binder_dir(self): has_binder = os.path.isdir("binder") @@ -554,6 +562,19 @@ def render(self): for k, v in self.get_build_script_files().items() } + # If get_command returns a list or a tuple, it will be stringified (exec form). + # If it returns a string, it will be used as is (shell form). + cmd = self.get_command() + if isinstance(cmd, tuple): + cmd = list(cmd) + if isinstance(cmd, list): + cmd = str(cmd).replace("'", '"') + if not isinstance(cmd, str): + raise ValueError( + 'Method "get_command" of buildpack "%s" must return a string, a list or a tuple.' + % self.__class__.__name__ + ) + return t.render( packages=sorted(self.get_packages()), path=self.get_path(), @@ -568,6 +589,7 @@ def render(self): base_packages=sorted(self.get_base_packages()), post_build_scripts=self.get_post_build_scripts(), start_script=self.get_start_script(), + command=cmd, appendix=self.appendix, )