Skip to content

Commit 1e17dbc

Browse files
Harden Compose update readiness
1 parent 3e0f503 commit 1e17dbc

4 files changed

Lines changed: 119 additions & 7 deletions

File tree

‎config/ulysses/runtime-management.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
{
5555
"path": ".env",
5656
"mode": "0600",
57-
"content": "# Official SearXNG container settings for a loopback workstation\nSEARXNG_VERSION=latest\nSEARXNG_HOST=127.0.0.1\nSEARXNG_PORT=7070\n"
57+
"content": "# Official SearXNG container settings for the local workstation network\nSEARXNG_VERSION=latest\nSEARXNG_HOST=0.0.0.0\nSEARXNG_PORT=7070\n"
5858
},
5959
{
6060
"path": "core-config/settings.yml",
@@ -64,7 +64,7 @@
6464
{
6565
"path": "docker-compose.yml",
6666
"mode": "0644",
67-
"content": "name: searxng\n\nservices:\n core:\n container_name: searxng-core\n image: docker.io/searxng/searxng:${SEARXNG_VERSION:-latest}\n restart: unless-stopped\n ports:\n - \"${SEARXNG_HOST:-127.0.0.1}:${SEARXNG_PORT:-7070}:${SEARXNG_PORT:-7070}\"\n env_file: ./.env\n volumes:\n - ./core-config/:/etc/searxng/:Z\n - core-data:/var/cache/searxng/\n\n valkey:\n container_name: searxng-valkey\n image: docker.io/valkey/valkey:9-alpine\n command: valkey-server --save 30 1 --loglevel warning\n restart: unless-stopped\n volumes:\n - valkey-data:/data/\n\nvolumes:\n core-data:\n valkey-data:\n"
67+
"content": "name: searxng\n\nservices:\n core:\n container_name: searxng-core\n image: docker.io/searxng/searxng:${SEARXNG_VERSION:-latest}\n restart: unless-stopped\n ports:\n - \"${SEARXNG_HOST:-0.0.0.0}:${SEARXNG_PORT:-7070}:${SEARXNG_PORT:-7070}\"\n env_file: ./.env\n volumes:\n - ./core-config/:/etc/searxng/:Z\n - core-data:/var/cache/searxng/\n\n valkey:\n container_name: searxng-valkey\n image: docker.io/valkey/valkey:9-alpine\n command: valkey-server --save 30 1 --loglevel warning\n restart: unless-stopped\n volumes:\n - valkey-data:/data/\n\nvolumes:\n core-data:\n valkey-data:\n"
6868
}
6969
],
7070
"git_update": false,

