From c20f8f474271ed12de64670d53bfd2d3b099211c Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Sun, 29 Sep 2024 19:10:50 -0300 Subject: [PATCH] Use per ROS distro dev containers Signed-off-by: Michel Hidalgo --- docker/docker-compose.yml | 4 ++-- docker/run.sh | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4b877e53b..d22d0b08b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,11 +1,11 @@ -version: "3" services: dev: build: context: .. dockerfile: docker/images/${ROSDISTRO:-humble}/Dockerfile image: ekumenlabs/beluga-${ROSDISTRO:-humble}-dev - container_name: beluga-dev + hostname: beluga-${ROSDISTRO:-humble}-dev + container_name: beluga-${ROSDISTRO:-humble}-dev environment: - DISPLAY - QT_X11_NO_MITSHM=1 diff --git a/docker/run.sh b/docker/run.sh index 769ad4716..c882dd28c 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -66,18 +66,11 @@ while [[ "$1" != "" ]]; do esac done -DEV_CONTAINER_NAME=beluga_dev - # Kill the container JIC it already exists, if building, to ensure we don't attach to an old container. -[[ "$BUILD" = true ]] && docker compose build dev && docker rm -f $DEV_CONTAINER_NAME 2>/dev/null +[[ "$BUILD" = true ]] && docker compose build dev && docker compose rm -fs dev 2>/dev/null -# Check if the container exists -if docker ps -a --format '{{.Names}}' | grep -q $DEV_CONTAINER_NAME; then - # Attach to the container if it is running - echo "Found dev container running, attaching to it..." -else - echo "Container '$DEV_CONTAINER_NAME' does not exist or is not running, proceeding to run it." - PRIVILEGED_CONTAINER=$PRIVILEGED_CONTAINER USERID=$(id -u) GROUPID=$(id -g) docker compose run --rm --detach --name $DEV_CONTAINER_NAME dev -fi +# Start up dev container in the background (a no-op if configuration has not changed). +PRIVILEGED_CONTAINER=$PRIVILEGED_CONTAINER USERID=$(id -u) GROUPID=$(id -g) docker compose up --detach dev -docker exec -it $DEV_CONTAINER_NAME /ros_entrypoint.sh /bin/bash +# Enter shell within dev container. +docker compose exec dev /bin/bash