forked from TheCacophonyProject/cacophony-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·84 lines (76 loc) · 1.9 KB
/
run
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
76
77
78
79
80
81
82
83
84
#!/usr/bin/python3
import argparse
import os
import subprocess
IMAGE_NAME = "cacophony-api"
CONTAINER_NAME = "cacophony-api"
parser = argparse.ArgumentParser(
description="Run cacophony API server inside a Docker container"
)
parser.add_argument(
"--isolate",
default=False,
action="store_true",
help="Re-install npm dependencies, don't restart server when code changes",
)
parser.add_argument(
"--background",
default=False,
action="store_true",
help="Run container in background & don't show container logs",
)
args = parser.parse_args()
print("Stopping $container_name container (if running)")
subprocess.call(
["sudo", "docker", "rm", "--force", CONTAINER_NAME],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)
print("Building the container")
subprocess.check_call(["sudo", "docker", "build", ".", "-t", IMAGE_NAME])
print("Starting container")
run_cmd = [
"sudo",
"docker",
"run",
"-td",
"--rm",
"--name",
CONTAINER_NAME,
"-p",
"1080:1080",
"-p",
"2008:2008",
"-p",
"9001:9001",
"-p",
"5400:5432",
"--volume",
os.getcwd() + ":/app",
]
if args.isolate:
run_cmd.extend(
[
"-e",
"ISOLATE=1", # copy code to a separate location & run "npm install"
"--volume",
"/app/node_modules", # don't pass node_modules directory through
"-e",
"NODE_BIN=node", # use node to run the server
]
)
else:
run_cmd.extend(
[
"-e",
"NODE_BIN=nodemon", # use nodemon to restart the server when the code changes
]
)
run_cmd.append(IMAGE_NAME)
subprocess.check_call(run_cmd)
if not args.background:
print("\nShowing container logs")
try:
subprocess.call(["sudo", "docker", "logs", "--follow", CONTAINER_NAME])
except (KeyboardInterrupt, PermissionError):
pass