Files
mtusi2026lab7/scripts/start.py
T

43 lines
1.6 KiB
Python

from pathlib import Path
import subprocess
import sys
import ssl
import time
from urllib.error import URLError
from urllib.request import urlopen
ROOT = Path(__file__).resolve().parents[1]
def run(*args):
subprocess.run(args, cwd=ROOT, check=True, timeout=300)
if __name__ == "__main__":
run(sys.executable, "scripts/setup.py")
run(sys.executable, "scripts/security_setup.py")
run("docker", "compose", "build", "migrate")
run("docker", "compose", "up", "-d", "db", "cache", "broker", "s3", "s3-tls",
"cache-tls", "broker-tls", "openbao")
run("docker", "compose", "up", "-d", "--no-deps", "--force-recreate",
"s3-tls", "cache-tls", "broker-tls")
run(sys.executable, "scripts/bao_operator.py")
run("docker", "compose", "run", "--rm", "migrate")
run(sys.executable, "scripts/apply_roles.py")
run("docker", "compose", "up", "-d", "--wait", "--wait-timeout", "120")
run("docker", "compose", "up", "-d", "--no-deps", "--force-recreate",
"api-a-tls", "api-b-tls", "otel-collector-tls-otlp",
"otel-collector-tls-scrape", "prometheus-tls", "loki-tls",
"tempo-tls-query", "tempo-tls-otlp")
context = ssl.create_default_context(cafile=str(ROOT / "secrets/operator/ca.pem"))
deadline = time.monotonic() + 30
while True:
try:
with urlopen("https://localhost:18443/health/ready", context=context, timeout=3):
break
except URLError:
if time.monotonic() >= deadline:
raise
time.sleep(0.5)
print("HTTPS stack is ready")