From f0e5c2caa4917555562e77d43d5af65a9abae1b8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 16 Nov 2023 14:33:06 +0100 Subject: [PATCH] Changed need to build logic --- roles/update-docker/files/update-docker.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/roles/update-docker/files/update-docker.py b/roles/update-docker/files/update-docker.py index 1e3d3cf9..3f8b726d 100644 --- a/roles/update-docker/files/update-docker.py +++ b/roles/update-docker/files/update-docker.py @@ -46,18 +46,25 @@ def update_docker(directory): before_digests = get_image_digests(directory) print("Pulling docker images.") + need_to_build=False + try: run_command("docker-compose pull") except subprocess.CalledProcessError as e: if "pull access denied" in e.output.decode() or "must be built from source" in e.output.decode(): print("Need to build the image from source.") + need_to_build=True else: print("Failed to pull images with unexpected error.") raise + after_digests = get_image_digests(directory) - if before_digests != after_digests: + if before_digests != after_digest: print("Changes detected in image digests. Rebuilding containers.") + need_to_build=True + + if need_to_build: run_command("docker-compose up -d --build --force-recreate") else: print("Docker images are up to date. No rebuild necessary.")