Skip to content

Commit e7995d6

Browse files
authored
Merge pull request #1795 from manics/docker-socket-optional
Make docker-socket optional, build volumes can be overridden
2 parents 340780d + 010acd3 commit e7995d6

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

binderhub/build.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,13 @@ def _default_builder_info(self):
299299

300300
docker_host = Unicode(
301301
"/var/run/docker.sock",
302+
allow_none=True,
302303
help=(
303304
"The docker socket to use for building the image. "
304305
"Must be a unix domain socket on a filesystem path accessible on the node "
305-
"in which the build pod is running."
306+
"in which the build pod is running. "
307+
"This is mounted into the build pod, set to None to disable, "
308+
"e.g. if you are using an alternative builder that doesn't need the docker socket."
306309
),
307310
config=True,
308311
)
@@ -416,27 +419,50 @@ def get_affinity(self):
416419

417420
return affinity
418421

422+
def get_builder_volumes(self):
423+
"""
424+
Get the lists of volumes and volume-mounts for the build pod.
425+
"""
426+
volume_mounts = []
427+
volumes = []
428+
429+
if self.docker_host is not None:
430+
volume_mounts.append(
431+
client.V1VolumeMount(
432+
mount_path="/var/run/docker.sock", name="docker-socket"
433+
)
434+
)
435+
docker_socket_path = urlparse(self.docker_host).path
436+
volumes.append(
437+
client.V1Volume(
438+
name="docker-socket",
439+
host_path=client.V1HostPathVolumeSource(
440+
path=docker_socket_path, type="Socket"
441+
),
442+
)
443+
)
444+
445+
if not self.registry_credentials and self.push_secret:
446+
volume_mounts.append(
447+
client.V1VolumeMount(mount_path="/root/.docker", name="docker-config")
448+
)
449+
volumes.append(
450+
client.V1Volume(
451+
name="docker-config",
452+
secret=client.V1SecretVolumeSource(secret_name=self.push_secret),
453+
)
454+
)
455+
456+
return volumes, volume_mounts
457+
419458
def submit(self):
420459
"""
421460
Submit a build pod to create the image for the repository.
422461
423462
Progress of the build can be monitored by listening for items in
424463
the Queue passed to the constructor as `q`.
425464
"""
426-
volume_mounts = [
427-
client.V1VolumeMount(
428-
mount_path="/var/run/docker.sock", name="docker-socket"
429-
)
430-
]
431-
docker_socket_path = urlparse(self.docker_host).path
432-
volumes = [
433-
client.V1Volume(
434-
name="docker-socket",
435-
host_path=client.V1HostPathVolumeSource(
436-
path=docker_socket_path, type="Socket"
437-
),
438-
)
439-
]
465+
volumes, volume_mounts = self.get_builder_volumes()
440466

441467
env = [
442468
client.V1EnvVar(name=key, value=value)
@@ -454,16 +480,6 @@ def submit(self):
454480
value=json.dumps(self.registry_credentials),
455481
)
456482
)
457-
elif self.push_secret:
458-
volume_mounts.append(
459-
client.V1VolumeMount(mount_path="/root/.docker", name="docker-config")
460-
)
461-
volumes.append(
462-
client.V1Volume(
463-
name="docker-config",
464-
secret=client.V1SecretVolumeSource(secret_name=self.push_secret),
465-
)
466-
)
467483

468484
self.pod = client.V1Pod(
469485
metadata=client.V1ObjectMeta(

0 commit comments

Comments
 (0)