mirror of
https://github.com/containers/podman-compose.git
synced 2025-06-02 00:15:38 +02:00
Simplify volume identification
The filtering provided by "volume ls" did not work as expected in previous versions of podman: https://github.com/containers/podman/pull/8345 Verified that this now works properly on podman 3.4.4 Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
This commit is contained in:
parent
890c584881
commit
af53b65068
@ -857,16 +857,15 @@ class Podman:
|
|||||||
time.sleep(sleep)
|
time.sleep(sleep)
|
||||||
return p
|
return p
|
||||||
|
|
||||||
def volume_inspect_all(self):
|
def volume_ls(self, proj=None):
|
||||||
output = self.output([], "volume", ["inspect", "--all"]).decode('utf-8')
|
|
||||||
return json.loads(output)
|
|
||||||
|
|
||||||
def volume_inspect_proj(self, proj=None):
|
|
||||||
if not proj:
|
if not proj:
|
||||||
proj = self.compose.project_name
|
proj = self.compose.project_name
|
||||||
volumes = [(vol.get("Labels", {}), vol) for vol in self.volume_inspect_all()]
|
output = self.output([], "volume", [
|
||||||
volumes = [(labels.get("io.podman.compose.project", None), vol) for labels, vol in volumes]
|
"ls", "--noheading", "--filter", f"label=io.podman.compose.project={proj}",
|
||||||
return [vol for vol_proj, vol in volumes if vol_proj==proj]
|
"--format", "{{.Name}}",
|
||||||
|
]).decode('utf-8')
|
||||||
|
volumes = output.splitlines()
|
||||||
|
return volumes
|
||||||
|
|
||||||
def normalize_service(service):
|
def normalize_service(service):
|
||||||
for key in ("env_file", "security_opt", "volumes"):
|
for key in ("env_file", "security_opt", "volumes"):
|
||||||
@ -1510,8 +1509,7 @@ def compose_down(compose, args):
|
|||||||
if cnt["_service"] not in excluded: continue
|
if cnt["_service"] not in excluded: continue
|
||||||
vol_names_to_keep.update(get_volume_names(compose, cnt))
|
vol_names_to_keep.update(get_volume_names(compose, cnt))
|
||||||
log("keep", vol_names_to_keep)
|
log("keep", vol_names_to_keep)
|
||||||
volume_names = [vol["Name"] for vol in compose.podman.volume_inspect_proj()]
|
for volume_name in compose.podman.volume_ls():
|
||||||
for volume_name in volume_names:
|
|
||||||
if volume_name in vol_names_to_keep: continue
|
if volume_name in vol_names_to_keep: continue
|
||||||
compose.podman.run([], "volume", ["rm", volume_name])
|
compose.podman.run([], "volume", ["rm", volume_name])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user