aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/deploy.yml
diff options
context:
space:
mode:
Diffstat (limited to 'tasks/deploy.yml')
-rw-r--r--tasks/deploy.yml93
1 files changed, 32 insertions, 61 deletions
diff --git a/tasks/deploy.yml b/tasks/deploy.yml
index 74232a6..df02464 100644
--- a/tasks/deploy.yml
+++ b/tasks/deploy.yml
@@ -31,18 +31,18 @@
31 - skip_ansible_lint 31 - skip_ansible_lint
32 32
33- name: Deploy to Clever-Cloud 33- name: Deploy to Clever-Cloud
34 shell: "clever deploy --force" 34 command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master"
35 args: 35 args:
36 chdir: "{{ clever_app_root }}" 36 chdir: "{{ clever_app_root }}"
37 environment:
38 CONFIGURATION_FILE: "{{ clever_login_file }}"
39 register: clever_deploy 37 register: clever_deploy
40 async: 900 # 15 minutes timeout
41 poll: 30
42 ignore_errors: true 38 ignore_errors: true
43 tags: 39 tags:
44 - skip_ansible_lint 40 - skip_ansible_lint
45 41
42##################################################################
43# Re-deploy only if its the first clever deploy for that project #
44##################################################################
45
46- name: First time push to Clever-Cloud needs a full git clone 46- name: First time push to Clever-Cloud needs a full git clone
47 command: "git fetch --unshallow" 47 command: "git fetch --unshallow"
48 args: 48 args:
@@ -55,72 +55,43 @@
55 - skip_ansible_lint 55 - skip_ansible_lint
56 56
57- name: Deploy to Clever-Cloud 57- name: Deploy to Clever-Cloud
58 shell: "clever deploy --force" 58 command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master"
59 args: 59 args:
60 chdir: "{{ clever_app_root }}" 60 chdir: "{{ clever_app_root }}"
61 environment: 61 when:
62 CONFIGURATION_FILE: "{{ clever_login_file }}" 62 - clever_deploy is failed
63 when: clever_deploy is failed 63 - clever_deploy.stderr is defined
64 - clever_deploy.stderr is search("Failed to read git object")
64 register: clever_deploy 65 register: clever_deploy
65 async: 900 # 15 minutes timeout
66 poll: 30
67 ignore_errors: true
68 tags: 66 tags:
69 - skip_ansible_lint 67 - skip_ansible_lint
70 68
71- name: Return deployment logs 69##############################################################################
72 debug: 70# Poll deployment status from 'clever activity' command. #
73 var: clever_deploy.stdout 71# 'clever deploy' command is not yet 100% reliable to get a blocking command #
74 when: clever_deploy.stdout is defined 72# until the deployment is over. Hence the need for a custom waiting script. #
75 73##############################################################################
76- name: Return deployment errors
77 debug:
78 var: clever_deploy.stderr
79 when:
80 - clever_deploy is failed
81 - clever_deploy.stderr is defined
82 74
83- name: Retrieve clever activity 75- name: Watch deployment status
84 command: clever activity 76 command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-wait-deploy.sh"
85 args: 77 args:
86 chdir: "{{ clever_app_root }}" 78 chdir: "{{ clever_app_root }}"
87 environment: 79 environment:
88 CONFIGURATION_FILE: "{{ clever_login_file }}" 80 CONFIGURATION_FILE: "{{ clever_login_file }}"
89 changed_when: false 81 async: 2400 # 40 minutes
90 register: clever_activity_result 82 poll: 0
91 83 register: long_command
92- name: Display clever activity 84 changed_when: False
93 debug:
94 var: clever_activity_result.stdout_lines
95 85
96- name: Get current commit sha 86- name: Wait 40 minutes for deployment completion
97 command: git show -q --format=format:%H HEAD 87 async_status:
98 args: 88 jid: "{{ long_command.ansible_job_id }}"
99 chdir: "{{ clever_app_root }}" 89 register: job_result
100 warn: False 90 until: job_result.finished
101 changed_when: false 91 delay: 30
102 register: current_commit_sha 92 retries: 80 # 40 minutes (80 * 30 secs delay)
103 93
104# #### 94# Output of waiting script stdout
105# Expects all configuration to be located in the project's repository. 95- name: Output waiting script logs
106# Making a git commit bound to the same *configuration* and *executable* version. 96 debug:
107# ## 97 var: job_result.stdout_lines
108- name: Fail if current commit is not the last deployed one
109 fail:
110 msg: "The clever deployment failed! Please check latest deploy activity logs above."
111 when:
112 - clever_deploy is failed
113 - clever_deploy.stderr is defined
114 - clever_deploy.stderr is search("application is up-to-date")
115 - |
116 (current_commit_sha.stdout_lines[-1] not in clever_activity_result.stdout_lines[-1])
117 or
118 (clever_activity_valid_deploy_keyword not in clever_activity_result.stdout_lines[-1])
119
120- name: Fail on any other deployment errors
121 fail:
122 msg: "The clever deployment failed! Please check logs above."
123 when:
124 - clever_deploy is failed
125 - clever_deploy.stderr is defined
126 - clever_deploy.stderr is not search("application is up-to-date")