From c3e2ff5e0f31c61eae330a1a41d7a8a83435d9bd Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Thu, 6 Aug 2020 11:44:26 +0200 Subject: deploy: try to restart the app when the CLI asks to do it In some cases (rollback or deployment errored on clever side), clever-tools will fail when calling `clever deploy` because it thinks the currently being deployed commit is already deployed. However in some cases the git pushed commit is not the currently running commit. Leading to a failure in our deployment process. The proposed solution from the clever tools error is to launch `clever restart`. Until we wait for https://github.com/CleverCloud/clever-tools/issues/422 to be fixed, let's do what the error message say: try to restart in case of a deployment failure. --- tasks/deploy.yml | 7 +++++++ tasks/restart.yml | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'tasks') diff --git a/tasks/deploy.yml b/tasks/deploy.yml index 8dda5e0..39b5845 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml @@ -85,6 +85,13 @@ - job_result.stderr is defined - job_result.stderr is search("Failed to read git object") +- name: Restart app on clever-cloud when error asks to restart + include_tasks: restart.yml + when: + - not job_result.finished or not job_result.rc == 0 + - job_result.stderr is defined + - job_result.stderr is search("clever restart") + - name: Deploy logs (stdout) debug: var: job_result.stdout_lines diff --git a/tasks/restart.yml b/tasks/restart.yml index e2a8891..1c52032 100644 --- a/tasks/restart.yml +++ b/tasks/restart.yml @@ -1,6 +1,13 @@ --- +- name: Get current HEAD commit revision + command: "git rev-parse HEAD" # noqa 303 + register: git_head_revision + args: + chdir: "{{ clever_app_root }}" + changed_when: false + - name: Restart app on Clever-Cloud - shell: "clever restart" + shell: "clever restart --commit {{ git_head_revision.stdout_lines | first }}" args: chdir: "{{ clever_app_root }}" environment: -- cgit v1.2.3