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

[WIP] Implement multi-architecture builds #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
18 changes: 18 additions & 0 deletions doc/010_Setup_Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ In order to make sure that the kernel modules are properly loaded, you should re

Now you are ready to use docker!

### Cross Development for docker images

To develop for arm-based boards on x86, you can enable your host machine execute non-native binary formats using [QEMU](https://www.qemu.org) and [binfmt_misc](https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html).

When this is set up, docker is able to run images for the architectures supported by QEMU on your host machine (using CPU emulation).

There is a docker image that can do the settings for you: [see here](https://github.com/multiarch/qemu-user-static)

Quick enable:

sudo apt-get install qemu binfmt-support qemu-user-static
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes

Test it using e.g.

docker run --rm -ti arm64v8/ubuntu uname -m


### Using a registry
If you want to use the image generated by the docker build from this repository, you can also use the already build image from the registry server.

Expand Down
2 changes: 1 addition & 1 deletion docker_commands.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ init_docker(){
touch $GPUS_SETTINGS_FILE
docker run --gpus=all --rm $IMAGE_NAME > /dev/null
GPU_SUPPORTED=$?
echo "this file contains the gegerated result of testing the docker --gpu setting, 0=enabled, 1=disabled" > $GPUS_SETTINGS_FILE
echo "this file contains the generated result of testing the docker --gpu setting, 0=enabled, 1=disabled" > $GPUS_SETTINGS_FILE
echo $GPU_SUPPORTED >> $GPUS_SETTINGS_FILE
fi
HAS_GPU_SUPPORT=$(tail -n1 $GPUS_SETTINGS_FILE)
Expand Down
3 changes: 3 additions & 0 deletions exec.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fi
if [ "$EXECMODE" == "base" ]; then
# DOCKER_REGISTRY and WORKSPACE_DEVEL_IMAGE from settings.bash
IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}$WORKSPACE_BASE_IMAGE
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
0Nel marked this conversation as resolved.
Show resolved Hide resolved
HOST_WORKSPACE=$(pwd)
mkdir -p $HOST_WORKSPACE/workspace
mkdir -p $HOST_WORKSPACE/home
Expand All @@ -45,6 +46,7 @@ fi
if [ "$EXECMODE" = "devel" ]; then
# DOCKER_REGISTRY and WORKSPACE_DEVEL_IMAGE from settings.bash
IMAGE_NAME=${DEVEL_REGISTRY:+${DEVEL_REGISTRY}/}$WORKSPACE_DEVEL_IMAGE
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
HOST_WORKSPACE=$(pwd)
#in case the devel image is pulled, we need the create the folders here
mkdir -p $HOST_WORKSPACE/workspace
Expand All @@ -58,6 +60,7 @@ fi
if [ "$EXECMODE" == "release" ]; then
# DOCKER_REGISTRY and WORKSPACE_DEVEL_IMAGE from settings.bash
IMAGE_NAME=${RELEASE_REGISTRY:+${RELEASE_REGISTRY}/}$WORKSPACE_RELEASE_IMAGE
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
fi

if [ "$DOCKER_REGISTRY_AUTOPULL" = true ]; then
Expand Down
15 changes: 7 additions & 8 deletions image_setup/01_base_images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ ENV DEBIAN_FRONTEND=noninteractive

# general requirements
RUN apt-get update && apt-get install -y \
build-essential \
apt-utils \
git \
wget \
cmake \
sudo \
build-essential \
cmake \
git \
locales \
python3 \
python3-dev \
locales
sudo \
wget

RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
Expand All @@ -39,13 +38,13 @@ RUN /opt/install.bash ${INSTALL_ARGS}

ADD init_user_id.bash /opt/init_user_id.bash

# create user (usermod -u UID username will be used later to maybe adapt UID on fitst start).
# create user (usermod -u UID username will be used later to maybe adapt UID on first start).
# using salted password: openssl passwd -1 -salt xyz yourpass # pw UserRos
# RUN useradd -m -U -p '$1$xyz$pzVfEx0ZWLPizymvlx2P70' -G sudo,users rosuser
RUN groupadd devel-group
RUN useradd --shell /bin/bash -c "development user" -m -G devel-group devel

# set user sudoers previlege for start script (w/o password), the /opt/init_user_id.bash script
# set user sudoers privilege for start script (w/o password), the /opt/init_user_id.bash script
# is using NUID and NGID environment variables, but ist executed by the user using sudo, so these vars have to be kept
RUN echo "devel ALL=(ALL) NOPASSWD: ALL \
\nDefaults env_keep += \"NUID\" \
Expand Down
28 changes: 28 additions & 0 deletions image_setup/01_base_images/arm32v7/install_ros_dependencies.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

#install ROS melodic (second install because needs gnupg)
export DEBIAN_FRONTEND=noninteractive

DISTRO=${1:-melodic}
[ $DISTRO == "noetic" ] && export vPYTHON=3

apt-get update && apt-get install -y \
lsb-release \
gnupg2 \
gosu \
ruby \
ruby-dev \
python$vPYTHON

sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
apt-get update && apt-get install -y \
ros-desktop \
python$vPYTHON-catkin-pkg \
python$vPYTHON-rosdep2 \
python$vPYTHON-rosinstall \
python$vPYTHON-rosinstall-generator \
python$vPYTHON-wstool


#rosdep init && rosdep update
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

#install ROS melodic (second install because needs gnupg)
export DEBIAN_FRONTEND=noninteractive

DISTRO=${1:-melodic}
[ $DISTRO == "noetic" ] && export vPYTHON=3

apt-get update && apt-get install -y \
lsb-release \
gnupg2 \
gosu \
ruby \
ruby-dev \
python$vPYTHON

sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
apt-get update && apt-get install -y \
ros-base \
python$vPYTHON-catkin-pkg \
python$vPYTHON-rosdep2 \
python$vPYTHON-rosinstall \
python$vPYTHON-rosinstall-generator \
python$vPYTHON-wstool


#rosdep init && rosdep update


28 changes: 28 additions & 0 deletions image_setup/01_base_images/arm64v8/install_ros_dependencies.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

#install ROS melodic (second install because needs gnupg)
export DEBIAN_FRONTEND=noninteractive

DISTRO=${1:-melodic}
[ $DISTRO == "noetic" ] && export vPYTHON=3

apt-get update && apt-get install -y \
lsb-release \
gnupg2 \
gosu \
ruby \
ruby-dev \
python$vPYTHON

sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
apt-get update && apt-get install -y \
ros-desktop \
python$vPYTHON-catkin-pkg \
python$vPYTHON-rosdep2 \
python$vPYTHON-rosinstall \
python$vPYTHON-rosinstall-generator \
python$vPYTHON-wstool


#rosdep init && rosdep update
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

#install ROS melodic (second install because needs gnupg)
export DEBIAN_FRONTEND=noninteractive

DISTRO=${1:-melodic}
[ $DISTRO == "noetic" ] && export vPYTHON=3

apt-get update && apt-get install -y \
lsb-release \
gnupg2 \
gosu \
ruby \
ruby-dev \
python$vPYTHON

sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
apt-get update && apt-get install -y \
ros-base \
python$vPYTHON-catkin-pkg \
python$vPYTHON-rosdep2 \
python$vPYTHON-rosinstall \
python$vPYTHON-rosinstall-generator \
python$vPYTHON-wstool


#rosdep init && rosdep update


20 changes: 17 additions & 3 deletions image_setup/01_base_images/build_plain_18.04.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/bin/bash

. ../../settings.bash
export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/plain_18.04

export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
# manage base image name depending on selected $ARCH in settings.bash
if [ $ARCH == "x86_64" ]; then
export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
echo "Building for x86_64 processor. Using $BASE_IMAGE as base image."
elif [ $ARCH == "arm64v8" ]; then
export BASE_IMAGE=arm64v8/ubuntu:bionic
echo "Building for arm64v8 processor. Using $BASE_IMAGE as base image."
elif [ $ARCH == "arm32v7" ]; then
export BASE_IMAGE=arm32v7/ubuntu:bionic
echo "Building for arm32v7 processor. Using $BASE_IMAGE as base image."
else
echo -e "[ERROR] The processor architecture you selected ($ARCH) is not supported." && exit 1
fi

export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/plain_18.04
export INSTALL_SCRIPT=install_plain_dependencies.bash
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
[ "$ARCH" != "x86_64" ] && export INSTALL_SCRIPT=$ARCH/$INSTALL_SCRIPT

docker pull $BASE_IMAGE
docker build --no-cache -f Dockerfile -t $IMAGE_NAME:base --build-arg BASE_IMAGE --build-arg INSTALL_SCRIPT .



echo
echo "don't forget to push the image if you wish:"
echo "docker push $IMAGE_NAME:base"
Expand Down
20 changes: 17 additions & 3 deletions image_setup/01_base_images/build_plain_20.04.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/bin/bash

. ../../settings.bash
export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/plain_20.04

export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu20.04
# manage base image name depending on selected $ARCH in settings.bash
if [ $ARCH == "x86_64" ]; then
export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu20.04
echo "Building for x86_64 processor. Using $BASE_IMAGE as base image."
elif [ $ARCH == "arm64v8" ]; then
export BASE_IMAGE=arm64v8/ubuntu:focal
echo "Building for arm64v8 processor. Using $BASE_IMAGE as base image."
elif [ $ARCH == "arm32v7" ]; then
export BASE_IMAGE=arm32v7/ubuntu:focal
echo "Building for arm32v7 processor. Using $BASE_IMAGE as base image."
else
echo -e "[ERROR] The processor architecture you selected ($ARCH) is not supported." && exit 1
fi

export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/plain_20.04
export INSTALL_SCRIPT=install_plain_dependencies.bash
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
[ "$ARCH" != "x86_64" ] && export INSTALL_SCRIPT=$ARCH/$INSTALL_SCRIPT

docker pull $BASE_IMAGE
docker build --no-cache -f Dockerfile -t $IMAGE_NAME:base --build-arg BASE_IMAGE --build-arg INSTALL_SCRIPT .



echo
echo "don't forget to push the image if you wish:"
echo "docker push $IMAGE_NAME:base"
Expand Down
14 changes: 11 additions & 3 deletions image_setup/01_base_images/build_rock_master_16.04.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#!/bin/bash

. ../../settings.bash
export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/rock_master_16.04

export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu16.04
# manage base image name depending on selected $ARCH in settings.bash
if [ $ARCH == "x86_64" ]; then
export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu16.04
echo "Building for x86_64 processor. Using $BASE_IMAGE as base image."
else
echo -e "[ERROR] The processor architecture you selected ($ARCH) is not supported." && exit 1
fi

export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/rock_master_16.04
export INSTALL_SCRIPT=install_rock_dependencies.bash
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
[ "$ARCH" != "x86_64" ] && export INSTALL_SCRIPT=$ARCH/$INSTALL_SCRIPT

docker pull $BASE_IMAGE
docker build --no-cache -f Dockerfile -t $IMAGE_NAME:base --build-arg BASE_IMAGE --build-arg INSTALL_SCRIPT .



echo
echo "don't forget to push the image if you wish:"
echo "docker push $IMAGE_NAME:base"
Expand Down
14 changes: 11 additions & 3 deletions image_setup/01_base_images/build_rock_master_18.04.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#!/bin/bash

. ../../settings.bash
export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/rock_master_18.04

export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
# manage base image name depending on selected $ARCH in settings.bash
if [ $ARCH == "x86_64" ]; then
export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
echo "Building for x86_64 processor. Using $BASE_IMAGE as base image."
else
echo -e "[ERROR] The processor architecture you selected ($ARCH) is not supported." && exit 1
fi

export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/rock_master_18.04
export INSTALL_SCRIPT=install_rock_dependencies.bash
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
[ "$ARCH" != "x86_64" ] && export INSTALL_SCRIPT=$ARCH/$INSTALL_SCRIPT

docker pull $BASE_IMAGE
docker build --no-cache -f Dockerfile -t $IMAGE_NAME:base --build-arg BASE_IMAGE --build-arg INSTALL_SCRIPT .



echo
echo "don't forget to push the image if you wish:"
echo "docker push $IMAGE_NAME:base"
Expand Down
15 changes: 11 additions & 4 deletions image_setup/01_base_images/build_ros_melodic_18.04.bash
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#!/bin/bash

. ../../settings.bash
export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/ros_melodic_18.04

export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
# manage base image name depending on selected $ARCH in settings.bash
if [ $ARCH == "x86_64" ]; then
export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
echo "Building for x86_64 processor. Using $BASE_IMAGE as base image."
else
echo -e "[ERROR] The processor architecture you selected ($ARCH) is not supported." && exit 1
fi

export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/ros_melodic_18.04
export INSTALL_SCRIPT=install_ros_dependencies.bash
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
[ "$ARCH" != "x86_64" ] && export INSTALL_SCRIPT=$ARCH/$INSTALL_SCRIPT

docker pull $BASE_IMAGE
docker build --no-cache -f Dockerfile -t $IMAGE_NAME:base --build-arg BASE_IMAGE --build-arg INSTALL_SCRIPT .



echo
echo "don't forget to push the image if you wish:"
echo "docker push $IMAGE_NAME:base"
echo

15 changes: 11 additions & 4 deletions image_setup/01_base_images/build_ros_melodic_18.04_minimal.bash
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#!/bin/bash

. ../../settings.bash
export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/ros_melodic_18.04_minimal

export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
# manage base image name depending on selected $ARCH in settings.bash
if [ $ARCH == "x86_64" ]; then
export BASE_IMAGE=nvidia/opengl:1.0-glvnd-devel-ubuntu18.04
echo "Building for x86_64 processor. Using $BASE_IMAGE as base image."
else
echo -e "[ERROR] The processor architecture you selected ($ARCH) is not supported." && exit 1
fi

export IMAGE_NAME=${BASE_REGISTRY:+${BASE_REGISTRY}/}developmentimage/ros_melodic_18.04_minimal
export INSTALL_SCRIPT=install_ros_minimal_dependencies.bash
[ "$ARCH" != "x86_64" ] && export IMAGE_NAME=$(dirname $IMAGE_NAME)/$ARCH/$(basename $IMAGE_NAME)
[ "$ARCH" != "x86_64" ] && export INSTALL_SCRIPT=$ARCH/$INSTALL_SCRIPT

docker pull $BASE_IMAGE
docker build --no-cache -f Dockerfile -t $IMAGE_NAME:base --build-arg BASE_IMAGE --build-arg INSTALL_SCRIPT .



echo
echo "don't forget to push the image if you wish:"
echo "docker push $IMAGE_NAME:base"
echo

Loading