Add support external volumes

# docker-compose.yml
version: '3'
services:
  test:
     volumes:
        - data:/data
volumes:
  data:
     name: some
     external: true
This commit is contained in:
Igor Kuznetsov 2020-12-21 13:24:17 +03:00 committed by Muayyad Alsadi
parent ab135030c8
commit 6d69b7c74c

View File

@ -144,6 +144,10 @@ def fix_mount_dict(mount_dict, proj_name, srv_name):
proj_name, srv_name,
hashlib.sha256(mount_dict["target"].encode("utf-8")).hexdigest(),
])
else:
name = mount_dict.get('name')
if name:
mount_dict["source"] = name
else:
# prefix with proj_name
mount_dict["source"] = proj_name+"_"+source
@ -390,7 +394,7 @@ def assert_volume(compose, mount_dict):
inspect volume to get directory
create volume if needed
"""
if mount_dict["type"] != "volume": return
if mount_dict["type"] != "volume" or mount_dict["external"]: return
proj_name = compose.project_name
shared_vols = compose.shared_vols
@ -494,6 +498,19 @@ def get_mount_args(compose, cnt, volume):
basedir = compose.dirname
if is_str(volume): volume = parse_short_mount(volume, basedir)
mount_type = volume["type"]
vol = None
source = volume.get('source')
if source:
vol = compose.shared_vols[source]
if vol:
name = vol.get('name')
if name:
volume['name'] = name
external = vol.get('external')
if external:
volume['external'] = external
assert_volume(compose, fix_mount_dict(volume, proj_name, srv_name))
if compose._prefer_volume_over_mount:
if mount_type == 'tmpfs':
@ -1110,8 +1127,6 @@ class PodmanCompose:
service_names = [ name for _, name in service_names]
# volumes: [...]
shared_vols = compose.get('volumes', {})
# shared_vols = list(shared_vols.keys())
shared_vols = set(shared_vols.keys())
self.shared_vols = shared_vols
podman_compose_labels = [
"io.podman.compose.config-hash=123",