aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorpaulrbr-fl <43074087+paulrbr-fl@users.noreply.github.com>2018-11-30 14:43:09 +0100
committerGitHub <noreply@github.com>2018-11-30 14:43:09 +0100
commite3f725a16f48d303ddbd8afed0bcdd50c923b33f (patch)
tree1a2be583a43a04a48aebf39ed72c546f2288dccc
parent7778d938b98ee3086a00fc4c932f442d648d23ef (diff)
parent85d8706c5b0f5672025342f70117909177657ff1 (diff)
downloadansible-clever-e3f725a16f48d303ddbd8afed0bcdd50c923b33f.tar.gz
ansible-clever-e3f725a16f48d303ddbd8afed0bcdd50c923b33f.tar.zst
ansible-clever-e3f725a16f48d303ddbd8afed0bcdd50c923b33f.zip
Merge pull request #24 from paulrbr-fl/revert-clever-cli-updatev1.11
Reverting upgrade of clever-tools CLI
-rw-r--r--defaults/main.yml2
-rwxr-xr-xfiles/clever-wait-deploy.sh56
-rw-r--r--tasks/deploy.yml54
-rw-r--r--tasks/setup.yml1
4 files changed, 82 insertions, 31 deletions
diff --git a/defaults/main.yml b/defaults/main.yml
index 9e98511..fb0e30f 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,6 +1,6 @@
1--- 1---
2# defaults file for clever 2# defaults file for clever
3clever_cli_version: 1.1.1 3clever_cli_version: 0.9.3
4clever_user_path: .local/bin 4clever_user_path: .local/bin
5clever_app_root: "{{ app_root | default(playbook_dir + '/..') }}" 5clever_app_root: "{{ app_root | default(playbook_dir + '/..') }}"
6clever_app_confdir: "{{ clever_app_root }}/.clever_cloud" 6clever_app_confdir: "{{ clever_app_root }}/.clever_cloud"
diff --git a/files/clever-wait-deploy.sh b/files/clever-wait-deploy.sh
new file mode 100755
index 0000000..e0bbcf1
--- /dev/null
+++ b/files/clever-wait-deploy.sh
@@ -0,0 +1,56 @@
1#!/bin/bash -e
2
3function deploying {
4 checkStatus "$1" "IN PROGRESS"
5}
6
7function deployed {
8 checkStatus "$1" "OK"
9}
10
11function inactive {
12 local commit="$1"
13 [[ "$(clever activity | grep "$commit" | grep "DEPLOY" | wc -l)" == "0" ]]
14}
15
16function checkStatus {
17 local commit="$1"
18 local status="$2"
19 [[ "$(clever activity | grep "$commit" | grep "${status}\s\+DEPLOY" | wc -l)" == "1" ]]
20}
21
22function check {
23 local timeout=600 # 10 minutes
24 local commit="$1"
25 local samplingTime=5
26
27 echo "Waiting for deployment start..."
28 while inactive "$commit" -a $timeout -gt 0
29 do
30 sleep $samplingTime
31 let "timeout-=$samplingTime"
32 done
33
34 # Wait for completion
35 echo "Deployment in progress..."
36 while deploying "$commit" -a $timeout -gt 0
37 do
38 sleep $samplingTime
39 let "timeout-=$samplingTime"
40 done
41
42 if [ $samplingTime -eq 0 ]
43 then
44 echo "Timeout"
45 fi
46
47 deployed "$commit"
48}
49
50function getHeadRev {
51 local chdir="$1/.git"
52
53 git --git-dir="$chdir" rev-parse HEAD
54}
55
56check "$(getHeadRev "$@")"
diff --git a/tasks/deploy.yml b/tasks/deploy.yml
index cc15050..84ebe73 100644
--- a/tasks/deploy.yml
+++ b/tasks/deploy.yml
@@ -24,15 +24,11 @@
24 tags: 24 tags:
25 - skip_ansible_lint 25 - skip_ansible_lint
26 26
27- name: Deploy to Clever-Cloud 27- name: Push to Clever-Cloud to trigger deployment
28 shell: "clever deploy" 28 command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master"
29 args: 29 args:
30 chdir: "{{ clever_app_root }}" 30 chdir: "{{ clever_app_root }}"
31 environment: 31 register: clever_git_push
32 CONFIGURATION_FILE: "{{ clever_login_file }}"
33 register: clever_deploy
34 async: 900 # 15 minutes timeout
35 poll: 30
36 ignore_errors: true 32 ignore_errors: true
37 tags: 33 tags:
38 - skip_ansible_lint 34 - skip_ansible_lint
@@ -42,35 +38,33 @@
42 args: 38 args:
43 chdir: "{{ clever_app_root }}" 39 chdir: "{{ clever_app_root }}"
44 when: 40 when:
45 - clever_deploy is failed 41 - clever_git_push is failed
46 - clever_deploy.stderr is search("Failed to read git object") 42 - clever_git_push.stderr is search("shallow update not allowed")
47 tags: 43 tags:
48 - skip_ansible_lint 44 - skip_ansible_lint
49 45
50- name: Deploy to Clever-Cloud 46- name: Push to Clever-Cloud to trigger deployment
51 shell: "clever deploy" 47 command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master"
52 args: 48 args:
53 chdir: "{{ clever_app_root }}" 49 chdir: "{{ clever_app_root }}"
54 environment: 50 when: clever_git_push is failed
55 CONFIGURATION_FILE: "{{ clever_login_file }}"
56 when: clever_deploy is failed
57 register: clever_deploy
58 async: 900 # 15 minutes timeout
59 poll: 30
60 ignore_errors: true
61 tags: 51 tags:
62 - skip_ansible_lint 52 - skip_ansible_lint
63 53
64- name: Return deployment logs 54- name: Watch deployment status
65 debug: 55 command: "clever-wait-deploy.sh '{{ clever_app_root }}'"
66 var: clever_deploy.stdout 56 async: 900
67 57 poll: 0
68- name: Return deployment errors 58 register: long_command
69 debug: 59 environment:
70 var: clever_deploy.stderr 60 CONFIGURATION_FILE: "{{ clever_login_file }}"
71 when: clever_deploy is failed 61 changed_when: False
72 62
73- name: Fail on deployment errors 63# Waits up to 15 minutes
74 fail: 64- name: Wait for deployment completion
75 msg: "The clever deployment failed! Please check logs above." 65 async_status:
76 when: clever_deploy is failed 66 jid: "{{ long_command.ansible_job_id }}"
67 register: job_result
68 until: job_result.finished
69 delay: 30
70 retries: 30
diff --git a/tasks/setup.yml b/tasks/setup.yml
index 33b1ff6..f85a635 100644
--- a/tasks/setup.yml
+++ b/tasks/setup.yml
@@ -26,3 +26,4 @@
26 with_items: 26 with_items:
27 - clever-set-domain.sh 27 - clever-set-domain.sh
28 - clever-set-drain.sh 28 - clever-set-drain.sh
29 - clever-wait-deploy.sh