From 6d69b7c74c398633e890cea18bd1c5ca4f75192d Mon Sep 17 00:00:00 2001 From: Igor Kuznetsov Date: Mon, 21 Dec 2020 13:24:17 +0300 Subject: [PATCH] Add support external volumes # docker-compose.yml version: '3' services: test: volumes: - data:/data volumes: data: name: some external: true --- podman_compose.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index 23659cb..7cd71c0 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -145,8 +145,12 @@ def fix_mount_dict(mount_dict, proj_name, srv_name): hashlib.sha256(mount_dict["target"].encode("utf-8")).hexdigest(), ]) else: - # prefix with proj_name - mount_dict["source"] = proj_name+"_"+source + name = mount_dict.get('name') + if name: + mount_dict["source"] = name + else: + # prefix with proj_name + mount_dict["source"] = proj_name+"_"+source return mount_dict # docker and docker-compose support subset of bash variable substitution @@ -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",