‎src/diogenes_docker_projects.py‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,9 @@ def create_plan(
13441344
"up",
13451345
"-d",
13461346
"--remove-orphans",
1347+
"--wait",
1348+
"--wait-timeout",
1349+
"300",
13471350
*selected,
13481351
],
13491352
"cwd": str(root),
@@ -1372,11 +1375,26 @@ def create_plan(
13721375
elif action == "restart":
13731376
steps = [
13741377
{
1375-
"label": "Restart Compose services",
1376-
"argv": [*base, "restart", *selected],
1378+
"label": "Stop Compose services before ordered restart",
1379+
"argv": [*base, "stop", *selected],
13771380
"cwd": str(root),
13781381
"timeout": 900,
1379-
}
1382+
},
1383+
{
1384+
"label": "Start Compose services and wait for readiness",
1385+
"argv": [
1386+
*base,
1387+
"up",
1388+
"-d",
1389+
"--remove-orphans",
1390+
"--wait",
1391+
"--wait-timeout",
1392+
"300",
1393+
*selected,
1394+
],
1395+
"cwd": str(root),
1396+
"timeout": 1200,
1397+
},
13801398
]
13811399
elif action == "pull":
13821400
steps = [
@@ -1429,13 +1447,15 @@ def create_plan(
14291447
)
14301448
steps.append(
14311449
{
1432-
"label": "Redeploy Compose project",
1450+
"label": "Apply Compose update and wait for readiness",
14331451
"argv": [
14341452
*base,
14351453
"up",
14361454
"-d",
14371455
"--remove-orphans",
1438-
"--force-recreate",
1456+
"--wait",
1457+
"--wait-timeout",
1458+
"300",
14391459
*selected,
14401460
],
14411461
"cwd": str(root),
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
5+
from src import diogenes_docker_projects as docker_projects
6+
7+
8+
def _compose_project(tmp_path: Path, *actions: str) -> dict:
9+
root = tmp_path / "firecrawl"
10+
root.mkdir()
11+
compose = root / "docker-compose.yaml"
12+
compose.write_text("services: {}\n", encoding="utf-8")
13+
return {
14+
"id": "compose-firecrawl",
15+
"name": "firecrawl",
16+
"root": str(root),
17+
"compose_file": str(compose),
18+
"services": ["api", "rabbitmq"],
19+
"actions": {action: True for action in actions},
20+
"has_build": True,
21+
}
22+
23+
24+
def _control(
25+
monkeypatch,
26+
tmp_path: Path,
27+
*actions: str,
28+
) -> docker_projects.DockerProjectControl:
29+
project = _compose_project(tmp_path, *actions)
30+
monkeypatch.setattr(docker_projects, "_project", lambda _project_id: project)
31+
monkeypatch.setattr(
32+
docker_projects,
33+
"_compose_base",
34+
lambda _root, compose: ["docker", "compose", "-f", str(compose)],
35+
)
36+
return docker_projects.DockerProjectControl(tmp_path / "state")
37+
38+
39+
def test_compose_update_does_not_force_recreate_healthy_dependencies(
40+
monkeypatch,
41+
tmp_path: Path,
42+
) -> None:
43+
control = _control(monkeypatch, tmp_path, "redeploy")
44+
45+
plan, _token = control.create_plan(
46+
project_id="compose-firecrawl",
47+
action="redeploy",
48+
)
49+
50+
redeploy = plan["steps"][-1]
51+
assert redeploy["label"] == "Apply Compose update and wait for readiness"
52+
assert "--force-recreate" not in redeploy["argv"]
53+
assert redeploy["argv"][-4:] == [
54+
"--remove-orphans",
55+
"--wait",
56+
"--wait-timeout",
57+
"300",
58+
]
59+
60+
61+
def test_compose_restart_stops_then_uses_dependency_ordered_start(
62+
monkeypatch,
63+
tmp_path: Path,
64+
) -> None:
65+
control = _control(monkeypatch, tmp_path, "restart")
66+
67+
plan, _token = control.create_plan(
68+
project_id="compose-firecrawl",
69+
action="restart",
70+
)
71+
72+
assert [step["label"] for step in plan["steps"]] == [
73+
"Stop Compose services before ordered restart",
74+
"Start Compose services and wait for readiness",
75+
]
76+
assert "restart" not in plan["steps"][1]["argv"]
77+
assert "--wait" in plan["steps"][1]["argv"]

‎tests/test_ulysses_runtime_management.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,21 @@ def test_firecrawl_lifecycle_operates_the_complete_official_stack(
11541154
assert "USE_DB_AUTHENTICATION=false" in firecrawl_env
11551155
assert "SEARXNG_ENDPOINT=http://host.docker.internal:7070" in firecrawl_env
11561156

1157+
searxng = next(
1158+
runtime
1159+
for runtime in manager.load_runtime_management(
1160+
home=tmp_path,
1161+
services_root=tmp_path / "services",
1162+
)
1163+
if runtime["id"] == "searxng.search"
1164+
)
1165+
searxng_bootstrap = {
1166+
bootstrap["path"].name: bootstrap["content"]
1167+
for bootstrap in searxng["bootstrap_files"]
1168+
}
1169+
assert "SEARXNG_HOST=0.0.0.0" in searxng_bootstrap[".env"]
1170+
assert "${SEARXNG_HOST:-0.0.0.0}" in searxng_bootstrap["docker-compose.yml"]
1171+
11571172

11581173
def test_missing_declared_artifact_reports_incomplete_and_keeps_repair(
11591174
monkeypatch: pytest.MonkeyPatch,

0 commit comments

Comments
 (0)