aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--defaults/main.yml2
-rwxr-xr-xfiles/clever-wait-deploy.sh54
-rw-r--r--tasks/deploy.yml59
-rw-r--r--tasks/setup.yml1
4 files changed, 34 insertions, 82 deletions
diff --git a/defaults/main.yml b/defaults/main.yml
index b1605c6..3e030cb 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: 0.9.3 3clever_cli_version: 1.3.0
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
deleted file mode 100755
index b911069..0000000
--- a/files/clever-wait-deploy.sh
+++ /dev/null
@@ -1,54 +0,0 @@
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 git rev-parse HEAD
52}
53
54check "$(getHeadRev)"
diff --git a/tasks/deploy.yml b/tasks/deploy.yml
index ae7e5f6..09cf10e 100644
--- a/tasks/deploy.yml
+++ b/tasks/deploy.yml
@@ -30,11 +30,15 @@
30 tags: 30 tags:
31 - skip_ansible_lint 31 - skip_ansible_lint
32 32
33- name: Push to Clever-Cloud to trigger deployment 33- name: Deploy to Clever-Cloud
34 command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master" 34 shell: "clever deploy --force"
35 args: 35 args:
36 chdir: "{{ clever_app_root }}" 36 chdir: "{{ clever_app_root }}"
37 register: clever_git_push 37 environment:
38 CONFIGURATION_FILE: "{{ clever_login_file }}"
39 register: clever_deploy
40 async: 900 # 15 minutes timeout
41 poll: 30
38 ignore_errors: true 42 ignore_errors: true
39 tags: 43 tags:
40 - skip_ansible_lint 44 - skip_ansible_lint
@@ -44,35 +48,38 @@
44 args: 48 args:
45 chdir: "{{ clever_app_root }}" 49 chdir: "{{ clever_app_root }}"
46 when: 50 when:
47 - clever_git_push is failed 51 - clever_deploy is failed
48 - clever_git_push.stderr is search("shallow update not allowed") 52 - clever_deploy.stderr is defined
53 - clever_deploy.stderr is search("Failed to read git object")
49 tags: 54 tags:
50 - skip_ansible_lint 55 - skip_ansible_lint
51 56
52- name: Push to Clever-Cloud to trigger deployment 57- name: Deploy to Clever-Cloud
53 command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master" 58 shell: "clever deploy --force"
54 args: 59 args:
55 chdir: "{{ clever_app_root }}" 60 chdir: "{{ clever_app_root }}"
56 when: clever_git_push is failed 61 environment:
62 CONFIGURATION_FILE: "{{ clever_login_file }}"
63 when: clever_deploy is failed
64 register: clever_deploy
65 async: 900 # 15 minutes timeout
66 poll: 30
67 ignore_errors: true
57 tags: 68 tags:
58 - skip_ansible_lint 69 - skip_ansible_lint
59 70
60- name: Watch deployment status 71- name: Return deployment logs
61 command: "clever-wait-deploy.sh" 72 debug:
62 args: 73 var: clever_deploy.stdout
63 chdir: "{{ clever_app_root }}" 74 when: clever_deploy.stdout is defined
64 async: 900 75
65 poll: 0 76- name: Return deployment errors
66 register: long_command 77 debug:
67 environment: 78 var: clever_deploy.stderr
68 CONFIGURATION_FILE: "{{ clever_login_file }}" 79 when:
69 changed_when: False 80 - clever_deploy is failed
81 - clever_deploy.stderr is defined
70 82
71# Waits up to 15 minutes 83- name: Fail on deployment errors
72- name: Wait for deployment completion 84 fail: "The clever deployment failed! Please check logs above."
73 async_status: 85 when: clever_deploy is failed
74 jid: "{{ long_command.ansible_job_id }}"
75 register: job_result
76 until: job_result.finished
77 delay: 30
78 retries: 30
diff --git a/tasks/setup.yml b/tasks/setup.yml
index f85a635..33b1ff6 100644
--- a/tasks/setup.yml
+++ b/tasks/setup.yml
@@ -26,4 +26,3 @@
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