From fa045db6b7d85f1c5aa53b8fba86958bde4b368b Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Tue, 30 Jul 2019 17:57:55 +0200 Subject: deploy: revert back to git push + polling In #19 we removed the polling script to rely on the clever cli's ability to wait on `clever deploy` command. After more than 6 months of experimentation it seems the command is still not reliable (sometimes the command never returns, sometimes it returns even when the deployment has finished..). Thus we are reverting back to our manual process of polling `clever activity` every 5 seconds. The timeout for this polling is set at the Ansible level (not in the bash script) and set for 40 minutes. This should give enough time for any of our applications to deploy. --- files/clever-wait-deploy.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 files/clever-wait-deploy.sh (limited to 'files') diff --git a/files/clever-wait-deploy.sh b/files/clever-wait-deploy.sh new file mode 100755 index 0000000..98c5c37 --- /dev/null +++ b/files/clever-wait-deploy.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +set -ueo pipefail + +VERBOSE=${VERBOSE:-} +lastCleverActivity="" + +function cleverActivity { + lastCleverActivity=$(clever activity) +} + +function ensure { + if [ "$?" == "1" ] + then + echo "✗ Deployment failed!" + fi + VERBOSE=true + verbose +} + +trap ensure EXIT ERR + +function deploying { + checkStatus "$1" "IN PROGRESS" +} + +function deployed { + checkStatus "$1" "OK" +} + +function inactive { + checkStatus "$1" "" "-v" +} + +function checkStatus { + local commit="$1" + local status="$2" + + cleverActivity + echo "${lastCleverActivity}" | tail -n1 | grep ${3:+ "${3}"} -q -E "${status}.*DEPLOY.*${commit}" +} + +function verbose { + if [ -n "${VERBOSE}" ]; then + echo -e "\\nLast clever activity:" + echo -e "${lastCleverActivity}\\n" + fi +} + +function check { + local commit="$1" + local samplingTime=5 + + echo "️▫ Waiting for deployment to start..." + while inactive "$commit" + do + verbose + sleep $samplingTime + done + + # Wait for completion + echo "▪ Deployment in progress..." + while deploying "$commit" + do + verbose + sleep $samplingTime + done + + deployed "$commit" + echo "✓ Deployment done." +} + +function getHeadRev { + local chdir="$1/.git" + + git --git-dir="$chdir" rev-parse HEAD +} + +workdir="$(pwd)" +check "$(getHeadRev "${workdir}")" -- cgit v1.2.3