Skip to content

Commit

Permalink
fix Dockerfile to set host time zone, UID, GID
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 6, 2024
1 parent 12befdb commit 73685e1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docker/driver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,8 @@ FROM build as final

COPY --from=cache_ws $HOME/driver_ws/install $HOME/driver_ws/install
COPY --from=cache_ws $HOME/driver_ws/script $HOME/driver_ws/script

# change location of ros base
COPY ros_entrypoint.sh /ros_entrypoint.sh
RUN sed -i 's:custom_ws:underlay_ws:' /ros_entrypoint.sh
RUN chmod +x /ros_entrypoint.sh
30 changes: 30 additions & 0 deletions docker/driver/ros_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
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
chown -R "$HOST_UID:$HOST_GID" /home/developer
fi

# Source ROS setup script
source "/opt/custom_ws/install/setup.bash"

WORKDIR=$(pwd)

exec gosu developer bash -c "cd $WORKDIR && exec $*"

0 comments on commit 73685e1

Please sign in to comment.