feat: update targets format for neo and farm
This commit is contained in:
1 parent
d12e34033c
commit
4570efe4f8
4 files changed
+75
-19
No files matched your search
@@ -21,4 +21,4 @@ COPY --from=project /LICENSE /usr/share/licenses/wahrwelt/LICENSE
|
||||
|
||||
USER farm
|
||||
EXPOSE 5000
|
||||
CMD ["gunicorn", "--bind=0.0.0.0:5000", "--workers=2", "--worker-class=gthread", "--threads=4", "--timeout=30", "--access-logfile=-", "--error-logfile=-", "app_flask:app"]
|
||||
CMD ["gunicorn", "--bind=0.0.0.0:5000", "--workers=2", "--worker-class=gthread", "--threads=4", "--timeout=30", "--no-control-socket", "--access-logfile=-", "--error-logfile=-", "app_flask:app"]
|
||||
+41
-15
@@ -230,10 +230,35 @@ def compose_base(
|
||||
return command
|
||||
|
||||
|
||||
def _compose_environment() -> dict[str, str]:
|
||||
def load_targets(root: Path = ROOT) -> dict[str, str] | None:
|
||||
"""Прочитать targets.txt: один адрес в строке, по желанию 'имя адрес'."""
|
||||
path = Path(root) / "targets.txt"
|
||||
if not path.is_file():
|
||||
return None
|
||||
teams: dict[str, str] = {}
|
||||
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
|
||||
line = line.split("#", 1)[0].strip()
|
||||
if not line:
|
||||
continue
|
||||
parts = line.split()
|
||||
if len(parts) > 2:
|
||||
raise ValueError(f"targets.txt:{number}: ожидается 'адрес' или 'имя адрес'")
|
||||
name, address = (parts[0], parts[0]) if len(parts) == 1 else parts
|
||||
if name in teams:
|
||||
raise ValueError(f"targets.txt:{number}: повторяется {name}")
|
||||
teams[name] = address
|
||||
if not 1 <= len(teams) <= 256:
|
||||
raise ValueError("targets.txt должен содержать от 1 до 256 целей")
|
||||
return teams
|
||||
|
||||
|
||||
def _compose_environment(root: Path = ROOT) -> dict[str, str]:
|
||||
"""Disable ambient profile activation; command-specific flags select profiles."""
|
||||
environment = dict(os.environ)
|
||||
environment["COMPOSE_PROFILES"] = ""
|
||||
teams = load_targets(root)
|
||||
if teams is not None:
|
||||
environment["FARM_TEAMS"] = json.dumps(teams)
|
||||
return environment
|
||||
|
||||
|
||||
@@ -250,7 +275,7 @@ def run_compose(
|
||||
return 2
|
||||
try:
|
||||
command = [*compose_base(root, env_file, project_name, profiles), *arguments]
|
||||
return subprocess.call(command, cwd=root, env=_compose_environment())
|
||||
return subprocess.call(command, cwd=root, env=_compose_environment(root))
|
||||
except (OSError, ValueError) as exc:
|
||||
print(f"Не удалось запустить Docker Compose: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
@@ -271,7 +296,7 @@ def _compose_config(
|
||||
result = subprocess.run(
|
||||
command,
|
||||
cwd=Path(root).resolve(),
|
||||
env=_compose_environment(),
|
||||
env=_compose_environment(root),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
@@ -297,18 +322,19 @@ def all_services(
|
||||
if tail:
|
||||
print("Команда up не принимает дополнительные параметры.", file=sys.stderr)
|
||||
return 2
|
||||
services = [
|
||||
"farm-db",
|
||||
"farm",
|
||||
"farm-front",
|
||||
"packmate-db",
|
||||
"packmate",
|
||||
"neo-redis",
|
||||
"neo",
|
||||
"neo-worker",
|
||||
]
|
||||
result = run_compose(
|
||||
["up", "-d", "--build", "--wait", "farm-db", "farm", "farm-front"],
|
||||
root,
|
||||
env_file,
|
||||
project_name,
|
||||
)
|
||||
if result:
|
||||
return result
|
||||
return run_compose(
|
||||
["up", "-d", "--build", "--wait", *services],
|
||||
[
|
||||
"up", "-d", "--build", "--wait",
|
||||
"packmate-db", "packmate", "neo-redis", "neo", "neo-worker",
|
||||
],
|
||||
root,
|
||||
env_file,
|
||||
project_name,
|
||||
@@ -703,7 +729,7 @@ def _run_neo_container(
|
||||
environment["COMPOSE_PROFILES"] = ""
|
||||
environment["NEO_GRPC_AUTH_KEY"] = admin_key
|
||||
else:
|
||||
environment = _compose_environment()
|
||||
environment = _compose_environment(root)
|
||||
return subprocess.call(args, cwd=Path(root).resolve(), env=environment)
|
||||
except (OSError, ValueError) as exc:
|
||||
print(f"Не удалось запустить команду Neo: {exc}", file=sys.stderr)
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
# Один адрес в строке. Можно писать "имя адрес", например: team1 10.183.101.2
|
||||
10.183.101.2
|
||||
10.183.102.2
|
||||
10.183.103.2
|
||||
10.183.104.2
|
||||
10.183.105.2
|
||||
10.183.106.2
|
||||
10.183.107.2
|
||||
10.183.108.2
|
||||
10.183.109.2
|
||||
10.183.110.2
|
||||
10.183.111.2
|
||||
10.183.112.2
|
||||
10.183.113.2
|
||||
10.183.114.2
|
||||
10.183.115.2
|
||||
10.183.116.2
|
||||
10.183.117.2
|
||||
10.183.118.2
|
||||
10.183.119.2
|
||||
10.183.120.2
|
||||
+12
-3
@@ -173,9 +173,13 @@ class ControlTests(unittest.TestCase):
|
||||
def test_all_start_excludes_submission_and_all_stop_keeps_volumes(self):
|
||||
status, call, _ = self.invoke("all-up")
|
||||
self.assertEqual(status, 0)
|
||||
command = call.call_args.args[0]
|
||||
self.assertTrue({"farm-front", "packmate", "neo-worker"}.issubset(command))
|
||||
self.assertNotIn("farm-submit", command)
|
||||
self.assertEqual(call.call_count, 2)
|
||||
farm_command = call.call_args_list[0].args[0]
|
||||
other_command = call.call_args_list[1].args[0]
|
||||
self.assertTrue({"farm", "farm-front"}.issubset(farm_command))
|
||||
self.assertNotIn("neo", farm_command)
|
||||
self.assertTrue({"packmate", "neo-worker"}.issubset(other_command))
|
||||
self.assertNotIn("farm-submit", other_command)
|
||||
status, call, _ = self.invoke("all-down")
|
||||
self.assertEqual(status, 0)
|
||||
command = call.call_args.args[0]
|
||||
@@ -184,6 +188,11 @@ class ControlTests(unittest.TestCase):
|
||||
self.assertNotIn("--volumes", command)
|
||||
self.assertNotIn("--remove-orphans", command)
|
||||
|
||||
def test_all_start_stops_if_farm_is_unhealthy(self):
|
||||
status, call, _ = self.invoke("all-up", result=17)
|
||||
self.assertEqual(status, 17)
|
||||
self.assertEqual(call.call_count, 1)
|
||||
|
||||
def test_submission_is_an_explicit_action(self):
|
||||
status, call, _ = self.invoke("farm", "submit-up")
|
||||
self.assertEqual(status, 0)
|
||||
|
||||
Reference in new issue
Block a user