Skip to content

Commit 8530ef9

Browse files
committed
feat: Use static volume mount destinations instead of parameters. Have phyto-arm use new config organization
1 parent 3e8939f commit 8530ef9

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

Diff for: configs/example.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name: Example
22

33
docker_image: whoi/phyto-arm:latest
4+
log_dir: /data/roslogs/
45

56
processes:
67
main:
78
enabled: true
8-
volumes:
9-
log_dir: /data/roslogs/
10-
rosbag_dir: /data/rosbags/
119
launch_args:
10+
rosbag_dir: /data/rosbags/
1211
rosbag_prefix: phyto-arm
1312
classifier: false
1413
tcp_ports:
@@ -18,11 +17,10 @@ processes:
1817
enabled: true
1918
launch_args:
2019
ifcb_winch: false
21-
devices:
22-
ctd_path: /dev/ttyS1
23-
volumes:
2420
routines_dir: /home/ifcb/IFCBacquire/Host/Routines
2521
data_dir: /data/ifcbdata
22+
devices:
23+
ctd_path: /dev/ttyS1
2624
arm_chanos:
2725
enabled: false
2826
launch_args:

Diff for: pa

+37-13
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,41 @@ def get_running_containers(client: docker.DockerClient) -> Dict[str, Container]:
2828
containers = client.containers.list(filters={"name": "phyto-arm-"})
2929
return {c.name.replace('phyto-arm-', ''): c for c in containers}
3030

31+
# This is here to wire up arguments to volume mounts to ROS launch parameters.
32+
# The alternative is to generate a mount automatically and pass the paths as
33+
# arguments to their respective launch files.
34+
def handle_special_volumes_by_process(process_name: str, process_config: dict) -> dict:
35+
volumes = {}
36+
if process_name == "main":
37+
volumes[process_config['launch_args']['rosbag_dir']] = {
38+
"bind": "/app/volumes/rosbags", # Must match launch file
39+
"mode": "rw"
40+
}
41+
if process_name == "arm_ifcb":
42+
volumes[process_config['launch_args']['routines_dir']] = {
43+
"bind": "/app/volumes/routines", # Must match launch file
44+
"mode": "ro"
45+
}
46+
volumes[process_config['launch_args']['data_dir']] = {
47+
"bind": "/app/volumes/ifcbdata", # Must match launch file
48+
"mode": "rw"
49+
}
50+
return volumes
51+
3152
def start_container(
3253
client: docker.DockerClient,
3354
network: docker.models.networks.Network,
3455
config_path: Path,
3556
process_name: str,
36-
process_config: dict,
37-
image_name: str
57+
config: dict
3858
) -> Container:
3959
"""Start a single PhytO-ARM container"""
60+
61+
process_config = config['processes'][process_name]
62+
image_name = config['docker_image']
4063
container_name = f"phyto-arm-{process_name}"
64+
log_dir = config['log_dir']
65+
log_mount = "/app/volumes/roslogs"
4166

4267
# Base volumes that all containers need
4368
volumes = {
@@ -48,16 +73,16 @@ def start_container(
4873
str(config_path.parent.absolute()): {
4974
"bind": "/app/configs",
5075
"mode": "ro"
76+
},
77+
log_dir: {
78+
"bind": log_mount,
79+
"mode": "rw"
5180
}
5281
}
5382

5483
# Add process-specific volumes
55-
for vol_name, host_path in process_config.get('volumes', {}).items():
56-
Path(host_path).mkdir(parents=True, exist_ok=True)
57-
volumes[host_path] = {
58-
"bind": f"/app/volumes/{vol_name}",
59-
"mode": "rw"
60-
}
84+
special_volumes = handle_special_volumes_by_process(process_name, process_config)
85+
volumes.update(special_volumes)
6186

6287
# Handle devices
6388
devices = [
@@ -85,7 +110,8 @@ def start_container(
85110
"ports": ports,
86111
"environment": {
87112
"DONT_SCREEN": "1", # screen is not needed within containers
88-
"ROS_MASTER_URI": "http://phyto-arm-main:11311"
113+
"ROS_MASTER_URI": "http://phyto-arm-main:11311",
114+
"ROS_LOG_DIR": log_mount
89115
}
90116
}
91117

@@ -143,8 +169,7 @@ def start_processes(config_path: Path, process_names: Optional[list[str]] = None
143169
# Always start main first if it's in the list
144170
if 'main' in processes:
145171
start_container(
146-
client, network, config_path, 'main',
147-
processes['main'], config['docker_image']
172+
client, network, config_path, 'main', config
148173
)
149174

150175
# Wait for ROS master to start
@@ -157,8 +182,7 @@ def start_processes(config_path: Path, process_names: Optional[list[str]] = None
157182
for name, process_config in processes.items():
158183
if process_config.get('enabled', True):
159184
start_container(
160-
client, network, config_path, name,
161-
process_config, config['docker_image']
185+
client, network, config_path, name, config
162186
)
163187

164188
# If process is not enabled in the config, but was requested, print a warning

Diff for: phyto-arm

+7-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,18 @@ def prep_roslaunch(config, env, package, launchfile):
6565
]
6666
rl_args.append(f'config_file:={os.path.abspath(args.config)}')
6767

68-
for launch_arg, value in config.get('launch_args', {}).items():
68+
# Get process-specific launch args if they exist
69+
process_config = config.get('processes', {}).get(args.launch_name, {})
70+
launch_args = process_config.get('launch_args', {})
71+
72+
# Add any process-specific launch args
73+
for launch_arg, value in launch_args.items():
6974
rl_args.append(f'{launch_arg}:={value}')
7075

7176
# Allow the config to set a launch prefix (like gdb) for nodes. We have to
7277
# use an environment variable for this because roslaunch will error if an
7378
# argument is unset, while an environment variable is option.
74-
launch_prefix = config.get('launch_args', {}).get('launch_prefix')
79+
launch_prefix = launch_args.get('launch_prefix')
7580
if launch_prefix is not None:
7681
env = dict(env) # copy first
7782
env['LAUNCH_PREFIX'] = launch_prefix

Diff for: src/phyto_arm/launch/arm_ifcb.launch

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<rosparam command="load" file="$(arg config_file)" />
44

55
<node name="ifcb" pkg="ifcb" type="ifcb">
6-
<param name="routines_dir" value="$(arg routines_dir)" />
7-
<param name="data_dir" value="$(arg data_dir)" />
6+
<param name="routines_dir" value="/app/volumes/routines" />
7+
<param name="data_dir" value="/app/volumes/ifcbdata" />
88
</node>
99

1010
<node name="ifcb_logfilter" pkg="ifcb" type="ifcb_logfilter" />

Diff for: src/phyto_arm/launch/rosbag.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In the future, we might process inactive rosbags to, for example, correct
88
timestamps, or generate reports. See http://wiki.ros.org/rosbag/Cookbook
99
-->
1010
<launch>
11-
<arg name="rosbag_dir" default="/data/rosbags/" />
11+
<arg name="rosbag_dir" default="/app/volumes/rosbags/" />
1212
<arg name="rosbag_prefix" default="phyto-arm" />
1313
<arg name="rosbag_size" default="1024" />
1414
<arg name="rosbag_duration" default="60m" />

0 commit comments

Comments
 (0)