Skip to content

Commit

Permalink
fix dockerfile to set host UID, GID, time zone
Browse files Browse the repository at this point in the history
DCO 1.1 Signed-off-by: Tatsuya Ishihara <[email protected]>
  • Loading branch information
tatsuya-ishihara committed Dec 19, 2024
1 parent 1b296d2 commit 241c003
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docker-compose-bag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ services:
extends:
file: docker-compose-common.yaml
service: bag-dev
volumes:
- ./docker/home:/home/developer/
profiles:
- build

Expand Down
5 changes: 4 additions & 1 deletion docker-compose-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ services:
- XAUTHORITY=/tmp/.docker.xauth
- NVIDIA_DRIVER_CAPABILITIES=compute,graphics,utility,video,display
- NVIDIA_VISIBLE_DEVICES=all
- HOST_UID
- HOST_GID
- HOST_TZ
- CABOT_ROSBAG_BACKEND
- CABOT_ROSBAG_COMPRESSION
- CABOT_ROSBAG_RECORD_CAMERA
Expand Down Expand Up @@ -334,7 +337,7 @@ services:
- ./cabot-drivers/motor_controller:/home/developer/bag_ws/src/motor_controller
- ./cabot-drivers/docker/driver/ros_odrive/odrive_base:/home/developer/bag_ws/src/ros_odrive/odrive_base
- ./cabot-drivers/docker/driver/ros_odrive/odrive_node:/home/developer/bag_ws/src/ros_odrive/odrive_node
- ./cabot-drivers/power_controller/power_controller_kx/power_controller_msgs:/home/developer/bag_ws/src/power_controller_msgs
- ./cabot-drivers/power_controller/power_controller_msgs:/home/developer/bag_ws/src/power_controller/power_controller_msgs
- ./cabot-navigation/script:/home/developer/bag_ws/script
- ./cabot-navigation/mf_localization_msgs:/home/developer/bag_ws/src/mf_localization_msgs
- ./cabot-navigation/mf_localization_rviz:/home/developer/bag_ws/src/mf_localization_rviz
Expand Down
12 changes: 7 additions & 5 deletions docker/bag/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ RUN apt update && \
ros-$ROS_DISTRO-dwb-msgs \
ros-$ROS_DISTRO-rosbridge-msgs \
ros-$ROS_DISTRO-nav2-msgs \
nlohmann-json3-dev \
&& \
rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -90,6 +91,9 @@ COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-common/cabot_msgs /hom
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-common/cabot_common /home/developer/bag_ws/src/cabot_common
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot_debug /home/developer/bag_ws/src/cabot_debug
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-drivers/motor_controller /home/developer/bag_ws/src/motor_controller
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-drivers/docker/driver/ros_odrive/odrive_base /home/developer/bag_ws/src/ros_odrive/odrive_base
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-drivers/docker/driver/ros_odrive/odrive_node /home/developer/bag_ws/src/ros_odrive/odrive_node
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-drivers/power_controller/power_controller_msgs /home/developer/bag_ws/src/power_controller/power_controller_msgs
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-navigation/script /home/developer/bag_ws/script
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-navigation/mf_localization_msgs /home/developer/bag_ws/src/mf_localization_msgs
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-navigation/mf_localization_rviz /home/developer/bag_ws/src/mf_localization_rviz
Expand Down Expand Up @@ -124,6 +128,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 \
Expand Down Expand Up @@ -151,17 +156,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 $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" ]
25 changes: 24 additions & 1 deletion docker/bag/ros_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $*"
3 changes: 2 additions & 1 deletion docker/home/bag_ws/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*
# Except this file
!.gitignore
!src
!src
!script
4 changes: 4 additions & 0 deletions docker/home/bag_ws/script/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions docker/home/bag_ws/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
3 changes: 2 additions & 1 deletion docker/home/loc_ws/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*
# Except this file
!.gitignore
!src
!src
!install
4 changes: 4 additions & 0 deletions docker/home/loc_ws/install/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
3 changes: 2 additions & 1 deletion docker/home/ros2_ws/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*
# Except this file
!.gitignore
!src
!src
!install
4 changes: 4 additions & 0 deletions docker/home/ros2_ws/install/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

0 comments on commit 241c003

Please sign in to comment.