]> git.immae.eu Git - github/fretlink/ansible-clever.git/commitdiff
deploy: remove custom polling script now that the CLI does it for us 63/head
authorPaul Bonaud <paul.bonaud@fretlink.com>
Wed, 17 Jun 2020 09:06:08 +0000 (11:06 +0200)
committerPaul Bonaud <paul.bonaud@fretlink.com>
Wed, 17 Jun 2020 11:03:29 +0000 (13:03 +0200)
See recent changes (https://github.com/CleverCloud/clever-tools/pull/415)
introduced in 2.5.0+ version of the clever cli tools

defaults/main.yml
files/clever-wait-deploy.sh [deleted file]
tasks/deploy.yml
tasks/redeploy.yml [new file with mode: 0644]
tasks/setup.yml
tests/fake.sh

index 0e4bada24411ba3ad23dd55f02ac481ad0974f08..dcf9650e1c8bbc0e729c9c62638b96dada44e5a7 100644 (file)
@@ -1,6 +1,6 @@
 ---
 # defaults file for clever
-clever_cli_version: 1.6.3
+clever_cli_version: 2.6.1
 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
deleted file mode 100755 (executable)
index a95c96f..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/env bash
-
-set -ueo pipefail
-
-VERBOSE=${VERBOSE:-}
-lastCleverActivity=""
-timeout=2300 # 100 seconds less than the Ansible tasks' timeout
-startTime=$(date +%s)
-
-function cleverActivity {
-  lastCleverActivity=$(clever activity)
-}
-
-function ensure {
-  local lastReturnCode="$?"
-
-  VERBOSE=true
-  verbose
-
-  if isNotTimeout
-  then
-    if [ "$lastReturnCode" == "0" ]
-    then
-      echo "✓ Deployment done."
-    else
-      echo "✗ Deployment failed!"
-    fi
-  else
-    echo "⁈ Deployment timeout... Please check clever logs"
-    exit 1
-  fi
-}
-
-function isNotTimeout {
-  [ $(($(date +%s) - startTime)) -lt $timeout ]
-}
-
-trap ensure EXIT ERR
-
-function deploying {
-  checkStatus "$1" "IN PROGRESS"
-}
-
-function deployed {
-  checkStatus "$1" "OK"
-}
-
-function inactive {
-  checkStatus "$1" "" "-v"
-}
-
-function checkStatus {
-  local commit="$1"
-  local status="$2"
-
-  cleverActivity
-  echo "${lastCleverActivity}" | tail -n1 | grep ${3:+ "${3}"} -q -E "${status}.*DEPLOY.*${commit}"
-}
-
-function verbose {
-  if [ -n "${VERBOSE}" ]; then
-    echo -e "\\nLast clever activity:"
-    echo -e "${lastCleverActivity}\\n"
-  fi
-}
-
-function check {
-  local commit="$1"
-  local samplingTime=5
-
-  echo "️▫ Waiting for deployment to start..."
-  while inactive "$commit" && isNotTimeout
-  do
-    verbose
-    sleep $samplingTime
-  done
-
-  # Wait for completion
-  echo "▪ Deployment in progress..."
-  while deploying "$commit" && isNotTimeout
-  do
-    verbose
-    sleep $samplingTime
-  done
-
-  deployed "$commit"
-}
-
-function getHeadRev {
-  local chdir="$1/.git"
-
-  git --git-dir="$chdir" rev-parse HEAD
-}
-
-workdir="$(pwd)"
-check "$(getHeadRev "${workdir}")"
index d5e5a4555fe6e9515dcd4b01a758d1cb92701b99..4d4ecaa4487c974583c4f637b747904c0255f1b2 100644 (file)
     CONFIGURATION_FILE: "{{ clever_login_file }}"
   changed_when: false
 
-#TODO: Improve ssh-key validation
-- name: Accept Clever-Cloud servers
-  shell: "ssh-keyscan -H push-par-clevercloud-customers.services.clever-cloud.com >> ~/.ssh/known_hosts"
-  tags:
-    - skip_ansible_lint
-
 - name: Deploy to Clever-Cloud
-  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 }}"
-  register: clever_deploy
-  ignore_errors: true
-  tags:
-    - skip_ansible_lint
-
-##################################################################
-# Re-deploy only if its the first clever deploy for that project #
-##################################################################
-
-- name: First time push to Clever-Cloud needs a full git clone
-  command: "git fetch --unshallow"
-  args:
-    chdir: "{{ clever_app_root }}"
-  when:
-    - clever_deploy is failed
-    - clever_deploy.stderr is defined
-    - clever_deploy.stderr is search("Failed to read git object")
-  tags:
-    - skip_ansible_lint
-
-- name: Deploy to Clever-Cloud
-  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 }}"
-  when:
-    - clever_deploy is failed
-    - clever_deploy.stderr is defined
-    - clever_deploy.stderr is search("Failed to read git object")
-  register: clever_deploy
-  tags:
-    - skip_ansible_lint
-
-##############################################################################
-# Poll deployment status from 'clever activity' command.                     #
-# 'clever deploy' command is not yet 100% reliable to get a blocking command #
-# until the deployment is over. Hence the need for a custom waiting script.  #
-##############################################################################
-
-- name: Watch deployment status
-  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-wait-deploy.sh"
+  shell: "clever deploy --force"
   args:
     chdir: "{{ clever_app_root }}"
   environment:
     CONFIGURATION_FILE: "{{ clever_login_file }}"
   async: 2400 # 40 minutes
   poll: 0
