Skip to content

Commit 0835f46

Browse files
authored
Merge pull request #535 from yuvipanda/cleaner-mounts
Cleanup how mounts are handled
2 parents 44ed0b3 + 9de96fd commit 0835f46

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

dockerspawner/dockerspawner.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def _default_name_template(self):
442442
)
443443

444444
mounts = List(
445+
Dict(),
445446
config=True,
446447
help=dedent(
447448
"""
@@ -894,24 +895,6 @@ def volume_binds(self):
894895
read_only_volumes.update(self.read_only_volumes)
895896
return self._volumes_to_binds(read_only_volumes, binds, mode="ro")
896897

897-
@property
898-
def mount_binds(self):
899-
"""
900-
A different way of specifying docker volumes using more advanced spec.
901-
Converts mounts list of dict to a list of docker.types.Mount
902-
"""
903-
904-
def _fmt(v):
905-
return self.format_volume_name(v, self)
906-
907-
mounts = []
908-
for mount in self.mounts:
909-
args = dict(mount)
910-
args["source"] = _fmt(mount["source"])
911-
args["target"] = _fmt(mount["target"])
912-
mounts.append(Mount(**args))
913-
return mounts
914-
915898
_escaped_name = None
916899

917900
@property
@@ -1184,12 +1167,24 @@ async def create_object(self):
11841167

11851168
_deep_merge(create_kwargs, extra_create_kwargs)
11861169

1170+
# Make a list of mount objects if present, formatting strings but passing through everything else
1171+
mount_binds = [
1172+
Mount(
1173+
**{
1174+
k: self.format_volume_name(v, self) if isinstance(v, str) else v
1175+
for k, v in mount.items()
1176+
}
1177+
)
1178+
for mount in self.mounts
1179+
]
1180+
11871181
# build the dictionary of keyword arguments for host_config
1182+
11881183
host_config = dict(
11891184
auto_remove=self.remove,
11901185
binds=self.volume_binds,
11911186
links=self.links,
1192-
mounts=self.mount_binds,
1187+
mounts=mount_binds,
11931188
)
11941189

11951190
if getattr(self, "mem_limit", None) is not None:

0 commit comments

Comments
 (0)