Skip to content

Commit

Permalink
Cleaned up Dockerfile and added new user entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-palmer committed Oct 12, 2023
1 parent b858303 commit 9b60032
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/nvidia/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"WORKSPACE": "${containerWorkspaceFolder}",
"ROS_DISTRO": "rolling"
},
"target": "develop-nvidia"
"target": "desktop-nvidia"
},
"remoteUser": "blue",
"runArgs": [
Expand Down
284 changes: 97 additions & 187 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
##############################################
# ci: Install core dependencies needed for CI
##############################################
ARG ROS_DISTRO=rolling
FROM ros:$ROS_DISTRO-ros-base as ci

LABEL maintainer="Evan Palmer"
LABEL maintainer-email="[email protected]"

ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /root/ws_blue

WORKDIR /root/ws_blue
COPY . src/blue

# Install apt packages
# Install apt packages needed for CI
RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& apt-get -q install --no-install-recommends -y \
git \
wget \
curl \
sudo \
clang \
clang-format-14 \
Expand All @@ -31,25 +23,6 @@ RUN apt-get -q update \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install the Python requirements that aren't available as rosdeps
RUN python3 -m pip install -r $(pwd)/src/blue/requirements-build.txt

# Install gstreamer
RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& apt-get -q install --no-install-recommends -y \
python3-gi \
gstreamer1.0-tools \
gir1.2-gstreamer-1.0 \
gir1.2-gst-plugins-base-1.0 \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-ugly \
gstreamer1.0-plugins-bad \
gstreamer1.0-libav \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install all ROS dependencies
RUN apt-get -q update \
&& apt-get -q -y upgrade \
Expand All @@ -60,6 +33,8 @@ RUN apt-get -q update \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

FROM ci as robot

# Configure a new non-root user
ARG USERNAME=blue
ARG USER_UID=1000
Expand All @@ -69,51 +44,95 @@ RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& usermod -a -G dialout $USERNAME \
&& echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc

# Switch to the non-root user to install MAVROS dependencies
ENV DEBIAN_FRONTEND=noninteractive

# Switch to the non-root user for the rest of the installation.
# We do this to avoid any conflicts with user permissions
USER $USERNAME
ENV USER=$USERNAME

# Install some core apt packages
RUN sudo apt-get -q update \
&& sudo apt-get -q -y upgrade \
&& sudo apt-get -q install --no-install-recommends -y \
lsb-release \
wget \
gnupg \
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# Install MAVROS dependencies
WORKDIR /home/$USERNAME
RUN wget https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh \
&& chmod +x install_geographiclib_datasets.sh \
&& sudo ./install_geographiclib_datasets.sh

# Switch back to root user
USER root
ENV USER=root
# Copy the project over to image
ENV USER_WORKSPACE=/home/$USERNAME/ws_blue
WORKDIR $USER_WORKSPACE
COPY --chown=$USER_UID:$USER_GID . src/blue

#################################################################
# sim: install Gazebo and the tools needed for Gazebo simulation
#################################################################
FROM ci as sim
# Install the Python requirements that aren't available as rosdeps
RUN python3 -m pip install -r $(pwd)/src/blue/requirements-build.txt

# Install gstreamer
RUN sudo apt-get -q update \
&& sudo apt-get -q -y upgrade \
&& sudo apt-get -q install --no-install-recommends -y \
python3-gi \
gstreamer1.0-tools \
gir1.2-gstreamer-1.0 \
gir1.2-gst-plugins-base-1.0 \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-ugly \
gstreamer1.0-plugins-bad \
gstreamer1.0-libav \
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# Install all ROS dependencies
RUN sudo apt-get -q update \
&& sudo apt-get -q -y upgrade \
&& rosdep update \
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} \
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# Setup the environment variables
RUN echo "source ${USER_WORKSPACE}/install/setup.bash" >> /home/$USERNAME/.bashrc \
&& echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashr

FROM robot as desktop

ENV DEBIAN_FRONTEND=noninteractive
ENV GZ_VERSION=garden

# Install Gazebo Garden: https://gazebosim.org/docs/garden/install_ubuntu
RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
RUN apt-get update \
&& apt-get -y --quiet --no-install-recommends install \
RUN sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null \
&& sudo apt-get update \
&& sudo apt-get -y --quiet --no-install-recommends install \
gz-garden \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# Install ArduPilot and ardupilot_gazebo dependencies
RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& apt-get -q install --no-install-recommends -y \
RUN sudo apt-get -q update \
&& sudo apt-get -q -y upgrade \
&& sudo apt-get -q install --no-install-recommends -y \
python3-wxgtk4.0 \
rapidjson-dev \
xterm \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch to the non-root user to install ArduSub
USER $USERNAME
ENV USER=$USERNAME
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# Clone ArduSub
# ArduSub is installed for simulation purposes ONLY
Expand Down Expand Up @@ -144,152 +163,43 @@ RUN [ "/bin/bash" , "-c" , " \
&& cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo \
&& make -j4" ]

# Switch back to the root user
USER root
ENV USER=root

# Extend the ros_entrypoint to source the simulation environment
COPY .docker/entrypoints/sim.sh /
RUN sed -i '/source "\/opt\/ros\/$ROS_DISTRO\/setup\.bash" --/a source /sim.sh' /ros_entrypoint.sh

##################################################
# deps: Install all external project dependencies
##################################################
FROM sim as deps

ENV GZ_VERSION=garden
ENV USER_WORKSPACE=/home/$USERNAME/ws_blue/install
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR $USER_WORKSPACE/..

COPY blue.repos src/

RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& vcs import src < src/blue.repos \
&& rosdep update \
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} --as-root=apt:false --skip-keys="gz-transport12 gz-sim7 gz-math7 gz-msgs9 gz-plugin2" \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \
&& colcon build \
# Update /ros_entrypoint.sh to source the workspace
&& sed -i "s#/opt/ros/\$ROS_DISTRO/setup.bash#$USER_WORKSPACE/setup.sh#g" /ros_entrypoint.sh \
&& echo "source ${USER_WORKSPACE}/setup.sh" >> /home/$USERNAME/.bashrc

####################################################
# develop: Setup the image for development purposes
####################################################
FROM deps as develop

ENV GZ_VERSION=garden
ENV ROS_UNDERLAY /root/ws_blue/install
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR $ROS_UNDERLAY/..

COPY . src/blue

# Install debugging/linting Python packages
RUN python3 -m pip install -r $(pwd)/src/blue/requirements-dev.txt

RUN apt-get -q update \
&& apt-get -q -y upgrade \
# Install Gazebo
WORKDIR $USER_WORKSPACE
RUN sudo apt-get -q update \
&& sudo apt-get -q -y upgrade \
&& vcs import src < src/blue/blue.repos \
&& rosdep update \
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} --as-root=apt:false --skip-keys="gz-transport12 gz-sim7 gz-math7 gz-msgs9" \
&& rm -rf src \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install development tools
RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& apt-get -q install --no-install-recommends -y \
iputils-ping \
net-tools \
gdb \
nano \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

COPY .docker/entrypoints/dev.sh /

# WARNING: This is a temporary solution for disabling the setuputils installation warning
ENV PYTHONWARNINGS="ignore"

ARG WORKSPACE
RUN echo "if [ -f ${WORKSPACE}/install/setup.bash ]; then source ${WORKSPACE}/install/setup.bash; fi" >> /home/$USERNAME/.bashrc \
&& echo "if [ -f /opt/ros/${ROS_DISTRO}/setup.bash ]; then source /opt/ros/${ROS_DISTRO}/setup.bash; fi" >> /home/$USERNAME/.bashrc \
# Expose the environment variables to the non-root user
&& echo "if [ -f /sim.sh ]; then source /sim.sh; fi" >> /home/$USERNAME/.bashrc \
&& echo "if [ -f /dev.sh ]; then source /dev.sh; fi" >> /home/$USERNAME/.bashrc
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} --skip-keys="gz-transport12 gz-sim7 gz-math7 gz-msgs9 gz-plugin2" \
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# For users that build this on a laptop or system with limited RAM,
# Modify the 'colcon build' line to be 'MAKEFLAGS="-j1 -l1" colcon build'
# This will limit the amount of RAM that colcon is allowed to use
RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \
&& colcon build

# Setup the simulation environment variables
RUN echo "source ${USER_WORKSPACE}/src/blue/.docker/entrypoints/sim.sh" >> /home/$USERNAME/.bashrc

######################################################################################
# develop-nvidia: Setup the image for development purposes with NVIDIA driver support
######################################################################################
FROM deps as develop-nvidia
FROM desktop as desktop-nvidia

# Install NVIDIA software
RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
RUN sudo apt-get update \
&& sudo apt-get -q -y upgrade \
&& sudo apt-get install -y -qq --no-install-recommends \
libglvnd0 \
libgl1 \
libglx0 \
libegl1 \
libxext6 \
libx11-6
libx11-6 \
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute
ENV QT_X11_NO_MITSHM 1

ENV GZ_VERSION=garden
ENV ROS_UNDERLAY /root/ws_blue/install
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR $ROS_UNDERLAY/..

COPY . src/blue

# Install debugging/linting Python packages
RUN python3 -m pip install -r $(pwd)/src/blue/requirements-dev.txt

RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& vcs import src < src/blue/blue.repos \
&& rosdep update \
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} --as-root=apt:false --skip-keys="gz-transport12 gz-sim7 gz-math7 gz-msgs9 gz-plugin2" \
&& rm -rf src \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install development tools
RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& apt-get -q install --no-install-recommends -y \
iputils-ping \
net-tools \
gdb \
nano \
htop \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

COPY .docker/entrypoints/dev.sh /

# WARNING: This is a temporary solution for disabling the setuputils installation warning
ENV PYTHONWARNINGS="ignore"

ARG WORKSPACE
RUN echo "if [ -f ${WORKSPACE}/install/setup.bash ]; then source ${WORKSPACE}/install/setup.bash; fi" >> /home/$USERNAME/.bashrc \
&& echo "if [ -f /opt/ros/${ROS_DISTRO}/setup.bash ]; then source /opt/ros/${ROS_DISTRO}/setup.bash; fi" >> /home/$USERNAME/.bashrc \
# Expose the environment variables to the non-root user
&& echo "if [ -f /sim.sh ]; then source /sim.sh; fi" >> /home/$USERNAME/.bashrc \
&& echo "if [ -f /dev.sh ]; then source /dev.sh; fi" >> /home/$USERNAME/.bashrc
22 changes: 22 additions & 0 deletions .docker/compose/nouveau-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3"
services:
blue:
image: blue
environment:
- DISPLAY=${DISPLAY}
- XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}
- WAYLAND_DISPLAY=${WAYLAND_DISPLAY} # Can be commented out if not used
- PULSE_SERVER=${PULSE_SERVER} # Can be commented out if not used
network_mode: host
privileged: true
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
- apparmor:unconfined
volumes:
- /dev:/dev
- /run/user/1000:/run/user/1000
command: /bin/bash
stdin_open: true
tty: true
Loading

0 comments on commit 9b60032

Please sign in to comment.