From 2deb3e8a6530772d5621e113a1bb0d374526a81e Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Thu, 5 Oct 2023 23:08:46 -0700 Subject: [PATCH] Allow passing extra arguments to repo2docker Very helpful for a specific binderhub instance to customize how images are built. Off the top of my head, two useful things would be to pass `--repo-dir` (so you can have this work with a persistent home directory but still get access to the files in the image), and `--base-image` (so an install can use a different base image than rep2docker default). As it's a simple passthrough, I've added a unit test only (no integration test). Fixes https://github.com/jupyterhub/binderhub/issues/1765 --- binderhub/build.py | 13 ++++++++++++- binderhub/tests/test_build.py | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/binderhub/build.py b/binderhub/build.py index 4ab9ec65b..ed64aa390 100644 --- a/binderhub/build.py +++ b/binderhub/build.py @@ -16,7 +16,7 @@ from kubernetes import client, watch from tornado.ioloop import IOLoop from tornado.log import app_log -from traitlets import Any, Bool, Dict, Integer, Unicode, default +from traitlets import Any, Bool, Dict, Integer, List, Unicode, default from traitlets.config import LoggingConfigurable from .utils import KUBE_REQUEST_TIMEOUT, ByteSpecification, rendezvous_rank @@ -125,6 +125,15 @@ class BuildExecutor(LoggingConfigurable): config=True, ) + repo2docker_extra_args = List( + Unicode, + default_value=[], + help=""" + Extra commandline parameters to be passed to jupyter-repo2docker during build + """, + config=True, + ) + def __init__(self, **kwargs): super().__init__(**kwargs) self.main_loop = IOLoop.current() @@ -156,6 +165,8 @@ def get_r2d_cmd_options(self): r2d_options.append("--build-memory-limit") r2d_options.append(str(self.memory_limit)) + r2d_options += self.repo2docker_extra_args + return r2d_options def get_cmd(self): diff --git a/binderhub/tests/test_build.py b/binderhub/tests/test_build.py index 7f7a795ea..6c87f2a15 100644 --- a/binderhub/tests/test_build.py +++ b/binderhub/tests/test_build.py @@ -13,7 +13,7 @@ from tornado.httputil import url_concat from tornado.queues import Queue -from binderhub.build import KubernetesBuildExecutor, ProgressEvent +from binderhub.build import BuildExecutor, KubernetesBuildExecutor, ProgressEvent from binderhub.build_local import LocalRepo2dockerBuild, ProcessTerminated, _execute_cmd from .utils import async_requests @@ -415,3 +415,21 @@ def break_callback(): lines.append(line) assert lines == ["1\n"] assert str(exc.value) == f"ProcessTerminated: {cmd}" + + +def test_extra_r2d_options(): + bex = BuildExecutor() + bex.repo2docker_extra_args = ["--repo-dir=/srv/repo"] + bex.image_name = "test:test" + bex.ref = "main" + + assert bex.get_r2d_cmd_options() == [ + "--ref=main", + "--image=test:test", + "--no-clean", + "--no-run", + "--json-logs", + "--user-name=jovyan", + "--user-id=1000", + "--repo-dir=/srv/repo", + ]