Skip to content
Merged
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
21 changes: 17 additions & 4 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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update the doc / user guide? Is this env set by the program or by user?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point. I didn't have the end-user in mind when making this, I was only thinking about how to integrate this into CI with new versions of sdr-docker before it gets updated into latest. I personally don't think we should advise the user to change our sdr-docker and use pyhubblenetwork with it, ideally they should only be using latest because that is what's validated.

CONTAINER_NAME = "hubble-pluto-sdr"
MOCK_CONTAINER_NAME = "hubble-pluto-sdr-mock"
API_PORT = 8050
Expand Down Expand Up @@ -103,8 +104,17 @@ 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.
"""
Comment on lines +116 to +117

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is no change to pull_image, we should keep the doc comment the same right?

logger.info("Pulling %s …", image)
client = _get_client()
try:
Expand Down Expand Up @@ -297,8 +307,11 @@ def scan(

ensure_docker_available()

_emit("Pulling Docker image...")
pull_image(image)
if _image_exists_locally(image):
_emit(f"Using local image {image}...")
else:
_emit("Pulling Docker image...")
pull_image(image)

_emit("Starting container...")
container_name = MOCK_CONTAINER_NAME if mock else CONTAINER_NAME
Expand Down
Loading