-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_compose.py
95 lines (80 loc) · 2.9 KB
/
build_compose.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import argparse
import pathlib
import yaml
thisdir = pathlib.Path(__file__).resolve().parent
ROS_IMAGE = "smile_ros"
def get_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument(
"--num-robots",
type=int, required=True,
help="Number of robots in system"
)
return parser
def main():
parser = get_parser()
args = parser.parse_args()
dockerfile = {
"version": "3",
"services": {}
}
build_commands = ["colcon build", ". ./install/setup.sh"]
all_nodes_str = ",".join([f"node_{j}" for j in range(1, args.num_robots+1)])
scheduler_commands = [*build_commands, "ros2 run gcnsched_demo scheduler"]
dockerfile["services"]["scheduler"] = {
"image": ROS_IMAGE,
"volumes": [
f'{thisdir.joinpath(".workspaces/scheduler")}:/workspace',
f'{thisdir.joinpath("src")}:/workspace/src:ro'
],
"environment": {
"PYTHONUNBUFFERED": 1,
"ALL_NODES": all_nodes_str
},
"command": f'bash -c "{" && ".join(scheduler_commands)}"'
}
rosboard_commands = [*build_commands, "/rosboard/run"]
dockerfile["services"]["rosboard"] = {
"image": "rosboard",
"volumes": [
f'{thisdir.joinpath(".workspaces/rosboard")}:/workspace',
f'{thisdir.joinpath("src")}:/workspace/src:ro'
],
"environment": {
"PYTHONUNBUFFERED": 1
},
"ports": ["9999:8888"],
"command": f'bash -c "{" && ".join(rosboard_commands)}"'
}
for i in range(1, args.num_robots+1):
executor_commands = [*build_commands, "ros2 run gcnsched_demo executor"]
dockerfile["services"][f"executor_{i}"] = {
"image": ROS_IMAGE,
"volumes": [
f'{thisdir.joinpath(f".workspaces/executor_{i}")}:/workspace',
f'{thisdir.joinpath("src")}:/workspace/src:ro'
],
"environment": {
"PYTHONUNBUFFERED": 1,
"ALL_NODES": all_nodes_str,
"NODE_NAME": f"node_{i}"
},
"command": f'bash -c "{" && ".join(executor_commands)}"'
}
bandwidth_commands = [*build_commands, "ros2 run gcnsched_demo bandwidth"]
dockerfile["services"][f"bandwidth_{i}"] = {
"image": ROS_IMAGE,
"volumes": [
f'{thisdir.joinpath(f".workspaces/bandwidth_{i}")}:/workspace',
f'{thisdir.joinpath("src")}:/workspace/src:ro'
],
"environment": {
"PYTHONUNBUFFERED": 1,
"ALL_NODES": all_nodes_str,
"NODE_NAME": f"node_{i}"
},
"command": f'bash -c "{" && ".join(bandwidth_commands)}"'
}
thisdir.joinpath("docker-compose.yml").write_text(yaml.dump(dockerfile))
if __name__ == "__main__":
main()