Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions binderhub/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,13 @@ def _default_builder_info(self):

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

return affinity

def get_builder_volumes(self):
"""
Get the lists of volumes and volume-mounts for the build pod.
"""
volume_mounts = []
volumes = []

if self.docker_host is not None:
volume_mounts.append(
client.V1VolumeMount(
mount_path="/var/run/docker.sock", name="docker-socket"
)
)
docker_socket_path = urlparse(self.docker_host).path
volumes.append(
client.V1Volume(
name="docker-socket",
host_path=client.V1HostPathVolumeSource(
path=docker_socket_path, type="Socket"
),
)
)

if not self.registry_credentials and self.push_secret:
volume_mounts.append(
client.V1VolumeMount(mount_path="/root/.docker", name="docker-config")
)
volumes.append(
client.V1Volume(
name="docker-config",
secret=client.V1SecretVolumeSource(secret_name=self.push_secret),
)
)

return volumes, volume_mounts

def submit(self):
"""
Submit a build pod to create the image for the repository.

Progress of the build can be monitored by listening for items in
the Queue passed to the constructor as `q`.
"""
volume_mounts = [
client.V1VolumeMount(
mount_path="/var/run/docker.sock", name="docker-socket"
)
]
docker_socket_path = urlparse(self.docker_host).path
volumes = [
client.V1Volume(
name="docker-socket",
host_path=client.V1HostPathVolumeSource(
path=docker_socket_path, type="Socket"
),
)
]
volumes, volume_mounts = self.get_builder_volumes()

env = [
client.V1EnvVar(name=key, value=value)
Expand All @@ -454,16 +480,6 @@ def submit(self):
value=json.dumps(self.registry_credentials),
)
)
elif self.push_secret:
volume_mounts.append(
client.V1VolumeMount(mount_path="/root/.docker", name="docker-config")
)
volumes.append(
client.V1Volume(
name="docker-config",
secret=client.V1SecretVolumeSource(secret_name=self.push_secret),
)
)

self.pod = client.V1Pod(
metadata=client.V1ObjectMeta(
Expand Down