]> git.immae.eu Git - github/fretlink/ansible-clever.git/commitdiff
deploy_task: Update clever CLI tools and use it instead of git push
authorPaul Bonaud <paul.bonaud@fretlink.com>
Wed, 21 Nov 2018 12:20:56 +0000 (13:20 +0100)
committerPaul Bonaud <paul.bonaud@fretlink.com>
Mon, 14 Jan 2019 10:25:32 +0000 (11:25 +0100)
Updating to latest version of 1.1.1 helps to have a stable `clever
deploy` command.

This commit relies on the output of the command instead of manually
pooling the results with `clever activity` command.

defaults/main.yml
files/clever-wait-deploy.sh [deleted file]
tasks/deploy.yml
tasks/setup.yml

index b1605c657e17415a1aa0a35b02e25016df99a70a..3e030cba74918d04e05b8af56a277848f0fb805e 100644 (file)
@@ -1,6 +1,6 @@
 ---
 # defaults file for clever
-clever_cli_version: 0.9.3
+clever_cli_version: 1.3.0
 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 b911069..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/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 {
-  git rev-parse HEAD
-}
-
-check "$(getHeadRev)"
index ae7e5f6471320cda444623e836f3daf6423d94b8..09cf10ea8dbb6098ef1b9df2b4886832f363c4f9 100644 (file)
   tags:
     - skip_ansible_lint
 
-- 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"
+- name: Deploy to Clever-Cloud
+  shell: "clever deploy --force"
   args:
     chdir: "{{ clever_app_root }}"
-  register: clever_git_push
+  environment:
+    CONFIGURATION_FILE: "{{ clever_login_file }}"
+  register: clever_deploy
+  async: 900 # 15 minutes timeout
+  poll: 30
   ignore_errors: true
   tags:
     - skip_ansible_lint
   args:
     chdir: "{{ clever_app_root }}"
   when:
-    - clever_git_push is failed
-    - clever_git_push.stderr is search("shallow update not allowed")
+    - clever_deploy is failed
+    - clever_deploy.stderr is defined
+    - clever_deploy.stderr is search("Failed to read git object")
   tags:
     - skip_ansible_lint
 
-- 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"
+- name: Deploy to Clever-Cloud
+  shell: "clever deploy --force"
   args:
     chdir: "{{ clever_app_root }}"
-  when: clever_git_push is failed
+  environment:
+    CONFIGURATION_FILE: "{{ clever_login_file }}"
+  when: clever_deploy is failed
+  register: clever_deploy
+  async: 900 # 15 minutes timeout
+  poll: 30
+  ignore_errors: true
   tags:
     - skip_ansible_lint
 
-- name: Watch deployment status
-  command: "clever-wait-deploy.sh"
-  args:
-    chdir: "{{ clever_app_root }}"
-  async: 900
-  poll: 0
-  register: long_command
-  environment:
-    CONFIGURATION_FILE: "{{ clever_login_file }}"
-  changed_when: False
+- name: Return deployment logs
+  debug:
+    var: clever_deploy.stdout
+  when: clever_deploy.stdout is defined
+
+- name: Return deployment errors
+  debug:
+    var: clever_deploy.stderr
+  when:
+    - clever_deploy is failed
+    - clever_deploy.stderr is defined
 
-# 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
+- name: Fail on deployment errors
+  fail: "The clever deployment failed! Please check logs above."
+  when: clever_deploy is failed
index f85a635400e2dd0c499ff7cc77976f3978040d82..33b1ff62a5ea87be40a693cf1c7e6d7b4569e94b 100644 (file)
@@ -26,4 +26,3 @@
   with_items:
     - clever-set-domain.sh
     - clever-set-drain.sh
-    - clever-wait-deploy.sh