Skip to content

Commit

Permalink
Merge pull request #2 from SimonSchwaiger/ros2_humble
Browse files Browse the repository at this point in the history
Merge main to show ROS 2 Humble. ROS Noetic is still available in its own branch
  • Loading branch information
SimonSchwaiger committed Jun 17, 2023
2 parents 1ab6ea2 + 47a9fde commit 5c46116
Show file tree
Hide file tree
Showing 10 changed files with 634 additions and 131 deletions.
131 changes: 131 additions & 0 deletions .github/workflows/Dockerfile.ros1_noetic
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Remove other container sources to deal with space constraints in github actions
# Default platform = opensource gpu acceleration
ARG GRAPHICS_PLATFORM=standard
# Default python version is 3.8
ARG PYTHONVER=3.8

## Generic container with MESA
FROM ubuntu:focal as build_standard

#############################################################
########## REAL BUILD STARTS HERE ##########

## Build container from specified source
FROM build_${GRAPHICS_PLATFORM}

ENV DEBIAN_FRONTEND="noninteractive"

## Recreate ROS noetic base image
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV ROS_DISTRO noetic

# Setup timezone
RUN echo 'Etc/UTC' > /etc/timezone && \
if ! [ -f /etc/localtime ]; then ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime; fi && \
apt-get update && \
apt-get install -q -y --no-install-recommends tzdata

# Install prerequisites
RUN apt-get update && apt-get install -q -y --no-install-recommends \
dirmngr \
gnupg2 \
software-properties-common \
build-essential

# Setup sources.list and keys for ROS
RUN echo "deb http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros1-latest.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# Install mesa
RUN apt-get update && apt-get install -q -y --no-install-recommends \
libgl1-mesa-glx libgl1-mesa-dri

# Install ROS
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-noetic-desktop-full \
ros-noetic-rviz ros-noetic-rqt* ros-noetic-rosbridge-server\
ros-noetic-gmapping ros-noetic-dwa-local-planner ros-noetic-joint-state-publisher-gui

# install python3, pip and venv
# you can change your preferred python version here and it will be installed from the deadsnakes ppa
# some tensorflow implementations (such as gym baselines 2) will require python 3.7
# Forward PYTHONVER argument to the current container
ARG PYTHONVER
ARG GRAPHICS_PLATFORM

RUN apt-get update && apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:deadsnakes/ppa \
&& apt-get update && apt-get install -y python$PYTHONVER python$PYTHONVER-dev python$PYTHONVER-tk

RUN apt-get update && apt-get install -y cmake libopenmpi-dev zlib1g-dev imagemagick

RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-pip \
python3-venv \
python3-tk \
&& pip3 install virtualenv

# Create virtualenv using the correct python interpreter
# Intel is an edgecase here, since they offer a custom interpreter in the intel distribution for python
RUN if [ "$GRAPHICS_PLATFORM" = "intel" ]; then \
virtualenv -p /opt/intel/oneapi/intelpython/latest/bin/python ~/myenv; else \
virtualenv -p /usr/bin/python$PYTHONVER ~/myenv; fi

# upgrade to latest pip
RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install --upgrade pip"

# install ros python prerequisites
# twisted, openssl, autobahn, pymongo and Pillow are there to enable rosbridge server
RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install launchpadlib \
wheel \
&& pip3 install rosdep \
rosinstall_generator \
wstool \
rosinstall \
empy \
catkin_tools \
defusedxml \
numpy \
twisted pyOpenSSL autobahn pymongo Pillow service-identity \
&& pip3 install --upgrade setuptools"

# Install required python packages
ADD ./requirements.txt .

RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install -r requirements.txt"

# Copy ROS packages for compilation in container
COPY ./src /catkin_ws/src

# Install ros dependencies
RUN apt-get update && apt-get install -y --no-install-recommends python3-rosdep python3-empy && rosdep init
RUN apt-get update && rosdep update && rosdep install --from-paths /catkin_ws/src -i -y --rosdistro noetic

