diff --git a/src/hubblenetwork/sat.py b/src/hubblenetwork/sat.py index cdf2843..7242b8d 100644 --- a/src/hubblenetwork/sat.py +++ b/src/hubblenetwork/sat.py @@ -12,6 +12,7 @@ import base64 import json import logging +import os import time from pathlib import Path from typing import Callable, Dict, Generator, List, Optional, Set, Tuple @@ -23,7 +24,7 @@ logger = logging.getLogger(__name__) -DOCKER_IMAGE = "ghcr.io/hubblenetwork/sdr-docker:latest" +DOCKER_IMAGE = os.environ.get("SDR_DOCKER_IMAGE", "ghcr.io/hubblenetwork/sdr-docker:latest") CONTAINER_NAME = "hubble-pluto-sdr" MOCK_CONTAINER_NAME = "hubble-pluto-sdr-mock" API_PORT = 8050 @@ -94,8 +95,23 @@ def ensure_docker_available() -> None: raise DockerError("Docker daemon is not responding") +def _image_exists_locally(image: str) -> bool: + try: + _get_client().images.get(image) + return True + except Exception: + return False + + def pull_image(image: str = DOCKER_IMAGE) -> None: - """Pull *image*, ensuring the latest version is fetched.""" + """Pull *image*, ensuring the latest version is fetched. + + Skips the pull if the image exists only locally (e.g. a locally-built tag + with no remote registry counterpart). + """ + if _image_exists_locally(image): + logger.info("Image %s found locally, skipping pull", image) + return logger.info("Pulling %s …", image) client = _get_client() try: @@ -241,7 +257,10 @@ def scan( ensure_docker_available() - _emit("Pulling Docker image...") + if _image_exists_locally(image): + _emit(f"Using local image {image}...") + else: + _emit("Pulling Docker image...") pull_image(image) _emit("Starting container...")