-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Subpath Support for Volumes in Docker-Py (#3243) #3270
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,14 +242,16 @@ class Mount(dict): | |
for the ``volume`` type. | ||
driver_config (DriverConfig): Volume driver configuration. Only valid | ||
for the ``volume`` type. | ||
subpath (string): The path within the volume where the container's | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd keep this the same as the suggestion above ☝️ |
||
volume should be mounted. | ||
tmpfs_size (int or string): The size for the tmpfs mount in bytes. | ||
tmpfs_mode (int): The permission mode for the tmpfs mount. | ||
""" | ||
|
||
def __init__(self, target, source, type='volume', read_only=False, | ||
consistency=None, propagation=None, no_copy=False, | ||
labels=None, driver_config=None, tmpfs_size=None, | ||
tmpfs_mode=None): | ||
tmpfs_mode=None, subpath=None): | ||
self['Target'] = target | ||
self['Source'] = source | ||
if type not in ('bind', 'volume', 'tmpfs', 'npipe'): | ||
|
@@ -267,7 +269,7 @@ def __init__(self, target, source, type='volume', read_only=False, | |
self['BindOptions'] = { | ||
'Propagation': propagation | ||
} | ||
if any([labels, driver_config, no_copy, tmpfs_size, tmpfs_mode]): | ||
if any([labels, driver_config, no_copy, tmpfs_size, tmpfs_mode, subpath]): | ||
raise errors.InvalidArgument( | ||
'Incompatible options have been provided for the bind ' | ||
'type mount.' | ||
|
@@ -280,6 +282,8 @@ def __init__(self, target, source, type='volume', read_only=False, | |
volume_opts['Labels'] = labels | ||
if driver_config: | ||
volume_opts['DriverConfig'] = driver_config | ||
if subpath: | ||
volume_opts['Subpath'] = subpath | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change the |
||
if volume_opts: | ||
self['VolumeOptions'] = volume_opts | ||
if any([propagation, tmpfs_size, tmpfs_mode]): | ||
|
@@ -299,7 +303,7 @@ def __init__(self, target, source, type='volume', read_only=False, | |
tmpfs_opts['SizeBytes'] = parse_bytes(tmpfs_size) | ||
if tmpfs_opts: | ||
self['TmpfsOptions'] = tmpfs_opts | ||
if any([propagation, labels, driver_config, no_copy]): | ||
if any([propagation, labels, driver_config, no_copy, subpath]): | ||
raise errors.InvalidArgument( | ||
'Incompatible options have been provided for the tmpfs ' | ||
'type mount.' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -620,6 +620,32 @@ def test_create_with_volume_mount(self): | |
assert mount['Source'] == mount_data['Name'] | ||
assert mount_data['RW'] is True | ||
|
||
@requires_api_version('1.45') | ||
def test_create_with_subpath_volume_mount(self): | ||
mount = docker.types.Mount( | ||
type="volume", source=helpers.random_name(), | ||
target=self.mount_dest, read_only=True, | ||
subpath='subdir' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a quick glance, it doesn't seem that the subpath is being checked in this test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made changes accordingly |
||
) | ||
host_config = self.client.create_host_config(mounts=[mount]) | ||
container = self.client.create_container( | ||
TEST_IMG, ['true'], host_config=host_config, | ||
) | ||
assert container | ||
inspect_data = self.client.inspect_container(container) | ||
assert 'Mounts' in inspect_data | ||
filtered = list(filter( | ||
lambda x: x['Destination'] == self.mount_dest, | ||
inspect_data['Mounts'] | ||
)) | ||
|
||
print(mount) | ||
assert len(filtered) == 1 | ||
mount_data = filtered[0] | ||
assert mount['Source'] == mount_data['Name'] | ||
assert mount_data['RW'] is False | ||
assert mount["VolumeOptions"]["Subpath"] == "subdir" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is testing that the input mount options, as defined above on line 628, are the same. The test needs to check that the path mounted inside the container corresponds to the subdir as defined in the mount options. The volume mounted must therefore contain the Maybe you could change to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sure. Will do it later today |
||
|
||
def check_container_data(self, inspect_data, rw, propagation='rprivate'): | ||
assert 'Mounts' in inspect_data | ||
filtered = list(filter( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change this to
To better match documentation we have elsewhere (eg https://github.com/docker/docs/blob/23f3fbd0639a24d0e2280fd0edb7f72b3f0cb1ca/content/reference/compose-file/services.md?plain=1#L1865)
@dvdksn WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM