mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 14:57:59 -05:00
Fix Reducing the amount being downloaded every time the hash changes. (#4078)
This commit is contained in:
@@ -26,12 +26,13 @@ class RuntimeBuilder(abc.ABC):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def image_exists(self, image_name: str) -> bool:
|
||||
def image_exists(self, image_name: str, pull_from_repo: bool = True) -> bool:
|
||||
"""
|
||||
Check if the runtime image exists.
|
||||
|
||||
Args:
|
||||
image_name (str): The name of the runtime image (e.g., "repo:sha").
|
||||
pull_from_repo (bool): Whether to pull from the remote repo if the image not present locally
|
||||
|
||||
Returns:
|
||||
bool: Whether the runtime image exists.
|
||||
|
||||
@@ -166,11 +166,12 @@ class DockerRuntimeBuilder(RuntimeBuilder):
|
||||
)
|
||||
return target_image_hash_name
|
||||
|
||||
def image_exists(self, image_name: str) -> bool:
|
||||
def image_exists(self, image_name: str, pull_from_repo: bool = True) -> bool:
|
||||
"""Check if the image exists in the registry (try to pull it first) or in the local store.
|
||||
|
||||
Args:
|
||||
image_name (str): The Docker image to check (<image repo>:<image tag>)
|
||||
pull_from_repo (bool): Whether to pull from the remote repo if the image not present locally
|
||||
Returns:
|
||||
bool: Whether the Docker image exists in the registry or in the local store
|
||||
"""
|
||||
@@ -184,6 +185,11 @@ class DockerRuntimeBuilder(RuntimeBuilder):
|
||||
logger.debug('Image found locally.')
|
||||
return True
|
||||
except docker.errors.ImageNotFound:
|
||||
if not pull_from_repo:
|
||||
logger.debug(
|
||||
f'Image {image_name} not found locally'
|
||||
)
|
||||
return False
|
||||
try:
|
||||
logger.debug(
|
||||
'Image not found locally. Trying to pull it, please wait...'
|
||||
|
||||
@@ -98,7 +98,7 @@ class RemoteRuntimeBuilder(RuntimeBuilder):
|
||||
# Wait before polling again
|
||||
sleep_if_should_continue(30)
|
||||
|
||||
def image_exists(self, image_name: str) -> bool:
|
||||
def image_exists(self, image_name: str, pull_from_repo: bool = True) -> bool:
|
||||
"""Checks if an image exists in the remote registry using the /image_exists endpoint."""
|
||||
params = {'image': image_name}
|
||||
response = send_request(
|
||||
|
||||
Reference in New Issue
Block a user