Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/hubblenetwork/sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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...")
Expand Down
Loading