diff --git a/README.md b/README.md index e9bca3d..14d11eb 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,28 @@ arm-cli --help ``` You can also use: - ```bash python -m arm_cli --help ``` + +### Container Management +The CLI includes tools for managing Docker containers: + +```bash +# List running containers +arm-cli container list + +# Attach to a container interactively (sources ROS and interactive entrypoints) +arm-cli container attach + +# Restart a container +arm-cli container restart + +# Stop a container +arm-cli container stop +``` + +For more details on container compliance, see [arm_cli/container/readme.md](arm_cli/container/readme.md). ## Development To contribute to this tool, first checkout the code. Then create a new virtual environment. From the root of the repo: diff --git a/arm_cli/container/container.py b/arm_cli/container/container.py index da30101..e8e01fb 100644 --- a/arm_cli/container/container.py +++ b/arm_cli/container/container.py @@ -63,8 +63,20 @@ def attach_container(ctx): print(f"Attaching to {selected_container_name}...") + cmd = """ + if [ -f /ros_entrypoint.sh ]; then + source /ros_entrypoint.sh + fi + if [ -f /interactive_entrypoint.sh ]; then + source /interactive_entrypoint.sh + fi + exec bash + """ + try: - subprocess.run(["docker", "exec", "-it", selected_container_name, "/bin/bash"], check=True) + subprocess.run( + ["docker", "exec", "-it", selected_container_name, "bash", "-c", cmd], check=True + ) except subprocess.CalledProcessError as e: print(f"Error attaching to container: {e}") except KeyboardInterrupt: diff --git a/arm_cli/container/readme.md b/arm_cli/container/readme.md new file mode 100644 index 0000000..15bc0fd --- /dev/null +++ b/arm_cli/container/readme.md @@ -0,0 +1,40 @@ +Container Compliance for arm-cli + +While not strictly necessary, to work with arm-cli's interactive attach: + +## Entrypoint Scripts + +arm-cli attach will automatically source the following scripts if they exist: + +1. `/ros_entrypoint.sh` - Standard ROS entrypoint script +2. `/interactive_entrypoint.sh` - Custom interactive entrypoint script + +### ROS Entrypoint Script + +Most ROS containers already include `/ros_entrypoint.sh`. This script typically: +- Sets up ROS environment variables +- Sources ROS setup files +- Configures the ROS workspace + +### Interactive Entrypoint Script + +Add /interactive_entrypoint.sh in your image: + +``` +#!/bin/bash +[ -f /opt/ros/$ROS_DISTRO/setup.bash ] && source /opt/ros/$ROS_DISTRO/setup.bash +[ -f /ros2_ws/install/setup.bash ] && source /ros2_ws/install/setup.bash +exec "$@" +``` + +Dockerfile: +``` +COPY interactive_entrypoint.sh /interactive_entrypoint.sh +ENTRYPOINT ["/interactive_entrypoint.sh"] +``` + +Behavior: +arm-cli attach sources both scripts in order if present: +1. First sources `/ros_entrypoint.sh` (if it exists) +2. Then sources `/interactive_entrypoint.sh` (if it exists) +3. Falls back to plain bash if neither exists \ No newline at end of file