From e0fc263dcb1f1feccaa5232b309cee393d4fca61 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 26 Dec 2023 16:09:18 +0100 Subject: [PATCH] Removed duplicated code --- backup-docker-to-local.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backup-docker-to-local.py b/backup-docker-to-local.py index 607ad51..e2d0820 100644 --- a/backup-docker-to-local.py +++ b/backup-docker-to-local.py @@ -90,9 +90,12 @@ def backup_volume(volume_name, volume_dir): execute_shell_command(rsync_command) print(f"Backup routine for volume: {volume_name} completed.") +def get_image_info(container): + return execute_shell_command(f"docker inspect {container} | jq -r '.[].Config.Image'") + def has_image(container,image): """Check if the container is using the image""" - image_info = execute_shell_command(f"docker inspect {container} | jq -r '.[].Config.Image'") + image_info = get_image_info(container) return image in image_info[0] def stop_containers(containers): @@ -115,7 +118,7 @@ def get_container_with_image(containers,image): def is_image_whitelisted(container, images): """Check if the container's image is one of the whitelisted images.""" - image_info = execute_shell_command(f"docker inspect {container} | jq -r '.[].Config.Image'") + image_info = get_image_info(container) container_image = image_info[0] for image in images: