diff --git a/dev/README.md b/dev/README.md index 60450ef..9dc95e2 100644 --- a/dev/README.md +++ b/dev/README.md @@ -123,6 +123,7 @@ The `backend` code houses the `scheduler` and the `RESTful API`. The following e - `DOCKER_API_RETRIES`: how many times to retry requests to the Docker daemon - `DOCKER_API_RETRY_DURATION`: how long to wait before retrying a failed request - `WIREGUARD_IMAGE` +- `WIREGUARD_PORT`: port for routing wireguard traffic in the wireguard container. This is not the exposed port. - `WIREGUARD_KERNEL_MODULES`: where to load wireguard kernel modules from (default `/lib/modules`) - `WIREGUARD_HEALTHCHECK_INTERVAL_SECONDS` - `WIREGUARD_HEALTHCHECK_TIMEOUT_SECONDS` diff --git a/worker/manager/src/mirrors_qa_manager/settings.py b/worker/manager/src/mirrors_qa_manager/settings.py index 974d885..318da47 100644 --- a/worker/manager/src/mirrors_qa_manager/settings.py +++ b/worker/manager/src/mirrors_qa_manager/settings.py @@ -40,6 +40,7 @@ class Settings: WIREGUARD_CONTAINER_NAME = getenv( "WIREGUARD_CONTAINER_NAME", default="mirrors-qa-wireguard" ) + WIREGUARD_PORT = int(getenv("WIREGUARD_PORT", default=51820)) # Optional path for loading kernel modules for wireguard container WIREGUARD_KERNEL_MODULES_FPATH = Path( getenv("WIREGUARD_KERNEL_MODULES", default="/lib/modules") diff --git a/worker/manager/src/mirrors_qa_manager/worker.py b/worker/manager/src/mirrors_qa_manager/worker.py index 2075555..bfeb859 100644 --- a/worker/manager/src/mirrors_qa_manager/worker.py +++ b/worker/manager/src/mirrors_qa_manager/worker.py @@ -7,7 +7,7 @@ import signal import sys import time -from collections.abc import Iterable +from collections.abc import Generator from enum import Enum from pathlib import Path from typing import Any @@ -131,8 +131,8 @@ def wg_container_is_healthy(self) -> ExecResult | None: Settings.WIREGUARD_CONTAINER_NAME, self.wg_healthcheck_cmd, ) - except APIError: - logger.error("error whlie performing healthcheck: {exc!s}") + except APIError as exc: + logger.error(f"error whlie performing healthcheck: {exc!s}") return None def wg_healthcheck_untill_healthy( @@ -201,7 +201,9 @@ def start_wireguard_container(self, image_name: str, conf_fpath: Path) -> Contai "timeout": Settings.WIREGUARD_HEALTHCHECK_TIMEOUT_NANOSECONDS, "retries": Settings.WIREGUARD_HEALTHCHECK_RETRIES, }, - ports={"51820/udp": None}, # Let the host assign a random port + ports={ + f"{Settings.WIREGUARD_PORT}/udp": None + }, # Let the host assign a random port sysctls={"net.ipv4.conf.all.src_valid_mark": 1}, environment={ "PUID": 1000, @@ -292,7 +294,7 @@ def update_countries_list(self): "countries." ) - def fetch_tests(self) -> Iterable[dict[str, str]]: + def fetch_tests(self) -> Generator[dict[str, str], None, None]: logger.debug("Fetching tasks from backend API") # Fetch tasks that were assigned to the worker that haven't been expired params = urlencode({"worker_id": self.worker_id, "status": "PENDING"})