Files
ros2_docker/Dockerfile
2025-04-04 14:40:10 +02:00

112 lines
3.6 KiB
Docker

FROM ubuntu:24.04 AS universe
# ensure system is up to date
RUN apt update
RUN apt upgrade -y
# setup locale
RUN apt install locales -y
RUN locale-gen en_US en_US.UTF-8
RUN update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG=en_US.UTF-8
# add the universe repo
RUN apt install software-properties-common -y
RUN add-apt-repository universe -y
FROM universe AS utils
## install required tools for the setup process
RUN apt install -y \
curl \
git \
vim
FROM utils AS zsh
# install zsh as default shell
RUN apt install zsh -y
RUN chsh -s $(which zsh)
# install oh-my-zsh and powerlevel10k
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
RUN git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
# install oh-my-zsh extensions
ENV ZSH_CUSTOM=/root/.oh-my-zsh/custom
RUN git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
# add config files to make the shell look fancy
ADD zsh/.zshrc /root
ADD zsh/.p10k.zsh /root
# make sure colors are displayed right
ENV TERM=xterm-256color
FROM zsh AS ros_repo
# add the ros repo keys
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
# add gazebo keys
RUN curl https://packages.osrfoundation.org/gazebo.gpg --output /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
# add glim keys
RUN curl -s https://koide3.github.io/ppa/setup_ppa.sh | bash
RUN curl -s --compressed "https://koide3.github.io/ppa/ubuntu2404/KEY.gpg" | gpg --dearmor | tee /etc/apt/trusted.gpg.d/koide3_ppa.gpg >/dev/null
RUN echo "deb [signed-by=/etc/apt/trusted.gpg.d/koide3_ppa.gpg] https://koide3.github.io/ppa/ubuntu2404 ./" | tee /etc/apt/sources.list.d/koide3_ppa.list
# update with the new keys
RUN apt update
FROM ros_repo AS ros_base
# install ros2 and source the install
RUN apt install ros-jazzy-desktop-full -y
RUN echo "source /opt/ros/jazzy/setup.sh" >> /root/.zshrc
RUN echo "source /ros2_ws/install/setup.sh" > /dev/null 2> /dev/null
FROM ros_base AS ros_packages
# install colcon support
RUN apt install -y \
python3-argcomplete \
python3-colcon-argcomplete \
python3-colcon-ros
# install velodyne drivers
RUN apt install -y ros-jazzy-velodyne
# install gazebo
RUN apt install -y gz-harmonic
RUN apt install -y ros-jazzy-gazebo-msgs
# setup autocomplete
RUN echo "eval \"\$(register-python-argcomplete ros2)\"" >> /root/.zshrc
RUN echo "eval \"\$(register-python-argcomplete colcon)\"" >> /root/.zshrc
RUN echo "eval \"\$(register-python-argcomplete rosidl)\"" >> /root/.zshrc
FROM ros_packages AS settings
# setup timezone
RUN echo "Europe/Berlin" > /etc/timezone
RUN ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
# set workspace
WORKDIR /ros2_ws
# add docker startup script
ADD scripts/docker-compose-entrypoint /etc
RUN chmod +x /etc/docker-compose-entrypoint
ENTRYPOINT ["zsh"]