mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-05-06 21:41:49 +02:00
Warn users if the minimum version of Docker Desktop is not met
This only happens on Windows and macOS. Fixes #693
This commit is contained in:
parent
c89988654c
commit
90c2e8569a
2 changed files with 29 additions and 1 deletions
|
@ -500,6 +500,10 @@ class WaitingWidgetContainer(WaitingWidget):
|
||||||
error: Optional[str] = None
|
error: Optional[str] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
is_available, version = self.dangerzone.isolation_provider.check_runtime_version()
|
||||||
|
if not is_available:
|
||||||
|
error = f"Your Docker version is too old ({version})."
|
||||||
|
print(error)
|
||||||
self.dangerzone.isolation_provider.is_runtime_available()
|
self.dangerzone.isolation_provider.is_runtime_available()
|
||||||
except NoContainerTechException as e:
|
except NoContainerTechException as e:
|
||||||
log.error(str(e))
|
log.error(str(e))
|
||||||
|
|
|
@ -12,7 +12,10 @@ from ..util import get_resource_path, get_subprocess_startupinfo
|
||||||
from .base import IsolationProvider, terminate_process_group
|
from .base import IsolationProvider, terminate_process_group
|
||||||
|
|
||||||
TIMEOUT_KILL = 5 # Timeout in seconds until the kill command returns.
|
TIMEOUT_KILL = 5 # Timeout in seconds until the kill command returns.
|
||||||
|
MINIMUM_DOCKER_VERSION = {
|
||||||
|
"Darwin": "4.35.1",
|
||||||
|
"Windows": "4.35.1",
|
||||||
|
}
|
||||||
|
|
||||||
# Define startupinfo for subprocesses
|
# Define startupinfo for subprocesses
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
@ -197,10 +200,31 @@ class Container(IsolationProvider):
|
||||||
log.info("Container image installed")
|
log.info("Container image installed")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_runtime_version() -> Tuple[bool, str]:
|
||||||
|
# On windows and darwin, check that the minimum version is met
|
||||||
|
if platform.system() != "Linux":
|
||||||
|
with subprocess.Popen(
|
||||||
|
["docker", "version", "--format", "'{{.Server.Platform.Name}}'"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
|
) as p:
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise NotAvailableContainerTechException("docker", stderr.decode())
|
||||||
|
# The output is like "Docker Desktop 4.35.1 (173168)"
|
||||||
|
version = stdout.replace("Docker Desktop", "").split()[0]
|
||||||
|
|
||||||
|
if version < MINIMUM_DOCKER_VERSION[platform.system()]:
|
||||||
|
return False, version
|
||||||
|
return True, ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_runtime_available() -> bool:
|
def is_runtime_available() -> bool:
|
||||||
container_runtime = Container.get_runtime()
|
container_runtime = Container.get_runtime()
|
||||||
runtime_name = Container.get_runtime_name()
|
runtime_name = Container.get_runtime_name()
|
||||||
|
|
||||||
# Can we run `docker/podman image ls` without an error
|
# Can we run `docker/podman image ls` without an error
|
||||||
with subprocess.Popen(
|
with subprocess.Popen(
|
||||||
[container_runtime, "image", "ls"],
|
[container_runtime, "image", "ls"],
|
||||||
|
|
Loading…
Reference in a new issue