fix: update env and PR template

This commit is contained in:
TAskMAster339
2026-10-10 22:35:17 +03:00
parent 715f6c4175
commit 18b3627ec8
22 changed files with 450 additions and 77 deletions
+14 -7
View File
@@ -24,6 +24,11 @@ def command(args, **kwargs):
return subprocess.check_output(args, cwd=ROOT, text=True, **kwargs).strip()
def configured_replicas():
config = json.loads(command(COMPOSE + ["config", "--format", "json"]))
return int(config["services"]["api"]["deploy"]["replicas"])
def containers():
return command(COMPOSE + ["ps", "-q", "api"]).split()
@@ -79,8 +84,9 @@ def replace_all():
with ROOT.joinpath(".memory/rolling.lock").open("w") as lock:
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
originals = containers()
if len(originals) != 2:
raise RuntimeError("Exactly two running API replicas are required")
expected = configured_replicas()
if expected < 2 or len(originals) != expected:
raise RuntimeError("All configured API replicas must be running; minimum two")
# One explicit migration job per operation, never one per replica.
# Only backward-compatible migrations may be deployed while API is live.
subprocess.run(
@@ -90,13 +96,14 @@ def replace_all():
for old in originals:
before = containers()
if (
len(before) != 2
or len([row for row in stats() if row["status"].startswith("UP")]) != 2
len(before) != expected
or len([row for row in stats() if row["status"].startswith("UP")]) != expected
):
raise RuntimeError(
"Both replicas must be ready before taking one out of service"
)
survivor = next(container for container in before if container != old)
survivors = set(before) - {old}
info = identity(old)
addresses = {network["IPAddress"] for network in info["networks"].values()}
matches = [row for row in stats() if row["addr"].split(":")[0] in addresses]
@@ -139,16 +146,16 @@ def replace_all():
finally:
runtime(slot, "ready")
after = containers()
if len(after) != 2 or survivor not in after or old in after:
if len(after) != expected or not survivors.issubset(after) or old in after:
raise RuntimeError("Replacement changed the surviving container")
new = next(container for container in after if container != survivor)
new = next(container for container in after if container not in survivors)
new_info = identity(new)
new_addresses = {
network["IPAddress"] for network in new_info["networks"].values()
}
wait_for(
lambda: (
len([row for row in stats() if row["status"].startswith("UP")]) == 2
len([row for row in stats() if row["status"].startswith("UP")]) == expected
and any(
row["addr"].split(":")[0] in new_addresses
and row["status"].startswith("UP")