devcake-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- devcake_cli/__init__.py +10 -0
- devcake_cli/__main__.py +8 -0
- devcake_cli/baker.py +15 -0
- devcake_cli/doctor.py +600 -0
- devcake_cli/down.py +37 -0
- devcake_cli/envfile.py +199 -0
- devcake_cli/main.py +209 -0
- devcake_cli/paths.py +29 -0
- devcake_cli/setup.py +933 -0
- devcake_cli/status.py +75 -0
- devcake_cli/up.py +676 -0
- devcake_cli-0.1.0.dist-info/METADATA +375 -0
- devcake_cli-0.1.0.dist-info/RECORD +17 -0
- devcake_cli-0.1.0.dist-info/WHEEL +5 -0
- devcake_cli-0.1.0.dist-info/entry_points.txt +2 -0
- devcake_cli-0.1.0.dist-info/licenses/LICENSE +674 -0
- devcake_cli-0.1.0.dist-info/top_level.txt +1 -0
devcake_cli/status.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""``devcake status`` — compose project + baker liveness snapshot."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .doctor import check_baker_liveness
|
|
11
|
+
from .paths import require_checkout_root
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _compose_ps(repo: Path) -> tuple[bool, str]:
|
|
15
|
+
try:
|
|
16
|
+
proc = subprocess.run(
|
|
17
|
+
["docker", "compose", "ps", "--format", "json"],
|
|
18
|
+
cwd=str(repo),
|
|
19
|
+
text=True,
|
|
20
|
+
capture_output=True,
|
|
21
|
+
timeout=60,
|
|
22
|
+
)
|
|
23
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
24
|
+
return False, str(exc)
|
|
25
|
+
if proc.returncode != 0:
|
|
26
|
+
# Fallback without --format for older compose
|
|
27
|
+
proc2 = subprocess.run(
|
|
28
|
+
["docker", "compose", "ps"],
|
|
29
|
+
cwd=str(repo),
|
|
30
|
+
text=True,
|
|
31
|
+
capture_output=True,
|
|
32
|
+
timeout=60,
|
|
33
|
+
)
|
|
34
|
+
text = (proc2.stdout or proc2.stderr or "").strip()
|
|
35
|
+
return proc2.returncode == 0, text
|
|
36
|
+
return True, (proc.stdout or "").strip()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def run_status(*, as_json: bool = False, repo: Path | None = None) -> int:
|
|
40
|
+
try:
|
|
41
|
+
root = repo or require_checkout_root()
|
|
42
|
+
except FileNotFoundError as exc:
|
|
43
|
+
sys.stderr.write(f"devcake status: {exc}\n")
|
|
44
|
+
return 3
|
|
45
|
+
|
|
46
|
+
compose_ok, compose_text = _compose_ps(root)
|
|
47
|
+
baker = check_baker_liveness(repo_root=root)
|
|
48
|
+
baker_alive = bool(baker.ok and "alive" in baker.detail and "dead" not in baker.detail)
|
|
49
|
+
# Prefer explicit pid alive wording from check detail.
|
|
50
|
+
if baker.detail.startswith("baker pid ") and "is alive" in baker.detail:
|
|
51
|
+
baker_alive = True
|
|
52
|
+
elif "not expected" in baker.detail or "skipped" in baker.detail:
|
|
53
|
+
baker_alive = False
|
|
54
|
+
|
|
55
|
+
payload = {
|
|
56
|
+
"ok": compose_ok,
|
|
57
|
+
"schema_version": 1,
|
|
58
|
+
"compose_ok": compose_ok,
|
|
59
|
+
"compose": compose_text,
|
|
60
|
+
"baker_alive": baker_alive,
|
|
61
|
+
"baker_detail": baker.detail,
|
|
62
|
+
"checkout": str(root),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if as_json:
|
|
66
|
+
sys.stdout.write(json.dumps(payload, indent=2) + "\n")
|
|
67
|
+
else:
|
|
68
|
+
sys.stdout.write(f"checkout: {root}\n")
|
|
69
|
+
sys.stdout.write(f"compose: {'ok' if compose_ok else 'FAIL'}\n")
|
|
70
|
+
if compose_text:
|
|
71
|
+
sys.stdout.write(compose_text + "\n")
|
|
72
|
+
sys.stdout.write(
|
|
73
|
+
f"baker_alive: {baker_alive} ({baker.detail})\n"
|
|
74
|
+
)
|
|
75
|
+
return 0 if compose_ok else 4
|