@@ -710,13 +710,25 @@ def update_check():
710710 timeout = 5
711711 )
712712 remote_digest = manifest_resp .headers .get ("Docker-Content-Digest" , "" )
713+ # Compare against the running container's image, not the locally pulled image.
714+ # This detects updates even when the image was pulled but the container wasn't recreated.
715+ container_image = subprocess .run (
716+ ["docker" , "inspect" , "--format" , "{{.Image}}" , "bridge-bank" ],
717+ capture_output = True , text = True , timeout = 10
718+ ).stdout .strip ()
713719 local_digest = subprocess .run (
714720 ["docker" , "inspect" , "--format" , "{{index .RepoDigests 0}}" , IMAGE_NAME ],
715721 capture_output = True , text = True , timeout = 10
716722 ).stdout .strip ()
717723 local_sha = local_digest .split ("@" )[- 1 ] if "@" in local_digest else ""
718- available = remote_digest != local_sha and remote_digest != ""
719- logger .info ("Update check: remote=%s local=%s available=%s" , remote_digest [:20 ], local_sha [:20 ], available )
724+ # Also check if the pulled image differs from what the container is running
725+ pulled_image_id = subprocess .run (
726+ ["docker" , "inspect" , "--format" , "{{.Id}}" , IMAGE_NAME ],
727+ capture_output = True , text = True , timeout = 10
728+ ).stdout .strip ()
729+ container_outdated = container_image != pulled_image_id
730+ available = (remote_digest != local_sha and remote_digest != "" ) or container_outdated
731+ logger .info ("Update check: remote=%s local=%s container_outdated=%s available=%s" , remote_digest [:20 ], local_sha [:20 ], container_outdated , available )
720732 return jsonify ({"available" : available })
721733 except Exception as e :
722734 logger .warning ("Update check failed: %s" , e )
@@ -733,9 +745,20 @@ def update_run():
733745 capture_output = True , text = True , timeout = 120
734746 )
735747 logger .info ("Docker pull output: %s" , pull .stdout .strip () or pull .stderr .strip ())
736- if "Image is up to date" in pull .stdout or "Image is up to date" in pull .stderr :
748+ # Check if container is running the pulled image
749+ container_image = subprocess .run (
750+ ["docker" , "inspect" , "--format" , "{{.Image}}" , "bridge-bank" ],
751+ capture_output = True , text = True , timeout = 10
752+ ).stdout .strip ()
753+ pulled_image_id = subprocess .run (
754+ ["docker" , "inspect" , "--format" , "{{.Id}}" , IMAGE_NAME ],
755+ capture_output = True , text = True , timeout = 10
756+ ).stdout .strip ()
757+ image_is_same = "Image is up to date" in pull .stdout or "Image is up to date" in pull .stderr
758+ container_current = container_image == pulled_image_id
759+ if image_is_same and container_current :
737760 return jsonify ({"up_to_date" : True })
738- logger .info ("New image pulled — recreating container via docker compose up -d" )
761+ logger .info ("Recreating container (new_image=%s, container_outdated=%s)" , not image_is_same , not container_current )
739762 subprocess .Popen (
740763 ["sh" , "-c" , "sleep 2 && cd /compose && docker compose up -d" ],
741764 start_new_session = True
0 commit comments