# Compile workspace
RUN /bin/bash -c "source /opt/ros/noetic/setup.bash \
&& cd catkin_ws \
&& catkin_make -DPYTHON_EXECUTABLE=~/myenv/bin/python"

# Remove src folder used for compilation, since the real src folder will be mounted at runtime
RUN rm -rf /catkin_ws/src

# Cleanup
RUN rm -rf /var/lib/apt/lists/*

# Add ROS sourcing to bashrc for interactive debugging
RUN echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
RUN echo "source /catkin_ws/devel/setup.bash" >> ~/.bashrc
RUN echo "source ~/myenv/bin/activate" >> ~/.bashrc

# Set shell env variable for jupyterlab (this fixes autocompletion in web-based shell)
ENV SHELL=/bin/bash

# Add entrypoint
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
206 changes: 206 additions & 0 deletions .github/workflows/Dockerfile.ros2_humble
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Remove other container sources to deal with space constraints in github actions
# Default platform = opensource gpu acceleration
ARG GRAPHICS_PLATFORM=standard
# Default python version is 3.8
ARG PYTHONVER=3.10

## Generic container with MESA
FROM ubuntu:jammy as build_standard

#############################################################
########## REAL BUILD STARTS HERE ##########

## Build container from specified source
FROM build_${GRAPHICS_PLATFORM}
LABEL org.opencontainers.image.source="https://github.com/SimonSchwaiger/ros-ml-container"

ENV DEBIAN_FRONTEND="noninteractive"

# Install mesa for GUI
RUN apt-get update && apt-get install -q -y --no-install-recommends \
libgl1-mesa-glx libgl1-mesa-dri

## Recreate ROS humble devel image
# ------------------------
# https://github.com/osrf/docker_images/blob/master/ros2/source/devel/Dockerfile
# setup timezone
RUN echo 'Etc/UTC' > /etc/timezone && \
ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
apt-get update && \
apt-get install -q -y --no-install-recommends tzdata && \
rm -rf /var/lib/apt/lists/*

# install packages
RUN apt-get update && apt-get install -q -y --no-install-recommends \
bash-completion \
dirmngr \
gnupg2 \
lsb-release \
python3-flake8 \
python3-flake8-blind-except \
python3-flake8-builtins \
python3-flake8-class-newline \
python3-flake8-comprehensions \
python3-flake8-deprecated \
python3-flake8-docstrings \
python3-flake8-import-order \
python3-flake8-quotes \
python3-pip \
python3-pytest-repeat \
python3-pytest-rerunfailures \
&& rm -rf /var/lib/apt/lists/*

# setup sources.list
RUN echo "deb http://packages.ros.org/ros2/ubuntu jammy main" > /etc/apt/sources.list.d/ros2-latest.list

# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
git \
python3-colcon-common-extensions \
python3-colcon-mixin \
python3-rosdep \
python3-setuptools \
python3-vcstool \
&& rm -rf /var/lib/apt/lists/*

# install python packages
RUN pip3 install -U \
argcomplete pytest
# add pytest here manually as a workaround for intel-based builds

# This is a workaround for pytest not found causing builds to fail
# Following RUN statements tests for regression of https://github.com/ros2/ros2/issues/722
RUN pip3 freeze | grep pytest \
&& python3 -m pytest --version

# bootstrap rosdep
RUN rosdep init \
&& rosdep update

# setup colcon mixin and metadata
RUN colcon mixin add default \
https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml && \
colcon mixin update && \
colcon metadata add default \
https://raw.githubusercontent.com/colcon/colcon-metadata-repository/master/index.yaml && \
colcon metadata update

# clone source
ENV ROS2_WS /opt/ros2_ws
RUN mkdir -p $ROS2_WS/src
WORKDIR $ROS2_WS

# build source
RUN colcon \
build \
--cmake-args \
-DSECURITY=ON --no-warn-unused-cli \
--symlink-install

# setup bashrc
RUN cp /etc/skel/.bashrc ~/

WORKDIR /
## Official ROS image recreated
# ------------------------

# Set ROS and ignition versions and install them
ENV ROS_DISTRO humble
ENV IGNITION_VERSION fortress

# Fully install ros2 instead of bootstrapping it and install rqt for debugging and rosbridge for web-based visualisation
RUN apt-get update && apt-get install -y ros-$ROS_DISTRO-ros-base ros-dev-tools ros-humble-rqt* ros-humble-rosbridge-server

# Install ignition gazebo
#RUN apt-get install -y ros-$ROS_DISTRO-ros-ign ignition-$IGNITION_VERSION

# install python3, pip and venv
# you can change your preferred python version here and it will be installed from the deadsnakes ppa
# some tensorflow implementations (such as gym baselines 2) will require python 3.7
# Forward PYTHONVER argument to the current container
ARG PYTHONVER
ARG GRAPHICS_PLATFORM

RUN apt-get update && apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:deadsnakes/ppa \
&& apt-get update && apt-get install -y python$PYTHONVER python$PYTHONVER-dev python$PYTHONVER-tk

RUN apt-get update && apt-get install -y --no-install-recommends \
python3-pip \
python3-venv \
cmake \
libopenmpi-dev \
zlib1g-dev \
imagemagick

RUN pip3 install virtualenv

# Create virtualenv using the correct python interpreter
# Intel is an edgecase here, since they offer a custom interpreter in the intel distribution for python
RUN if [ "$GRAPHICS_PLATFORM" = "intel" ]; then \
virtualenv -p /opt/intel/oneapi/intelpython/latest/bin/python ~/myenv; else \
virtualenv -p /usr/bin/python$PYTHONVER ~/myenv; fi

# Upgrade to latest pip
RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install --upgrade pip"

# Install ros python prerequisites
# Pytest is explicitly installed to handle the intel edgecase
# Netifaces, pymongo and Pillow are installed for rosbridge
RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install launchpadlib \
rosinstall_generator \
rosinstall \
empy \
catkin_tools \
lark \
lxml \
pytest \
numpy \
netifaces pymongo Pillow \
&& pip3 install --upgrade setuptools"

# Install required python packages
ADD ./requirements.txt .

RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install -r requirements.txt"

# Copy ROS packages for compilation in container
COPY ./src /opt/$ROS2_WS/src

# Install ros dependencies
RUN apt-get update && rosdep update && rosdep install --from-paths /opt/$ROS2_WS/src -i -y --rosdistro $ROS_DISTRO

# Compile workspace
RUN /bin/bash -c "source /opt/ros/$ROS_DISTRO/setup.bash \
&& cd /opt/$ROS2_WS \
&& colcon build --symlink-install"

# Remove src folder used for compilation, since the real src folder will be mounted at runtime
RUN rm -rf /opt/$ROS2_WS/src

# Cleanup
RUN rm -rf /var/lib/apt/lists/*

# Add ROS and venv sourcing to bashrc for interactive debugging
RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc
RUN echo ". /opt/ros2_ws/install/local_setup.bash" >> ~/.bashrc
RUN echo "source ~/myenv/bin/activate" >> ~/.bashrc

# Set shell env variable for jupyterlab (this fixes autocompletion in web-based shell)
ENV SHELL=/bin/bash

# Add entrypoint
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
31 changes: 31 additions & 0 deletions .github/workflows/ci_ros1_noetic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy Opensource Image to GHCR

on:
push:
branches: [ "ros1_noetic" ]
pull_request:
branches: [ "ros1_noetic" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@v3

- name: "Login to GitHub Container Registry"
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: "Build the Docker image"
run: |
mkdir src
echo "jupyterlab" > requirements.txt
docker build . --file .github/workflows/Dockerfile.ros1_noetic --tag ghcr.io/simonschwaiger/ros-ml-container:ros1_noetic
docker push ghcr.io/simonschwaiger/ros-ml-container:ros1_noetic
Loading

0 comments on commit 5c46116

Please sign in to comment.