Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Dockerfile optimizations #288

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# syntax=docker/dockerfile:1.7-labs
# Above must be the first line in Dockerfile. It enables the "copy --parents" syntax
evan-palmer marked this conversation as resolved.
Show resolved Hide resolved
ARG ROS_DISTRO=rolling
FROM ros:$ROS_DISTRO-ros-base AS ci

ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /root/ws_blue
COPY . src/blue

# Install apt packages needed for CI
RUN apt-get -q update \
&& apt-get -q -y upgrade \
Expand All @@ -27,11 +26,17 @@ RUN apt-get -q update \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install all ROS dependencies for _just_ blue
# (we have not imported other repos from .repos files)
# Pull in _just_ the */package.xml files from blue's subdirectories
# Install rosdeps for all of those sub-packages
WORKDIR /root/ws_blue/src/blue
COPY --parents */package.xml .
COPY blue.repos .
WORKDIR /root/ws_blue

RUN apt-get -q update \
&& apt-get -q -y upgrade \
&& rosdep update \
&& vcs import src < src/blue/blue.repos \
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} --as-root=apt:false \
&& rm -rf src \
&& apt-get autoremove -y \
Expand All @@ -48,6 +53,29 @@ RUN apt-get -q update \
#
FROM ci AS robot

# Install gstreamer, plus geographiclib-tools for install_geographiclib_datasets
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 \
libgstreamer1.0-dev \
gstreamer1.0-gl \
libgstreamer-plugins-base1.0-dev \
geographiclib-tools \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install MAVROS dependencies
RUN wget -O - https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh | sh

#
# Ubuntu 24.04 "Noble", which is used as the base image for
# jazzy and rolling images, now includes a user "ubuntu" at UID 1000
Expand Down Expand Up @@ -76,38 +104,13 @@ ENV VIRTUAL_ENV=/home/$USERNAME/.venv/blue
RUN python3 -m venv --system-site-packages --symlinks $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# 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

ENV USER_WORKSPACE=/home/$USERNAME/ws_blue
WORKDIR $USER_WORKSPACE
COPY --chown=$USER_UID:$USER_GID . src/blue

# 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 \
libgstreamer1.0-dev \
gstreamer1.0-gl \
libgstreamer-plugins-base1.0-dev \
&& sudo apt-get autoremove -y \
&& sudo apt-get clean -y \
&& sudo rm -rf /var/lib/apt/lists/*

# Manually install MAVROS from source in the ws_blue/ workspace
WORKDIR $USER_WORKSPACE/src/
ARG MAVROS_RELEASE=ros2
Expand Down Expand Up @@ -141,8 +144,7 @@ RUN sudo apt-get -q update \
RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \
&& colcon build

RUN echo "source ${USER_WORKSPACE}/install/setup.bash" >> /home/$USERNAME/.bashrc \
&& echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc \
RUN echo "if [ -f ${USER_WORKSPACE}/install/setup.bash ]; then source ${USER_WORKSPACE}/install/setup.bash; else source /opt/ros/${ROS_DISTRO}/setup.bash; fi" >> /home/$USERNAME/.bashrc \
&& echo "source $VIRTUAL_ENV/bin/activate" >> /home/$USERNAME/.bashrc \
&& echo "\n# Ensure colcon is run in the venv\nalias colcon='python3 -m colcon'" >> /home/$USERNAME/.bashrc

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
fail-fast: false
matrix:
env:
- IMAGE: rolling-ci
ROS_DISTRO: rolling
- IMAGE: humble-ci
ROS_DISTRO: humble
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted, industrial CI tries to install mavros viaapt, which is currently not available for rolling (#248).

CI does work if we force it to use Humble, for which there's a binary image.

Note this is just the ros_industrial CI stage, not building the Docker images (where Mavros is built from source for rolling/jazzy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into that. Because we know it's an issue with MAVROS, It's not a big deal if the CI fails in this PR. We can just update the CI stage in #241 to use the new mavros stage.

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down