-  register: long_command
-  changed_when: False
+  ignore_errors: true
+  register: clever_deploy
+  tags:
+    - skip_ansible_lint
 
-- name: Wait 40 minutes for deployment completion
+- name: Wait up to 40 minutes for deployment completion
   async_status:
-    jid: "{{ long_command.ansible_job_id }}"
+    jid: "{{ clever_deploy.ansible_job_id }}"
   register: job_result
   until: job_result.finished
   ignore_errors: true
   delay: 30
   retries: 80 # 40 minutes (80 * 30 secs delay)
 
-- name: Waiting script logs (stdout)
+##################################################################
+# Re-deploy only if its the first clever deploy for that project #
+##################################################################
+
+- name: Retry deploy to clever-cloud
+  include_tasks: redeploy.yml
+  when:
+    - not job_result.rc == 0
+    - job_result.stderr is defined
+    - job_result.stderr is search("Failed to read git object")
+
+- name: Deploy logs (stdout)
   debug:
     var: job_result.stdout_lines
   when: job_result.stdout_lines is defined
 
-- name: Waiting script logs (stderr)
+- name: Deploy error logs (stderr)
   debug:
     var: job_result.stderr_lines
   when: job_result.stderr_lines is defined
diff --git a/tasks/redeploy.yml b/tasks/redeploy.yml
new file mode 100644 (file)
index 0000000..38068da
--- /dev/null
@@ -0,0 +1,33 @@
+---
+##################################################################
+# Re-deploy only if its the first clever deploy for that project #
+##################################################################
+
+- name: First time push to Clever-Cloud needs a full git clone
+  command: "git fetch --unshallow"
+  args:
+    chdir: "{{ clever_app_root }}"
+  tags:
+    - skip_ansible_lint
+
+- name: Deploy to Clever-Cloud
+  shell: "clever deploy --force"
+  args:
+    chdir: "{{ clever_app_root }}"
+  environment:
+    CONFIGURATION_FILE: "{{ clever_login_file }}"
+  async: 2400 # 40 minutes
+  poll: 0
+  ignore_errors: true
+  register: clever_deploy
+  tags:
+    - skip_ansible_lint
+
+- name: Wait up to 40 minutes for deployment completion
+  async_status:
+    jid: "{{ clever_deploy.ansible_job_id }}"
+  register: job_result
+  until: job_result.finished
+  ignore_errors: true
+  delay: 30
+  retries: 80 # 40 minutes (80 * 30 secs delay)
index c5abb81e890b9a1db1b7bba994b996d5a46be13b..a2d5b900b875d5ae231eb5f030aa4f92375ad1e7 100644 (file)
@@ -17,7 +17,7 @@
     src: "{{ clever_repo }}/{{ clever_tools_archive }}"
     dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}"
   vars:
-    clever_repo: https://clever-tools.cellar.services.clever-cloud.com/releases
+    clever_repo: https://clever-tools.clever-cloud.com/releases
     clever_tools_archive: "{{ clever_cli_version }}/clever-tools-{{ clever_cli_version }}_linux.tar.gz"
   when: clever_returned_version is failed or clever_returned_version.stdout != clever_cli_version
 
@@ -27,6 +27,5 @@
     dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}/{{ item }}"
     mode: 0755
   with_items:
-    - clever-wait-deploy.sh
     - clever-set-domain.sh
     - clever-set-drain.sh
index 2835e854f50dcbcc403cba9a9eff69f3dbff2112..75bc0514d8b22407f45355259ce8ae74936b2ddb 100755 (executable)
@@ -4,7 +4,7 @@ binary="${0/*\/}"
 fakeCommit="aaa000aaa000aaa000aaa000aaa000aaa000aaa0"
 
 if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then
-    echo "1.6.3"
+    echo "2.6.1"
 elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then
     echo "2020-02-02T20:20:02+02:00  OK         DEPLOY     ${fakeCommit}  Git"
 elif [ "${binary}" = "git" ]; then