-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_local.py
64 lines (51 loc) · 1.33 KB
/
start_local.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import platform
import subprocess
import sys
from time import sleep
import requests
BURGER_GRAPHQL_HOSTNAME = "burger.local"
def hasura_is_available() -> bool:
try:
return (
requests.get(f"http://{BURGER_GRAPHQL_HOSTNAME}:8080/healthz").status_code
== 200
)
except Exception:
return False
hosts_file = (
"C:/Windows/System32/drivers/etc/hosts"
if platform.system() == "Windows"
else "/etc/hosts"
)
with open(hosts_file, "r") as hosts:
hosts_content = hosts.read()
missing = [
hostname
for hostname in [BURGER_GRAPHQL_HOSTNAME, "social.local"]
if hostname not in hosts_content
]
if missing:
sys.exit(
f"Missing hostnames: [{', '.join(missing)}]. Please add these to [{hosts_file}] before continuing."
)
subprocess.run(["docker", "compose", "up", "-d", "--build"])
attempt = 1
while not hasura_is_available():
print(f"Waiting for Hasura to be available; attempt [{attempt}]...")
sleep(10)
attempt += 1
del attempt
print("Hasura is up.")
os.chdir(os.path.join(os.path.dirname(__file__), "burger-joint-resources", "hasura"))
subprocess.run(
[
"hasura",
"seed",
"apply",
"--database-name",
"hasura",
"--admin-secret",
os.getenv("GRAPHQL_ADMIN_SECRET"), # type: ignore
]
)