From 52fbe86e0f4465ff7ad0a0e0777b96d69dd666a1 Mon Sep 17 00:00:00 2001 From: Artem Smirnov Date: Wed, 10 Oct 2018 15:28:29 +0300 Subject: [PATCH] image: Add my_travis_retry for pip install --- builder/image-ros.sh | 27 +++++++++++++++++++++++++-- builder/image-software.sh | 31 +++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/builder/image-ros.sh b/builder/image-ros.sh index 28b8fe41..facbd6f3 100755 --- a/builder/image-ros.sh +++ b/builder/image-ros.sh @@ -37,6 +37,29 @@ echo_stamp() { echo -e ${TEXT} } +# https://gist.github.com/letmaik/caa0f6cc4375cbfcc1ff26bd4530c2a3 +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh +my_travis_retry() { + local result=0 + local count=1 + while [ $count -le 3 ]; do + [ $result -ne 0 ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2 + } + # ! { } ignores set -e, see https://stackoverflow.com/a/4073372 + ! { "$@"; result=$?; } + [ $result -eq 0 ] && break + count=$(($count + 1)) + sleep 1 + done + + [ $count -gt 3 ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2 + } + + return $result +} + # TODO: 'kinetic-rosdep-clever.yaml' should add only if we use our repo? echo_stamp "Init rosdep" \ && rosdep init \ @@ -128,8 +151,8 @@ echo_stamp "Installing CLEVER" \ && git checkout ${REF} \ && cd /home/pi/catkin_ws \ && resolve_rosdep $(pwd) \ -&& pip install wheel \ -&& pip install -r /home/pi/catkin_ws/src/clever/clever/requirements.txt \ +&& my_travis_retry pip install wheel \ +&& my_travis_retry pip install -r /home/pi/catkin_ws/src/clever/clever/requirements.txt \ && source /opt/ros/kinetic/setup.bash \ && catkin_make -j${NUMBER_THREADS} -DCMAKE_BUILD_TYPE=Release \ && ln -s /root/roscore.service /lib/systemd/system/roscore.service \ diff --git a/builder/image-software.sh b/builder/image-software.sh index 71a56144..ef3ab9cb 100755 --- a/builder/image-software.sh +++ b/builder/image-software.sh @@ -30,6 +30,29 @@ echo_stamp() { echo -e ${TEXT} } +# https://gist.github.com/letmaik/caa0f6cc4375cbfcc1ff26bd4530c2a3 +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh +my_travis_retry() { + local result=0 + local count=1 + while [ $count -le 3 ]; do + [ $result -ne 0 ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2 + } + # ! { } ignores set -e, see https://stackoverflow.com/a/4073372 + ! { "$@"; result=$?; } + [ $result -eq 0 ] && break + count=$(($count + 1)) + sleep 1 + done + + [ $count -gt 3 ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2 + } + + return $result +} + echo_stamp "Install apt keys & repos" # TODO: This STDOUT consist 'OK' @@ -84,12 +107,12 @@ sudo sed -i "s/updates_available//" /usr/share/byobu/status/status # sudo sed -i "s/updates_available//" /home/pi/.byobu/status echo_stamp "Upgrade pip" -pip install --upgrade pip -pip3 install --upgrade pip3 +my_travis_retry pip install --upgrade pip +my_travis_retry pip3 install --upgrade pip3 echo_stamp "Install and enable Butterfly (web terminal)" -pip3 install butterfly -pip3 install butterfly[systemd] +my_travis_retry pip3 install butterfly +my_travis_retry pip3 install butterfly[systemd] ln -s /root/butterfly.service /lib/systemd/system/ ln -s /root/butterfly.socket /lib/systemd/system/ systemctl enable butterfly.socket