Lab 2: PostgreSQL storage and Redis sessions
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""Restart the complete lab stack; keep volumes and record actual start times."""
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SERVICES = ["api", "postgres", "redis"]
|
||||
|
||||
|
||||
def snapshot(filename):
|
||||
ids = subprocess.check_output(
|
||||
["docker", "compose", "ps", "--all", "-q", *SERVICES], cwd=ROOT, text=True
|
||||
).split()
|
||||
if len(ids) != 3:
|
||||
raise RuntimeError("Expected one api, postgres and redis container")
|
||||
template = ('{{index .Config.Labels "com.docker.compose.service"}} '
|
||||
'{{.Id}} {{.State.StartedAt}} {{.State.Status}}')
|
||||
lines = subprocess.check_output(
|
||||
["docker", "inspect", "--format", template, *ids], cwd=ROOT, text=True
|
||||
)
|
||||
(ROOT / "evidence").mkdir(exist_ok=True)
|
||||
(ROOT / "evidence" / filename).write_text(lines, encoding="utf-8")
|
||||
|
||||
|
||||
def main():
|
||||
snapshot("restart-before.txt")
|
||||
subprocess.run(["docker", "compose", "stop", *SERVICES], cwd=ROOT, check=True, timeout=45)
|
||||
subprocess.run(["docker", "compose", "up", "-d", "--wait", "api"],
|
||||
cwd=ROOT, check=True, timeout=40)
|
||||
snapshot("restart-after.txt")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user