From f237cf140ced565be1bb2c5f75a8ff8347fb2137 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 16 Nov 2023 14:42:09 +0100 Subject: [PATCH] Catched error if no local images exist --- roles/update-docker/files/update-docker.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/roles/update-docker/files/update-docker.py b/roles/update-docker/files/update-docker.py index 3f8b726d..81b34278 100644 --- a/roles/update-docker/files/update-docker.py +++ b/roles/update-docker/files/update-docker.py @@ -34,11 +34,17 @@ def git_pull(directory): def get_image_digests(directory): compose_project = os.path.basename(directory) - images_output = subprocess.check_output( - f'docker images --format "{{{{.Repository}}}}:{{{{.Tag}}}}@{{{{.Digest}}}}" | grep {compose_project}', - shell=True - ).decode().strip() - return dict(line.split('@') for line in images_output.splitlines() if line) + try: + images_output = subprocess.check_output( + f'docker images --format "{{{{.Repository}}}}:{{{{.Tag}}}}@{{{{.Digest}}}}" | grep {compose_project}', + shell=True + ).decode().strip() + return dict(line.split('@') for line in images_output.splitlines() if line) + except subprocess.CalledProcessError as e: + if e.returncode == 1: # grep no match found + return {} + else: + raise # Other errors are still raised def update_docker(directory): print(f"Checking for updates to Docker images in {directory}.")