From 54b33afc2a75394114de0bc8a0ce1cfd08c8123e Mon Sep 17 00:00:00 2001 From: Mindstan Date: Wed, 8 May 2019 16:53:57 +0200 Subject: [PATCH] :sparkles: Improved docker script + added more images --- cross-compilation/run_compilation.sh | 84 +++++++++++++------ .../utcoupe-ros-kinetic-amd64/Dockerfile | 26 ++++++ .../utcoupe-ros-kinetic-armv7/Dockerfile | 4 +- .../utcoupe-ros-melodic-amd64/Dockerfile | 26 ++++++ 4 files changed, 113 insertions(+), 27 deletions(-) create mode 100644 cross-compilation/utcoupe-ros-kinetic-amd64/Dockerfile create mode 100644 cross-compilation/utcoupe-ros-melodic-amd64/Dockerfile diff --git a/cross-compilation/run_compilation.sh b/cross-compilation/run_compilation.sh index ae7b51c..b04146c 100755 --- a/cross-compilation/run_compilation.sh +++ b/cross-compilation/run_compilation.sh @@ -2,41 +2,73 @@ # TODO select architecture compile_arch="armv7" +# TODO ask user +build_image=O +ros_version='kinetic' -img_tag="utcoupe-ros-kinetic-${compile_arch}" -img_dir="utcoupe-ros-kinetic-${compile_arch}" +img_tag="utcoupe-ros-${ros_version}-${compile_arch}" +img_dir="utcoupe-ros-${ros_version}-${compile_arch}" img_ws_root_dir="/utcoupe/coupe18" cross_compilation_dir="${UTCOUPE_WORKSPACE}/cross-compilation" -cross_compilation_install_dir="${cross_compilation_dir}/generated_install/${compile_arch}" +cross_compilation_install_dir="${cross_compilation_dir}/generated_install/${ros_version}/${compile_arch}" -docker build -t ${img_tag} "${cross_compilation_dir}/${img_dir}" +function green_echo() { + echo -e "\033[32m$1\033[0m" +} -mkdir -p "${cross_compilation_install_dir}" +function red_echo() { + echo -e "\033[31m$1\033[0m" +} -# looks slower than the other method -# docker run \ -# -i \ -# --mount type=bind,source="${UTCOUPE_WOKSPACE}",target="${img_ws_root_dir}" \ -# ${img_tag} +function build_image() { + green_echo "Started to build $img_tag..." + docker build -t ${img_tag} "${cross_compilation_dir}/${img_dir}" + green_echo "Done." +} -echo "Generating files in \"${cross_compilation_install_dir}\"" +function run_cross_compilation() { + if [[ -z "$(docker images --format='{{print .Tag}}' | grep ${img_tag})" ]]; then + red_echo "docker image ${img_tag} not found locally." + if [[ ${build_image} -eq 0 ]]; then + docker pull "utcoupe/coupe19:${img_tag}" + else + build_image + fi + fi -docker run \ - -i \ - --mount type=bind,source="${UTCOUPE_WORKSPACE}"/ros_ws/src,target="${img_ws_root_dir}"/ros_ws/src,readonly \ - --mount type=bind,source="${UTCOUPE_WORKSPACE}"/libs,target="${img_ws_root_dir}"/libs,readonly \ - --mount type=bind,source="${cross_compilation_install_dir}",target="${img_ws_root_dir}"/ros_ws/install \ - ${img_tag} -# Makes cmake crash -# --tmpfs "${img_ws_root_dir}"/ros_ws/devel -# --tmpfs "${img_ws_root_dir}"/ros_ws/build + mkdir -p "${cross_compilation_install_dir}" + # looks slower than the other method + # docker run \ + # -i \ + # --mount type=bind,source="${UTCOUPE_WOKSPACE}",target="${img_ws_root_dir}" \ + # ${img_tag} -echo "Creating archive..." -last_directory=$(pwd) -cd "${cross_compilation_install_dir}/../" -tar -czf "${compile_arch}.tgz" "${compile_arch}" -cd "${last_directory}" + green_echo "Generating files in \"${cross_compilation_install_dir}\"..." -echo "DONE, ENJOY THE CROSS-COMPILED BINARIES!" + docker run \ + -i \ + --mount type=bind,source="${UTCOUPE_WORKSPACE}"/ros_ws/src,target="${img_ws_root_dir}"/ros_ws/src \ + --mount type=bind,source="${UTCOUPE_WORKSPACE}"/libs,target="${img_ws_root_dir}"/libs,readonly \ + --mount type=bind,source="${cross_compilation_install_dir}",target="${img_ws_root_dir}"/ros_ws/install \ + "utcoupe/coupe19:${img_tag}" \ + /bin/bash -c "catkin_make install -DCMAKE_BUILD_TYPE=Release" + # Makes cmake crash + # --tmpfs "${img_ws_root_dir}"/ros_ws/devel + # --tmpfs "${img_ws_root_dir}"/ros_ws/build + green_echo "Done." +} + +function create_archive() { + green_echo "Creating archive..." + pushd . + cd "${cross_compilation_install_dir}/../" + tar -czf "${compile_arch}.tgz" "${compile_arch}" + popd +} + +run_cross_compilation +create_archive + +green_echo "DONE, ENJOY THE CROSS-COMPILED BINARIES!" diff --git a/cross-compilation/utcoupe-ros-kinetic-amd64/Dockerfile b/cross-compilation/utcoupe-ros-kinetic-amd64/Dockerfile new file mode 100644 index 0000000..6c58506 --- /dev/null +++ b/cross-compilation/utcoupe-ros-kinetic-amd64/Dockerfile @@ -0,0 +1,26 @@ +FROM ros:kinetic-ros-base-xenial + +ENV UTCOUPE_WORKSPACE /utcoupe/coupe19 +RUN mkdir -p $UTCOUPE_WORKSPACE/ros_ws/src +ENV ROS_LANG_DISABLE=genlisp:geneus + +RUN apt-get update +RUN apt-get install wget libsfml-dev libarmadillo-dev sudo -qq -y +RUN apt-get install ros-kinetic-tf2 ros-kinetic-tf2-ros ros-kinetic-rviz ros-kinetic-diagnostic-updater ros-kinetic-roslint ros-kinetic-camera-info-manager ros-kinetic-rosserial-arduino ros-kinetic-rosbridge-suite ros-kinetic-tf2-web-republisher ros-kinetic-serial ros-kinetic-dynamixel-sdk ros-kinetic-rosserial-python ros-kinetic-tf2-geometry-msgs ros-kinetic-urg-c ros-kinetic-urg-node -y -qq +RUN rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /temp/utcoupe_install +WORKDIR /temp/utcoupe_install +RUN wget https://github.com/utcoupe/coupe18/raw/master/scripts/install_external_nodes.sh && chmod +x install_external_nodes.sh +RUN bash -c "source /opt/ros/kinetic/setup.sh && ./install_external_nodes.sh" +RUN rm -rf /tmp/utcoupe* + +WORKDIR $UTCOUPE_WORKSPACE/ros_ws +# Tests if the setup works +RUN bash -c "source /opt/ros/kinetic/setup.sh && catkin_make" +RUN rm -rf build devel + + +WORKDIR $UTCOUPE_WORKSPACE/ros_ws +CMD echo "Using $UTCOUPE_WORKSPACE as ROS workspace." + diff --git a/cross-compilation/utcoupe-ros-kinetic-armv7/Dockerfile b/cross-compilation/utcoupe-ros-kinetic-armv7/Dockerfile index 386f6c0..3f3fdcd 100644 --- a/cross-compilation/utcoupe-ros-kinetic-armv7/Dockerfile +++ b/cross-compilation/utcoupe-ros-kinetic-armv7/Dockerfile @@ -16,8 +16,10 @@ RUN bash -c "source /opt/ros/kinetic/setup.sh && ./install_external_nodes.sh" RUN rm -rf /tmp/utcoupe* WORKDIR $UTCOUPE_WORKSPACE/ros_ws +# Tests if the setup works RUN bash -c "source /opt/ros/kinetic/setup.sh && catkin_make" +RUN rm -rf build devel WORKDIR $UTCOUPE_WORKSPACE/ros_ws -CMD bash -c "echo $UTCOUPE_WORKSPACE && rm -rf build/* devel/* install/* && catkin_make install -DCMAKE_BUILD_TYPE=Release" +CMD bash -c "echo 'Using' $UTCOUPE_WORKSPACE ' as ROS workspace." diff --git a/cross-compilation/utcoupe-ros-melodic-amd64/Dockerfile b/cross-compilation/utcoupe-ros-melodic-amd64/Dockerfile new file mode 100644 index 0000000..48fe4d3 --- /dev/null +++ b/cross-compilation/utcoupe-ros-melodic-amd64/Dockerfile @@ -0,0 +1,26 @@ +FROM ros:melodic-ros-base-bionic + +ENV UTCOUPE_WORKSPACE /utcoupe/coupe19 +RUN mkdir -p $UTCOUPE_WORKSPACE/ros_ws/src +ENV ROS_LANG_DISABLE=genlisp:geneus + +RUN apt-get update +RUN apt-get install wget libsfml-dev libarmadillo-dev sudo -qq -y +RUN apt-get install ros-melodic-tf2 ros-melodic-tf2-ros ros-melodic-rviz ros-melodic-diagnostic-updater ros-melodic-roslint ros-melodic-camera-info-manager ros-melodic-rosserial-arduino ros-melodic-rosbridge-suite ros-melodic-tf2-web-republisher ros-melodic-serial ros-melodic-dynamixel-sdk ros-melodic-rosserial-python ros-melodic-tf2-geometry-msgs ros-melodic-urg-c ros-melodic-urg-node -y -qq +RUN rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /temp/utcoupe_install +WORKDIR /temp/utcoupe_install +RUN wget https://github.com/utcoupe/coupe19/raw/master/scripts/install_external_nodes.sh && chmod +x install_external_nodes.sh +RUN bash -c "source /opt/ros/melodic/setup.sh && ./install_external_nodes.sh" +RUN rm -rf /tmp/utcoupe* + +WORKDIR $UTCOUPE_WORKSPACE/ros_ws +# Tests if the setup works +RUN bash -c "source /opt/ros/melodic/setup.sh && catkin_make" +RUN rm -rf build devel + + +WORKDIR $UTCOUPE_WORKSPACE/ros_ws +CMD echo "Using $UTCOUPE_WORKSPACE as ROS workspace." +