From f2eac0f8b56a09d198dd64036a38869a0790546c Mon Sep 17 00:00:00 2001 From: hunterhubble Date: Wed, 10 Jun 2026 23:08:46 +0000 Subject: [PATCH] feat: add option to use local sdr-docker image - Set the SDR_DOCKER_IMAGE to the name of the container on the local machine and pyhubblenetwork sat scan will use that instead of latest. - Helpful for development and CI with changes to sdr-docker. Now we can do CI runs on PRs from sdr-docker before they become a part of the latest image Signed-off-by: hunterhubble --- src/hubblenetwork/sat.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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...")