Skip to content

Commit

Permalink
Clean the container code
Browse files Browse the repository at this point in the history
  • Loading branch information
victorpaleologue committed Oct 26, 2023
1 parent aa50225 commit 76e3b01
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 147 deletions.
52 changes: 6 additions & 46 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,20 @@

version: "3.9"
services:
# Base image containing dependencies.
base:
image: ros2-naoqi-driver:base
# Developer container
dev:
image: ros2-naoqi-driver:dev
build:
context: .
dockerfile: docker/Dockerfile
args:
ROS_DISTRO: humble
target: base
target: dev

# Interactive shell
stdin_open: true
tty: true
# Networking and IPC for ROS 2
network_mode: host
ipc: host
# Needed to display graphical applications
privileged: True
environment:
# Allows graphical programs in the container.
- DISPLAY=${DISPLAY}
- QT_X11_NO_MITSHM=1
- NVIDIA_DRIVER_CAPABILITIES=all
volumes:
# Allows graphical programs in the container.
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority

# Overlay image containing the example source code.
overlay:
extends: base
image: ros2-naoqi-driver:overlay
build:
context: .
dockerfile: docker/Dockerfile
target: overlay

# Developer container
dev:
extends: overlay
image: ros2-naoqi-driver:dev
build:
context: .
dockerfile: docker/Dockerfile
target: dev
args:
- UID=${UID:-1000}
- GID=${UID:-1000}
- USERNAME=${USERNAME:-devuser}
volumes:
# Mount the source code
- .:/overlay_ws/src/naoqi_driver2:rw
# Mount colcon build artifacts for faster rebuilds
- ./.colcon/build/:/overlay_ws/build/:rw
- ./.colcon/install/:/overlay_ws/install/:rw
- ./.colcon/log/:/overlay_ws/log/:rw
user: ${USERNAME:-devuser}
command: sleep infinity
- .:/ws/src/naoqi_driver2:rw
107 changes: 19 additions & 88 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,104 +1,35 @@
# ROS distribution to use
ARG ROS_DISTRO=iron

########################################
# Base ROS 2 development image, #
# Forked from TurtleBot3 Simulation #
# sea-bass/turtlebot3_behavior_demos #
########################################
FROM ros:${ROS_DISTRO} as base
FROM ros:${ROS_DISTRO} as dev
ENV ROS_DISTRO=${ROS_DISTRO}
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-c"]

# Install basic apt packages
RUN apt-get update && apt-get install -y --no-install-recommends \
git curl libcanberra-gtk-module libcanberra-gtk3-module fuse3 libfuse2 libqt5svg5-dev \
python3-pip python3-opencv python3-tk python3-pyqt5.qtwebengine

# Install additional Python modules
RUN pip3 install matplotlib transforms3d

# Use Cyclone DDS as middleware
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-${ROS_DISTRO}-rmw-cyclonedds-cpp
ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

# Create Colcon workspace with external dependencies
ENV BASE_WS=/ws
RUN mkdir -p $BASE_WS/src
WORKDIR $BASE_WS/src
COPY dependencies.repos .
RUN vcs import < dependencies.repos
# Create Colcon workspace with the project and its deps
ENV WS=/ws
ENV PROJ_SRC=${WS}/src/naoqi_driver2
COPY . $PROJ_SRC
WORKDIR $WS/src
RUN apt install -y git python3-vcstool
RUN vcs import < $PROJ_SRC/dependencies.repos

# Build the base Colcon workspace, installing dependencies first.
WORKDIR $BASE_WS
WORKDIR $WS
RUN source /opt/ros/${ROS_DISTRO}/setup.bash \
&& apt-get update -y \
&& rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y \
&& colcon build --symlink-install

# Remove display warnings
RUN mkdir /tmp/runtime-root
ENV XDG_RUNTIME_DIR "/tmp/runtime-root"
RUN chmod -R 0700 /tmp/runtime-root
ENV NO_AT_BRIDGE 1

# Set up the entrypoint
WORKDIR $BASE_WS
COPY ./docker/entrypoint.sh /
ENTRYPOINT [ "/entrypoint.sh" ]

###########################################
# Overlay Image with robot-specific deps #
###########################################
FROM base AS overlay

# Create an overlay Colcon workspace
ENV OVERLAY_WS=/overlay_ws
RUN mkdir -p $OVERLAY_WS/src
WORKDIR $OVERLAY_WS
COPY . ./src/naoqi_driver2/
RUN source $BASE_WS/install/setup.bash \
&& rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y --include-eol-distros

############################################
# Production image has everything compiled #
############################################
FROM overlay AS production
RUN colcon build --symlink-install

#####################
# Development Image #
#####################
FROM overlay as dev

# Dev container arguments
ARG USERNAME=devuser
ARG UID=1000
ARG GID=${UID}
&& apt-get update -y \
&& rosdep update \
&& rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y

# Install extra tools for development
RUN apt-get update && apt-get install -y --no-install-recommends \
gdb gdbserver nano libgmock-dev

# Create new user and home directory
RUN groupadd --gid $GID $USERNAME \
&& useradd --uid ${GID} --gid ${UID} --create-home ${USERNAME} \
&& echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \
&& chmod 0440 /etc/sudoers.d/${USERNAME} \
&& mkdir -p /home/${USERNAME} \
&& chown -R ${UID}:${GID} /home/${USERNAME}

# Set the ownership of the overlay workspace to the new user
RUN chown -R ${UID}:${GID} $OVERLAY_WS/
# Expect to mount the source code from the host.
VOLUME $PROJ_SRC

# Set the user and source entrypoint in the user's .bashrc file
USER ${USERNAME}
RUN echo "source /entrypoint.sh" >> /home/${USERNAME}/.bashrc
# Every bash instance should source the entrypoint
RUN echo "source ${PROJ_SRC}/docker/entrypoint.sh" >> /root/.bashrc
SHELL [ "/bin/bash", "-c" ]
ENTRYPOINT [ "/bin/bash" ]

#####################
# Development Image #
#####################
FROM dev as dev-prebuilt
RUN colcon build --symlink-install
RUN colcon build --symlink-install
15 changes: 3 additions & 12 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@ source /opt/ros/${ROS_DISTRO}/setup.bash
echo "Sourced ROS 2 ${ROS_DISTRO}"

# Source the base workspace, if built
if [ -f $BASE_WS/install/setup.bash ]
if [ -f $WS/install/setup.bash ]
then
source $BASE_WS/install/setup.bash
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:$(ros2 pkg prefix turtlebot3_gazebo)/share/turtlebot3_gazebo/models
echo "Sourced TurtleBot3 base workspace"
fi

# Source the overlay workspace, if built
if [ -f $OVERLAY_WS/install/setup.bash ]
then
source $OVERLAY_WS/install/setup.bash
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:$(ros2 pkg prefix tb3_worlds)/share/tb3_worlds/models
echo "Sourced autonomy overlay workspace"
source $WS/install/setup.bash
echo "Sourced workspace"
fi

# Execute the command passed into this entrypoint
Expand Down
1 change: 0 additions & 1 deletion docker/run_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ DOCKER_VOLUMES="
--volume="${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority" \
"
DOCKER_ENV_VARS="
--env="TURTLEBOT3_MODEL=waffle_pi" \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--env="NVIDIA_DRIVER_CAPABILITIES=all" \
Expand Down

0 comments on commit 76e3b01

Please sign in to comment.