diff options
author | Paul Bonaud <paul.bonaud@fretlink.com> | 2019-07-30 17:57:55 +0200 |
---|---|---|
committer | Paul Bonaud <paul.bonaud@fretlink.com> | 2019-07-31 14:18:37 +0200 |
commit | fa045db6b7d85f1c5aa53b8fba86958bde4b368b (patch) | |
tree | bd8a49590b380867bd2688800ff772a0ae9b8669 /files | |
parent | 8305eb92f5bb6445868fda6d4e3075011d1fd248 (diff) | |
download | ansible-clever-fa045db6b7d85f1c5aa53b8fba86958bde4b368b.tar.gz ansible-clever-fa045db6b7d85f1c5aa53b8fba86958bde4b368b.tar.zst ansible-clever-fa045db6b7d85f1c5aa53b8fba86958bde4b368b.zip |
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.
Diffstat (limited to 'files')
-rwxr-xr-x | files/clever-wait-deploy.sh | 80 |
1 files changed, 80 insertions, 0 deletions
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 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | set -ueo pipefail | ||
4 | |||
5 | VERBOSE=${VERBOSE:-} | ||
6 | lastCleverActivity="" | ||
7 | |||
8 | function cleverActivity { | ||
9 | lastCleverActivity=$(clever activity) | ||
10 | } | ||
11 | |||
12 | function ensure { | ||
13 | if [ "$?" == "1" ] | ||
14 | then | ||
15 | echo "✗ Deployment failed!" | ||
16 | fi | ||
17 | VERBOSE=true | ||
18 | verbose | ||
19 | } | ||
20 | |||
21 | trap ensure EXIT ERR | ||
22 | |||
23 | function deploying { | ||
24 | checkStatus "$1" "IN PROGRESS" | ||
25 | } | ||
26 | |||
27 | function deployed { | ||
28 | checkStatus "$1" "OK" | ||
29 | } | ||
30 | |||
31 | function inactive { | ||
32 | checkStatus "$1" "" "-v" | ||
33 | } | ||
34 | |||
35 | function checkStatus { | ||
36 | local commit="$1" | ||
37 | local status="$2" | ||
38 | |||
39 | cleverActivity | ||
40 | echo "${lastCleverActivity}" | tail -n1 | grep ${3:+ "${3}"} -q -E "${status}.*DEPLOY.*${commit}" | ||
41 | } | ||
42 | |||
43 | function verbose { | ||
44 | if [ -n "${VERBOSE}" ]; then | ||
45 | echo -e "\\nLast clever activity:" | ||
46 | echo -e "${lastCleverActivity}\\n" | ||
47 | fi | ||
48 | } | ||
49 | |||
50 | function check { | ||
51 | local commit="$1" | ||
52 | local samplingTime=5 | ||
53 | |||
54 | echo "️▫ Waiting for deployment to start..." | ||
55 | while inactive "$commit" | ||
56 | do | ||
57 | verbose | ||
58 | sleep $samplingTime | ||
59 | done | ||
60 | |||
61 | # Wait for completion | ||
62 | echo "▪ Deployment in progress..." | ||
63 | while deploying "$commit" | ||
64 | do | ||
65 | verbose | ||
66 | sleep $samplingTime | ||
67 | done | ||
68 | |||
69 | deployed "$commit" | ||
70 | echo "✓ Deployment done." | ||
71 | } | ||
72 | |||
73 | function getHeadRev { | ||
74 | local chdir="$1/.git" | ||
75 | |||
76 | git --git-dir="$chdir" rev-parse HEAD | ||
77 | } | ||
78 | |||
79 | workdir="$(pwd)" | ||
80 | check "$(getHeadRev "${workdir}")" | ||