From fc7e42282114eb87e838fc2aa3b667fd268510fa Mon Sep 17 00:00:00 2001 From: Ramon Roche Date: Mon, 31 Jan 2022 08:03:24 -0800 Subject: [PATCH] container: general purpose multiarch docker * new docker container using ubuntu focal (20.04) * adds nuttx building for any supported target * adds initial support for gazebo simulation via X11 * updates docker_run.sh script to initialize container * NEEDS: updated ubuntu.sh script How to run: ``` ./Tools/docker_run.sh make all_variants_px4_fmu-v5x ``` --- Tools/docker_run.sh | 59 ++++---------------------------- Tools/setup/Dockerfile | 55 +++++++++++++++++++++++++++++ Tools/setup/docker-entrypoint.sh | 28 +++++++++++++++ 3 files changed, 90 insertions(+), 52 deletions(-) create mode 100644 Tools/setup/Dockerfile create mode 100755 Tools/setup/docker-entrypoint.sh diff --git a/Tools/docker_run.sh b/Tools/docker_run.sh index 3ac640428e..24943c04c4 100755 --- a/Tools/docker_run.sh +++ b/Tools/docker_run.sh @@ -1,35 +1,5 @@ #! /bin/bash -if [ -z ${PX4_DOCKER_REPO+x} ]; then - echo "guessing PX4_DOCKER_REPO based on input"; - if [[ $@ =~ .*px4_fmu.* ]]; then - # nuttx-px4fmu-v{1,2,3,4,5} - PX4_DOCKER_REPO="px4io/px4-dev-nuttx-focal:2021-09-08" - elif [[ $@ =~ .*navio2.* ]] || [[ $@ =~ .*raspberry.* ]] || [[ $@ =~ .*beaglebone.* ]] || [[ $@ =~ .*pilotpi.default ]]; then - # beaglebone_blue_default, emlid_navio2_default, px4_raspberrypi_default, scumaker_pilotpi_default - PX4_DOCKER_REPO="px4io/px4-dev-armhf:2021-08-18" - elif [[ $@ =~ .*pilotpi.arm64 ]]; then - # scumaker_pilotpi_arm64 - PX4_DOCKER_REPO="px4io/px4-dev-aarch64:latest" - elif [[ $@ =~ .*navio2.* ]] || [[ $@ =~ .*raspberry.* ]] || [[ $@ =~ .*bebop.* ]]; then - # posix_rpi_cross, posix_bebop_default - PX4_DOCKER_REPO="px4io/px4-dev-armhf:2021-08-18" - elif [[ $@ =~ .*clang.* ]] || [[ $@ =~ .*scan-build.* ]]; then - # clang tools - PX4_DOCKER_REPO="px4io/px4-dev-clang:2021-02-04" - elif [[ $@ =~ .*tests* ]]; then - # run all tests with simulation - PX4_DOCKER_REPO="px4io/px4-dev-simulation-bionic:2021-12-11" - fi -else - echo "PX4_DOCKER_REPO is set to '$PX4_DOCKER_REPO'"; -fi - -# otherwise default to nuttx -if [ -z ${PX4_DOCKER_REPO+x} ]; then - PX4_DOCKER_REPO="px4io/px4-dev-nuttx-focal:2021-09-08" -fi - # docker hygiene #Delete all stopped containers (including data-only containers) @@ -38,30 +8,15 @@ fi #Delete all 'untagged/dangling' () images #docker rmi $(docker images -q -f dangling=true) -echo "PX4_DOCKER_REPO: $PX4_DOCKER_REPO"; +PX4_DOCKER_REPO="px4io/px4-dev" PWD=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) SRC_DIR=$PWD/../ -CCACHE_DIR=${HOME}/.ccache -mkdir -p "${CCACHE_DIR}" - docker run -it --rm -w "${SRC_DIR}" \ - --env=AWS_ACCESS_KEY_ID \ - --env=AWS_SECRET_ACCESS_KEY \ - --env=BRANCH_NAME \ - --env=CCACHE_DIR="${CCACHE_DIR}" \ - --env=CI \ - --env=CODECOV_TOKEN \ - --env=COVERALLS_REPO_TOKEN \ - --env=LOCAL_USER_ID="$(id -u)" \ - --env=PX4_ASAN \ - --env=PX4_MSAN \ - --env=PX4_TSAN \ - --env=PX4_UBSAN \ - --env=TRAVIS_BRANCH \ - --env=TRAVIS_BUILD_ID \ - --publish 14556:14556/udp \ - --volume=${CCACHE_DIR}:${CCACHE_DIR}:rw \ - --volume=${SRC_DIR}:${SRC_DIR}:rw \ - ${PX4_DOCKER_REPO} /bin/bash -c "$1 $2 $3" + --env=LOCAL_USER_ID="$(id -u)" \ + --publish 14556:14556/udp \ + --volume=/tmp/.X11-unix:/tmp/.X11-unix \ + --volume=/tmp:/tmp:rw \ + --volume=${SRC_DIR}:${SRC_DIR}:rw \ + ${PX4_DOCKER_REPO} /bin/bash -c "$1 $2 $3" diff --git a/Tools/setup/Dockerfile b/Tools/setup/Dockerfile new file mode 100644 index 0000000000..ec38d0bcd7 --- /dev/null +++ b/Tools/setup/Dockerfile @@ -0,0 +1,55 @@ +# +# PX4 base development environment +# + +FROM ubuntu:20.04 +LABEL maintainer="Daniel Agar , Ramon Roche " + +ENV DEBIAN_FRONTEND noninteractive +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +# Installing required utilities +RUN apt-get update && apt-get -y --quiet --no-install-recommends install \ + ca-certificates \ + gnupg \ + lsb-core \ + lsb-release \ + sudo \ + software-properties-common \ + wget \ + gosu \ + ; + +# Install PX4 Requirements +COPY Tools/setup/requirements.txt /tmp/requirements.txt +COPY Tools/setup/ubuntu.sh /tmp/ubuntu.sh +# We support pre-downloading the gcc arm none eabi compiler +# to speed up build times, if the file is not present when +# building, the ubuntu.sh script will download it from source +COPY *gcc-arm-none-eabi-9-2020-q2-update-linux.tar.bz2 /tmp/gcc-arm-none-eabi-9-2020-q2-update-linux.tar.bz2 +# The PATH env is set within ubuntu.sh, but given how we +# are running the image using `gosu` to avoid read-only problems +# with the filesystem the env variable does not persist +ENV PATH="/opt/gcc-arm-none-eabi-9-2020-q2-update/bin:$PATH" +ENV PATH="/opt/jdk-14.0.2+12/bin:$PATH" +RUN bash /tmp/ubuntu.sh --from-docker --with-java --with-rtps + +ENV DISPLAY :99 + +ENV FASTRTPSGEN_DIR="/usr/local/bin/" +ENV TERM=xterm +ENV TZ=UTC + +# SITL UDP PORTS +EXPOSE 14556/udp +EXPOSE 14557/udp + +# create user with id 1001 (jenkins docker workflow default) +RUN useradd --shell /bin/bash -u 1001 -c "" -m user && usermod -a -G dialout user + +# create and start as LOCAL_USER_ID +COPY Tools/setup/docker-entrypoint.sh /usr/local/bin/entrypoint.sh +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +CMD ["/bin/bash"] diff --git a/Tools/setup/docker-entrypoint.sh b/Tools/setup/docker-entrypoint.sh new file mode 100755 index 0000000000..4af2a9638a --- /dev/null +++ b/Tools/setup/docker-entrypoint.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Start virtual X server in the background +# - DISPLAY default is :99, set in dockerfile +# - Users can override with `-e DISPLAY=` in `docker run` command to avoid +# running Xvfb and attach their screen +if [[ -x "$(command -v Xvfb)" && "$DISPLAY" == ":99" ]]; then + echo "Starting Xvfb" + Xvfb :99 -screen 0 1600x1200x24+32 & +fi + +# Check if the ROS_DISTRO is passed and use it +# to source the ROS environment +if [ -n "${ROS_DISTRO}" ]; then + source "/opt/ros/$ROS_DISTRO/setup.bash" +fi + +# Use the LOCAL_USER_ID if passed in at runtime +if [ -n "${LOCAL_USER_ID}" ]; then + echo "Starting with UID : $LOCAL_USER_ID" + # modify existing user's id + usermod -u $LOCAL_USER_ID user + + # run as user + exec gosu user "$@" +else + exec "$@" +fi