Skip to content

Commit

Permalink
Add template changes
Browse files Browse the repository at this point in the history
  • Loading branch information
apockill committed Dec 12, 2024
1 parent 244ec9d commit 2b62189
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/UrbanMachine/create-ros-app.git",
"commit": "3d4731e5661e8cbac11d71c60c8e925a989c150c",
"commit": "93e541631403e2c2c091c65d6583d61bd85a472c",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ services:
DISPLAY: $DISPLAY
# Necessary for PulseAudio passthrough
PULSE_SERVER: "unix:/pulse-socket"
# Enable serial passthrough
privileged: true
# Gives the container access to kernel capabilities, useful for most robots
network_mode: host
cap_add:
Expand Down
23 changes: 23 additions & 0 deletions docker/_shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,27 @@ function deploy_and_wait {
done
echo "Another process brought down the stack." >&2
return 1
}

# Shows the user the available launch profiles
function launch_profiles_helper_msg {
echo "Available launch profiles are:" >&2
# shellcheck disable=SC2012
ls -1 launch-profiles/ | sed 's/^/ - /' >&2
echo "" >&2
echo "Read more about 'launch-profiles' under 'docs/about_template.md'" >&2
exit 1
}

# Inform the user that the chosen launch profile is invalid if it is not a directory
function validate_launch_profile {
local chosen_profile
chosen_profile="$1"

# Check if the chosen profile is a directory under 'launch-profiles'
if [[ ! -d "launch-profiles/${chosen_profile}" ]]; then
echo "Error: '${chosen_profile}' is not a valid launch profile." >&2
echo "It should be a directory under 'launch-profiles/'." >&2
launch_profiles_helper_msg
fi
}
13 changes: 4 additions & 9 deletions docker/launch
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ set -o errexit
set -o pipefail
set -o nounset

source docker/_shared.sh

function usage {
echo "Usage: docker/launch [--no-pull] <launch-profile>" >&2
echo "Available launch profiles are:" >&2
# shellcheck disable=SC2012
ls -1 launch-profiles/ | sed 's/^/ - /' >&2
echo "" >&2
echo "Read more about 'launch-profiles' under 'docs/about_template.md'" >&2
exit 1
launch_profiles_helper_msg
}

function main {
Expand Down Expand Up @@ -64,9 +61,7 @@ function main {
echo "Missing <launch_profile> argument, specify a directory under 'launch-profiles/'" >&2
usage
fi

source docker/_shared.sh

validate_launch_profile "${launch_profile}"

# To reduce downtime, build the latest images before stopping any existing stacks.
if [[ "${pull_upstream_images}" = true ]]; then
Expand Down
37 changes: 37 additions & 0 deletions docker/reload-ros-nodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Builds and re-runs the ROS nodes container. This is useful if you want to restart
# the container over and over, oftentimes when developing on you ROS code.
# The container is only re-run if the image has changed.
#
# Usage:
# docker/reload-ros-nodes <launch-profile>
#
# Examples:
# docker/reload-ros-nodes node_helpers_showcase

set -o errexit
set -o pipefail
set -o nounset

source docker/_shared.sh

function main {
local launch_profile
launch_profile="${1:-}"

if [[ -z "${launch_profile}" ]]; then
echo "Missing <launch_profile> argument, specify a directory under 'launch-profiles/'" >&2
echo "Usage: docker/reload-ros-nodes <launch-profile>" >&2
launch_profiles_helper_msg
fi
validate_launch_profile "${launch_profile}"

build_images # Build any images that need to be built
enable_display_passthrough # Enable passthrough for the stack

export LAUNCH_PROFILE="${launch_profile}"
docker compose up -d --force-recreate ros-nodes
}

main "${@}"
3 changes: 3 additions & 0 deletions docs/about_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Here's a quick guide on the features of this template

# Enter a currently running ROS container to poke around
docker/exec

# Rebuild and restart the ROS nodes in the container, useful for fast development
docker/reload-ros-nodes
```

More usage examples for the above scripts are documented at the top of the script files.
Expand Down

0 comments on commit 2b62189

Please sign in to comment.