diff --git a/docker-compose-common.yaml b/docker-compose-common.yaml index 5921b7cd..cb5e483d 100644 --- a/docker-compose-common.yaml +++ b/docker-compose-common.yaml @@ -250,6 +250,9 @@ services: - XAUTHORITY=/tmp/.docker.xauth - NVIDIA_DRIVER_CAPABILITIES=compute,graphics,utility,video,display - NVIDIA_VISIBLE_DEVICES=all + - HOST_UID + - HOST_GID + - HOST_TZ - ROS_LOG_DIR - CABOT_ROSBAG_BACKEND - CABOT_ROSBAG_COMPRESSION diff --git a/docker/bag/Dockerfile b/docker/bag/Dockerfile index e545664c..d3a6b511 100644 --- a/docker/bag/Dockerfile +++ b/docker/bag/Dockerfile @@ -124,6 +124,7 @@ ARG ROS_DISTRO RUN apt update && \ apt install -y --no-install-recommends \ + gosu \ ros-$ROS_DISTRO-dwb-msgs \ ros-$ROS_DISTRO-rosbridge-msgs \ ros-$ROS_DISTRO-nav2-msgs \ @@ -151,17 +152,14 @@ COPY ros_entrypoint.sh /ros_entrypoint.sh RUN sed -i 's:custom_ws:underlay_ws:' /ros_entrypoint.sh RUN chmod +x /ros_entrypoint.sh -USER $USERNAME - ENV HOME /home/$USERNAME WORKDIR $HOME/bag_ws - -RUN mkdir -p $HOME/bag_ws/script +RUN chown -R $USERNAME:$USERNAME $HOME/bag_ws COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-navigation/docker/ros2/launch.sh / -COPY --from=build $HOME/bag_ws/install $HOME/bag_ws/install +COPY --chown=$USERNAME:$USERNAME --from=build $HOME/bag_ws/install $HOME/bag_ws/install COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-navigation/script /home/developer/bag_ws/script CMD [ "/launch.sh record" ] diff --git a/docker/bag/ros_entrypoint.sh b/docker/bag/ros_entrypoint.sh index 0bc7167a..82ab20e1 100755 --- a/docker/bag/ros_entrypoint.sh +++ b/docker/bag/ros_entrypoint.sh @@ -24,10 +24,33 @@ set -e +# Default values +HOST_UID=${HOST_UID:-1000} +HOST_GID=${HOST_GID:-1000} +HOST_TZ=${HOST_TZ:-UTC} + +if [[ $TZ != $HOST_TZ ]]; then + # Setting up timezone + sudo ln -snf /usr/share/zoneinfo/$HOST_TZ /etc/localtime + echo $HOST_TZ | sudo tee /etc/timezone + export TZ=$HOST_TZ +fi + +CONT_UID=$(id -u developer) +CONT_GID=$(id -g developer) +if [[ $CONT_UID -ne $HOST_UID ]] || [[ $CONT_GID -ne $HOST_GID ]]; then + # Update user and group ID to match host + sudo usermod -u $HOST_UID developer + sudo groupmod -g $HOST_GID developer +fi + +# Source ROS setup script if [[ -e /home/developer/bag_ws/install/setup.bash ]]; then source "/home/developer/bag_ws/install/setup.bash" else source /opt/custom_ws/install/setup.bash fi -exec "$@" +WORKDIR=$(pwd) + +exec gosu developer bash -c "cd $WORKDIR && exec $*"