From d282ae808ee247ec7a2f471338fea76c7fd0ea3a Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Fri, 30 Nov 2018 14:38:01 +0100 Subject: Revert "Merge pull request #20 from paulrbr-fl/update-clever-tools" This reverts commit b17a839d622bdb36ddbe2e0667559c33e9b7fd8a, reversing changes made to 695ceaa28821660e17a1cf819cffebe1b5d8c7ca. --- tasks/deploy.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tasks/deploy.yml b/tasks/deploy.yml index cc15050..10c02c4 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml @@ -71,6 +71,5 @@ when: clever_deploy is failed - name: Fail on deployment errors - fail: - msg: "The clever deployment failed! Please check logs above." + fail: "The clever deployment failed! Please check logs above." when: clever_deploy is failed -- cgit v1.2.3 From 85d8706c5b0f5672025342f70117909177657ff1 Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Fri, 30 Nov 2018 14:38:25 +0100 Subject: Revert "Merge pull request #19 from paulrbr-fl/update-clever-tools" This reverts commit 695ceaa28821660e17a1cf819cffebe1b5d8c7ca, reversing changes made to 5485dbc4db3e141673457475bcda5fc88057739f. --- defaults/main.yml | 2 +- files/clever-wait-deploy.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++ tasks/deploy.yml | 53 +++++++++++++++++++----------------------- tasks/setup.yml | 1 + 4 files changed, 82 insertions(+), 30 deletions(-) create mode 100755 files/clever-wait-deploy.sh 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 @@ --- # defaults file for clever -clever_cli_version: 1.1.1 +clever_cli_version: 0.9.3 clever_user_path: .local/bin clever_app_root: "{{ app_root | default(playbook_dir + '/..') }}" clever_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 @@ +#!/bin/bash -e + +function deploying { + checkStatus "$1" "IN PROGRESS" +} + +function deployed { + checkStatus "$1" "OK" +} + +function inactive { + local commit="$1" + [[ "$(clever activity | grep "$commit" | grep "DEPLOY" | wc -l)" == "0" ]] +} + +function checkStatus { + local commit="$1" + local status="$2" + [[ "$(clever activity | grep "$commit" | grep "${status}\s\+DEPLOY" | wc -l)" == "1" ]] +} + +function check { + local timeout=600 # 10 minutes + local commit="$1" + local samplingTime=5 + + echo "Waiting for deployment start..." + while inactive "$commit" -a $timeout -gt 0 + do + sleep $samplingTime + let "timeout-=$samplingTime" + done + + # Wait for completion + echo "Deployment in progress..." + while deploying "$commit" -a $timeout -gt 0 + do + sleep $samplingTime + let "timeout-=$samplingTime" + done + + if [ $samplingTime -eq 0 ] + then + echo "Timeout" + fi + + deployed "$commit" +} + +function getHeadRev { + local chdir="$1/.git" + + git --git-dir="$chdir" rev-parse HEAD +} + +check "$(getHeadRev "$@")" diff --git a/tasks/deploy.yml b/tasks/deploy.yml index 10c02c4..84ebe73 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml @@ -24,15 +24,11 @@ tags: - skip_ansible_lint -- name: Deploy to Clever-Cloud - shell: "clever deploy" +- name: Push to Clever-Cloud to trigger deployment + command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master" args: chdir: "{{ clever_app_root }}" - environment: - CONFIGURATION_FILE: "{{ clever_login_file }}" - register: clever_deploy - async: 900 # 15 minutes timeout - poll: 30 + register: clever_git_push ignore_errors: true tags: - skip_ansible_lint @@ -42,34 +38,33 @@ args: chdir: "{{ clever_app_root }}" when: - - clever_deploy is failed - - clever_deploy.stderr is search("Failed to read git object") + - clever_git_push is failed + - clever_git_push.stderr is search("shallow update not allowed") tags: - skip_ansible_lint -- name: Deploy to Clever-Cloud - shell: "clever deploy" +- name: Push to Clever-Cloud to trigger deployment + command: "git push --force git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/{{ clever_app }}.git HEAD:refs/heads/master" args: chdir: "{{ clever_app_root }}" - environment: - CONFIGURATION_FILE: "{{ clever_login_file }}" - when: clever_deploy is failed - register: clever_deploy - async: 900 # 15 minutes timeout - poll: 30 - ignore_errors: true + when: clever_git_push is failed tags: - skip_ansible_lint -- name: Return deployment logs - debug: - var: clever_deploy.stdout - -- name: Return deployment errors - debug: - var: clever_deploy.stderr - when: clever_deploy is failed +- name: Watch deployment status + command: "clever-wait-deploy.sh '{{ clever_app_root }}'" + async: 900 + poll: 0 + register: long_command + environment: + CONFIGURATION_FILE: "{{ clever_login_file }}" + changed_when: False -- name: Fail on deployment errors - fail: "The clever deployment failed! Please check logs above." - when: clever_deploy is failed +# Waits up to 15 minutes +- name: Wait for deployment completion + async_status: + jid: "{{ long_command.ansible_job_id }}" + register: job_result + until: job_result.finished + delay: 30 + 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 @@ with_items: - clever-set-domain.sh - clever-set-drain.sh + - clever-wait-deploy.sh -- cgit v1.2.3