-
Notifications
You must be signed in to change notification settings - Fork 14
/
deploy-code
executable file
·72 lines (59 loc) · 3.1 KB
/
deploy-code
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
#!/usr/bin/env python3
import os
import argparse
import subprocess
from utils import yes_no
CURRENT_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
# parameters
BINARIES = ["KidSize", "rhio", "rhal"]
BLACK_LIST = ["libpthread.", "libdl-", "libdl.", "librt.", "libopenvino"]
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="deploy-code", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("remote", nargs="?", help="Remote address", default="10.0.0.1")
parser.add_argument("-d", "--deploy_dir", help="Deploy directory", default=".deploy")
parser.add_argument("-b", "--bin_dir", help="Binary directory", default=CURRENT_FILE_DIR + "/build/bin")
parser.add_argument("-e", "--exported_binaries", nargs="+", help="Binaries to be export", default=[])
parser.add_argument("-t", "--target_dir", help="Target directory", default="/home/rhoban/binaries")
args = parser.parse_args()
args.exported_binaries += BINARIES
cmake_cache = open("build/CMakeCache.txt", "r")
cmake_cache_lines = cmake_cache.read().split("\n")
cmake_cache.close()
if len(list(filter(lambda l: l.startswith("CMAKE_BUILD_TYPE:STRING=Release"), cmake_cache_lines))) != 1:
if not yes_no("WARNING: It appear that you didn't build in RELEASE mode, deploy anyway? "):
exit(1)
if not os.path.exists(args.deploy_dir):
os.mkdir(args.deploy_dir)
# Killing server on host
print("* Killing KidSize on " + args.remote)
os.system(f"ssh rhoban@{args.remote} ./env/stop.sh")
# Scan binaries and add shared libraries
for binary in args.exported_binaries:
if os.path.exists(f"{args.bin_dir}/{binary}"):
print(f"Add {binary}")
# symlink each binary in the deploy dir
if not os.path.islink(f"{args.deploy_dir}/{binary}"):
# print(f"PATH: {args.deploy_dir}/{binary}")
os.symlink(f"{args.bin_dir}/{binary}", f"{args.deploy_dir}/{binary}")
# search all shared library and symlink them in the deploy dir
output = subprocess.check_output(f'ldd {args.bin_dir}/{binary} | grep -iv "Not found"', shell=True).splitlines()
for l in output:
l = l.decode("utf-8")
index = l.find("=> /")
if index == -1:
continue
shared_lib_path = l[index + 3 :].split(" ")[0]
shared_lib_name = shared_lib_path.split("/")[-1]
ignore = False
black_list_used = BLACK_LIST
for prefix in black_list_used:
if shared_lib_name.startswith(prefix):
ignore = True
if ignore:
print(f"Ignore {l}")
else:
if not os.path.exists(f"{args.deploy_dir}/{shared_lib_name}"):
os.symlink(f"{shared_lib_path}", f"{args.deploy_dir}/{shared_lib_name}")
# Deploying
print("* Sending files...\n")
os.system(f"rsync --delete -avzhL --info=flist2,name,progress {args.deploy_dir}/ rhoban@{args.remote}:{args.target_dir}")