Skip to content

Commit

Permalink
feat: Use static volume mount destinations instead of parameters. Hav…
Browse files Browse the repository at this point in the history
…e phyto-arm use new config organization
  • Loading branch information
figuernd committed Jan 1, 2025
1 parent 3e8939f commit 8530ef9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
10 changes: 4 additions & 6 deletions configs/example.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Example

docker_image: whoi/phyto-arm:latest
log_dir: /data/roslogs/

processes:
main:
enabled: true
volumes:
log_dir: /data/roslogs/
rosbag_dir: /data/rosbags/
launch_args:
rosbag_dir: /data/rosbags/
rosbag_prefix: phyto-arm
classifier: false
tcp_ports:
Expand All @@ -18,11 +17,10 @@ processes:
enabled: true
launch_args:
ifcb_winch: false
devices:
ctd_path: /dev/ttyS1
volumes:
routines_dir: /home/ifcb/IFCBacquire/Host/Routines
data_dir: /data/ifcbdata
devices:
ctd_path: /dev/ttyS1
arm_chanos:
enabled: false
launch_args:
Expand Down
50 changes: 37 additions & 13 deletions pa
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,41 @@ def get_running_containers(client: docker.DockerClient) -> Dict[str, Container]:
containers = client.containers.list(filters={"name": "phyto-arm-"})
return {c.name.replace('phyto-arm-', ''): c for c in containers}

# This is here to wire up arguments to volume mounts to ROS launch parameters.
# The alternative is to generate a mount automatically and pass the paths as
# arguments to their respective launch files.
def handle_special_volumes_by_process(process_name: str, process_config: dict) -> dict:
volumes = {}
if process_name == "main":
volumes[process_config['launch_args']['rosbag_dir']] = {
"bind": "/app/volumes/rosbags", # Must match launch file
"mode": "rw"
}
if process_name == "arm_ifcb":
volumes[process_config['launch_args']['routines_dir']] = {
"bind": "/app/volumes/routines", # Must match launch file
"mode": "ro"
}
volumes[process_config['launch_args']['data_dir']] = {
"bind": "/app/volumes/ifcbdata", # Must match launch file
"mode": "rw"
}
return volumes

def start_container(
client: docker.DockerClient,
network: docker.models.networks.Network,
config_path: Path,
process_name: str,
process_config: dict,
image_name: str
config: dict
) -> Container:
"""Start a single PhytO-ARM container"""

process_config = config['processes'][process_name]
image_name = config['docker_image']
container_name = f"phyto-arm-{process_name}"
log_dir = config['log_dir']
log_mount = "/app/volumes/roslogs"

# Base volumes that all containers need
volumes = {
Expand All @@ -48,16 +73,16 @@ def start_container(
str(config_path.parent.absolute()): {
"bind": "/app/configs",
"mode": "ro"
},
log_dir: {
"bind": log_mount,
"mode": "rw"
}
}

# Add process-specific volumes
for vol_name, host_path in process_config.get('volumes', {}).items():
Path(host_path).mkdir(parents=True, exist_ok=True)
volumes[host_path] = {
"bind": f"/app/volumes/{vol_name}",
"mode": "rw"
}
special_volumes = handle_special_volumes_by_process(process_name, process_config)
volumes.update(special_volumes)

# Handle devices
devices = [
Expand Down Expand Up @@ -85,7 +110,8 @@ def start_container(
"ports": ports,
"environment": {
"DONT_SCREEN": "1", # screen is not needed within containers
"ROS_MASTER_URI": "http://phyto-arm-main:11311"
"ROS_MASTER_URI": "http://phyto-arm-main:11311",
"ROS_LOG_DIR": log_mount
}
}

Expand Down Expand Up @@ -143,8 +169,7 @@ def start_processes(config_path: Path, process_names: Optional[list[str]] = None
# Always start main first if it's in the list
if 'main' in processes:
start_container(
client, network, config_path, 'main',
processes['main'], config['docker_image']
client, network, config_path, 'main', config
)

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

# If process is not enabled in the config, but was requested, print a warning
Expand Down
9 changes: 7 additions & 2 deletions phyto-arm
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ def prep_roslaunch(config, env, package, launchfile):
]
rl_args.append(f'config_file:={os.path.abspath(args.config)}')

for launch_arg, value in config.get('launch_args', {}).items():
# Get process-specific launch args if they exist
process_config = config.get('processes', {}).get(args.launch_name, {})
launch_args = process_config.get('launch_args', {})

# Add any process-specific launch args
for launch_arg, value in launch_args.items():
rl_args.append(f'{launch_arg}:={value}')

# Allow the config to set a launch prefix (like gdb) for nodes. We have to
# use an environment variable for this because roslaunch will error if an
# argument is unset, while an environment variable is option.
launch_prefix = config.get('launch_args', {}).get('launch_prefix')
launch_prefix = launch_args.get('launch_prefix')
if launch_prefix is not None:
env = dict(env) # copy first
env['LAUNCH_PREFIX'] = launch_prefix
Expand Down
4 changes: 2 additions & 2 deletions src/phyto_arm/launch/arm_ifcb.launch
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<rosparam command="load" file="$(arg config_file)" />

<node name="ifcb" pkg="ifcb" type="ifcb">
<param name="routines_dir" value="$(arg routines_dir)" />
<param name="data_dir" value="$(arg data_dir)" />
<param name="routines_dir" value="/app/volumes/routines" />
<param name="data_dir" value="/app/volumes/ifcbdata" />
</node>

<node name="ifcb_logfilter" pkg="ifcb" type="ifcb_logfilter" />
Expand Down
2 changes: 1 addition & 1 deletion src/phyto_arm/launch/rosbag.launch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In the future, we might process inactive rosbags to, for example, correct
timestamps, or generate reports. See http://wiki.ros.org/rosbag/Cookbook
-->
<launch>
<arg name="rosbag_dir" default="/data/rosbags/" />
<arg name="rosbag_dir" default="/app/volumes/rosbags/" />
<arg name="rosbag_prefix" default="phyto-arm" />
<arg name="rosbag_size" default="1024" />
<arg name="rosbag_duration" default="60m" />
Expand Down

0 comments on commit 8530ef9

Please sign in to comment.