Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance run_sensors.sh #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dev_radar_compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ services:
privileged: true
command: rosmaster --core
volumes:
- "/etc/localtime:/etc/localtime:ro"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_radar:
image: "av_radar:latest"
Expand Down Expand Up @@ -36,7 +38,8 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/shm:/dev/shm"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"
depends_on:
- ros1_bridge
35 changes: 27 additions & 8 deletions dev_sensors_compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/shm:/dev/shm"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_dbw:
Expand All @@ -15,7 +16,8 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/bus/usb:/dev/bus/usb"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_imu:
Expand All @@ -24,8 +26,8 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/shm:/dev/shm"
- "/dev/imu-6:/dev/imu-6"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_gps:
Expand All @@ -34,7 +36,8 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/shm:/dev/shm"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_ouster:
Expand All @@ -43,7 +46,8 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/shm:/dev/shm"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_velodyne:
Expand All @@ -52,7 +56,8 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/shm:/dev/shm"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_camera:
Expand All @@ -61,8 +66,22 @@ services:
network_mode: "host"
privileged: true
volumes:
- "/dev/shm:/dev/shm"
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"

av_camera_trigger:
image: "av_camera_trigger:latest"
command: sh -c "sleep 13 && ros2 launch av_camera_trigger av_camera_trigger.launch.xml"
container_name: av_camera_trigger
network_mode: "host"
privileged: true
volumes:
- "/dev:/dev"
- "/tmp:/tmp"
- "/etc/localtime:/etc/localtime:ro"
depends_on:
- av_camera

include:
- dev_radar_compose.yaml
99 changes: 95 additions & 4 deletions run_sensors.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,109 @@
#!/bin/bash

help() {
echo "Usage: run_sensors.sh [options] [sensor_list]

Options:
--dev Use the 'dev_sensors_compose.yaml' file
--build Build Docker images for the specified sensors (only valid with --dev)
--build-only Only build Docker images
--no-cache Build Docker images with no cache
-h, --help Show this help message and exit
"
exit 0
}


# Function to handle termination
stop_sensors() {
echo "Caught signal, stopping Docker Compose..."
docker compose -f ./sensors_compose.yaml kill
docker compose -f ./sensors_compose.yaml down
docker compose -f "$compose_file" kill
docker compose -f "$compose_file" down
exit 0
}

# Trap SIGINT and SIGTERM
trap 'stop_sensors' SIGINT SIGTERM

# Start Docker Compose
docker compose -f ./sensors_compose.yaml up &
# Default values
compose_file="./sensors_compose.yaml"
services=""
build_docker=""
is_dev_mode="false"
run_services="true"
build_no_cache=""

while [[ $# -gt 0 ]]; do
case $1 in
--dev)
compose_file="./dev_sensors_compose.yaml"
is_dev_mode="true"
shift
;;
--build)
build_docker="True"
shift
;;
--build-only)
build_docker="True"
run_services="false"
shift
;;
--no-cache)
build_no_cache="--no-cache"
shift
;;
-h|--help)
help
;;
*)
services="$services $1"
shift
;;
esac
done

build_docker_images() {
original_dir=$(pwd) # Save the original directory
for service in $services; do
found=0
# Search recursively for directories matching the service name
for dir in $(find . -type d -name "$service"); do
# Check for Dockerfile in the directory
if [[ -f "$dir/Dockerfile" ]]; then
echo "Building Docker image for $service..."
pushd "$dir" > /dev/null # Change to the directory containing the Dockerfile
docker build $build_no_cache -t "$service:latest" --target runtime .
popd > /dev/null # Return to the original directory
found=1
break
fi
done
# If no matching Dockerfile or directory is found
if [[ $found -eq 0 ]]; then
echo "No directory or Dockerfile found for $service."
fi
done
}

# Only build Docker images if --dev is specified
if [ "$is_dev_mode" == "true" ] && [ -n "$build_docker" ]; then
if [ -n "$services" ]; then
build_docker_images
else
echo "No services specified for building."
exit 1
fi
fi

if [ "$run_services" == "true" ]; then
# Start Docker Compose with optional services
if [ -n "$services" ]; then
docker compose -f "$compose_file" up $services &
else
docker compose -f "$compose_file" up &
fi
fi

# Wait for Docker Compose to finish
wait $!