def get_image_environment_variable(env_name: str) -> Optional[str]: image_name = get_docker_image_to_start() image_info = DOCKER_CLIENT.inspect_image(image_name) image_envs = image_info["Config"]["Env"] try: found_env = next(env for env in image_envs if env.startswith(env_name)) except StopIteration: return None return found_env.split("=")[1]
def get_important_image_hashes() -> Dict[str, str]: result = {} for image in DIAGNOSE_IMAGES: try: image_version = DOCKER_CLIENT.inspect_image(image, pull=False)["RepoDigests"] except NoSuchImage: image_version = "not_present" except Exception as e: image_version = f"error: {e}" result[image] = image_version return result
def update_images(image_list: List[str]): from rich.markup import escape from rich.progress import MofNCompleteColumn, Progress from localstack.utils.container_utils.container_client import ContainerException from localstack.utils.docker_utils import DOCKER_CLIENT updated_count = 0 failed_count = 0 progress = Progress(*Progress.get_default_columns(), MofNCompleteColumn(), transient=True, console=console) with progress: for image in progress.track(image_list, description="Processing image..."): try: updated = False hash_before_pull = DOCKER_CLIENT.inspect_image( image_name=image, pull=False)["Id"] DOCKER_CLIENT.pull_image(image) if (hash_before_pull != DOCKER_CLIENT.inspect_image( image_name=image, pull=False)["Id"]): updated = True updated_count += 1 console.print( f":heavy_check_mark: Image {escape(image)} {'updated' if updated else 'up-to-date'}.", style="bold" if updated else None, highlight=False, ) except ContainerException as e: console.print( f":heavy_multiplication_x: Image {escape(image)} pull failed: {e.message}", style="bold red", highlight=False, ) failed_count += 1 console.rule() console.print( f"Images updated: {updated_count}, Images failed: {failed_count}, total images processed: {len(image_list)}." )
def get_docker_image_details(image_name=None): image_name = image_name or get_docker_image_to_start() try: result = DOCKER_CLIENT.inspect_image(image_name) except ContainerException: return {} result = { "id": result["Id"].replace("sha256:", "")[:12], "tag": (result.get("RepoTags") or ["latest"])[0].split(":")[-1], "created": result["Created"].split(".")[0], } return result