ROS2 project from development to deployment, Part 4: Using docker for cross compiler
- Build docker image for ARM
- Using github action to run build process on the docker
Build docker image
Run ARM docker architecture on x64 machine install
Docker
| # docker buildx build --platform linux/arm64 -t humble/arm -f Dockerfile.arm .
FROM ubuntu:22.04
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES all
# Install common programs
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
gnupg2 \
lsb-release \
sudo \
software-properties-common \
wget \
&& rm -rf /var/lib/apt/lists/*
ARG USERNAME=user
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Create a non-root user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# Add sudo support for the non-root user
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& rm -rf /var/lib/apt/lists/*
# Install language
RUN apt-get update && apt-get install -y \
locales \
&& locale-gen en_US.UTF-8 \
&& update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 \
&& rm -rf /var/lib/apt/lists/*
ENV LANG=en_US.UTF-8
# Install timezone
RUN ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y tzdata \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get -y upgrade \
&& rm -rf /var/lib/apt/lists/*
# Install ROS2
RUN sudo add-apt-repository universe \
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \
&& 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" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null \
&& apt-get update && apt-get install -y --no-install-recommends \
ros-humble-ros-base \
python3-argcomplete \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends \
bash-completion \
python-is-python3 \
vim \
## ros
ros-humble-rmw-cyclonedds-cpp \
python3-colcon-common-extensions \
python3-colcon-clean \
## devops
tmux \
tmuxp \
python3-rosdep \
python3-bloom \
fakeroot \
debhelper \
dh-python \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Set up autocompletion for user
RUN apt-get update && apt-get install -y git-core bash-completion \
&& echo "if [ -f /opt/ros/${ROS_DISTRO}/setup.bash ]; then source /opt/ros/${ROS_DISTRO}/setup.bash; fi" >> /home/$USERNAME/.bashrc \
&& echo "if [ -f /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash ]; then source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash; fi" >> /home/$USERNAME/.bashrc \
&& rm -rf /var/lib/apt/lists/*
ENV DEBIAN_FRONTEND=
ENV AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS=1
RUN rosdep init \
&& rosdep update
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
|
| docker build --platform=linux/arm64/v8 -t ros2_cross_compile:arm64v8 -f Docker/Dockerfile.arm .
|
linux/arm64/v8
linux/arm64/v8
is an Alias for linux/arm64
Using github actions
Using github actions local using act
install act |
---|
| curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
|
Config github action in project
- Add
.github
folder
- Add
workflows
folder
- Add action yaml file
.github action folder and files |
---|
| .github/
└── workflows
├── build.yml
└── README.md
|
build.yaml |
---|
| name: My Action
on: [workflow_dispatch]
jobs:
build_pc_pkg_interface_ng:
runs-on: pc
steps:
- name: build
uses: ./.github/actions/ros_build
with:
PROJECT_NAME: pkg_interface
|
update rosdep sources
Update docker /etc/ros/rosdep/source.list.d
with project custom DB and run rosdep update
run |
---|
| act -j build_pkg_interface -P arm=ros2_cross_compile:arm64v8 \
--pull=false \
--bind --directory .
|