Skip to content

Commit

Permalink
Allow passing extra arguments to repo2docker
Browse files Browse the repository at this point in the history
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 jupyterhub#1765
  • Loading branch information
yuvipanda committed Oct 6, 2023
1 parent fcc0a46 commit 2deb3e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 12 additions & 1 deletion binderhub/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 19 additions & 1 deletion binderhub/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
]

0 comments on commit 2deb3e8

Please sign in to comment.