Собрать стенд lab3: балансировка, идемпотентность и трек 1
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def compose(*args, check=True, input_bytes=None, timeout=180):
|
||||
proc = subprocess.run(
|
||||
["docker", "compose", "--env-file", ".env", *args],
|
||||
cwd=ROOT,
|
||||
input=input_bytes,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=timeout,
|
||||
check=False,
|
||||
)
|
||||
if check and proc.returncode != 0:
|
||||
err = proc.stderr.decode("utf-8", "replace")[-800:]
|
||||
raise RuntimeError(err or "docker compose failed")
|
||||
return proc
|
||||
|
||||
|
||||
def psql(sql, timeout=180):
|
||||
proc = compose(
|
||||
"exec",
|
||||
"-T",
|
||||
"postgres",
|
||||
"psql",
|
||||
"-U",
|
||||
"messenger",
|
||||
"-d",
|
||||
"messenger",
|
||||
"-v",
|
||||
"ON_ERROR_STOP=1",
|
||||
"-q",
|
||||
"-t",
|
||||
"-A",
|
||||
input_bytes=sql.encode("utf-8"),
|
||||
timeout=timeout,
|
||||
)
|
||||
return proc.stdout.decode("utf-8").strip()
|
||||
Reference in New Issue
Block a user