-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
75 lines (63 loc) · 2.2 KB
/
test.py
File metadata and controls
75 lines (63 loc) · 2.2 KB
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
65
66
67
68
69
70
71
72
73
74
75
import subprocess
import atexit
import time
import webbrowser
import argparse
import os
import socket
def get_host_ip_address():
"""
Copied from https://stackoverflow.com/a/28950776/11741232
Returns: the local computer's IP address, which tries to not return 127.0.0.1 which is the localhost IP address.
We want this address for the Docker to be able to send messages out to the local computer. Since the Docker
container can't find its hosts IP address easily, we have to pass it in as an environment variable.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(0)
try:
# doesn't even have to be reachable
s.connect(("10.254.254.254", 1))
ip = s.getsockname()[0]
except Exception:
ip = "127.0.0.1"
finally:
s.close()
return ip
def run_and_wait(command, env=None):
process = subprocess.Popen(command, shell=True, env=env)
process.wait()
def post_script_tasks():
run_and_wait("docker compose stop")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Test entire system, locally or via the server"
)
parser.add_argument(
"--local", action="store_true", help="Run in local mode, bypassing the server"
)
args = parser.parse_args()
env = os.environ.copy()
if args.local:
print("Running with docker-compose-local.yml")
docker = "docker compose -f docker-compose-local.yml up --build -d"
env["remote_server"] = "False"
env["host_ip"] = get_host_ip_address()
print(
f"Using host ip address for docker to python communication: {env['host_ip']}"
)
gamergui = "python gamer-gui/main.py --test --local"
else:
docker = "docker compose up --build -d"
env["remote_server"] = "True"
gamergui = "python gamer-gui/main.py --test"
icarus_url = "http://localhost:3000/"
minnie_url = "http://localhost:3001/"
atexit.register(post_script_tasks)
run_and_wait(docker, env=env)
time.sleep(6)
webbrowser.open(icarus_url)
webbrowser.open(minnie_url)
time.sleep(3)
subprocess.Popen(gamergui, shell=True, env=env)
while True:
time.sleep(1)