]> git.immae.eu Git - github/fretlink/ansible-clever.git/commitdiff
Don't run `clever deploy` if the app is up-to-date
authorClement Delafargue <clement.delafargue@fretlink.com>
Wed, 24 Jun 2020 09:34:28 +0000 (11:34 +0200)
committerClement Delafargue <clement.delafargue@fretlink.com>
Tue, 30 Jun 2020 13:31:19 +0000 (15:31 +0200)
Running `git push` when the remote is up-to-date
no-ops (it does not trigger a deployment, but it does not fail either).

Running `clever deploy` when the remote is up-to-date triggers a failure. Here, we care about the _end result_ (ie the app is deployed on the correct commit), so no-oping is more appropriate.

This behaviour is not baked in `clever-tools`, but I think it should. I opened an issue. This script
is a temporary workaround. (at least I hope it's temporary)
https://github.com/CleverCloud/clever-tools/issues/422

files/clever-deploy.sh [new file with mode: 0755]
tasks/deploy.yml
tasks/setup.yml

diff --git a/files/clever-deploy.sh b/files/clever-deploy.sh
new file mode 100755 (executable)
index 0000000..c301a89
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+function getHeadRev {
+  git rev-parse HEAD
+}
+
+target_commit="$(getHeadRev)"
+running_commit=$(clever status | grep running | sed 's/^.*Commit: //' | sed 's/)$//')
+
+if [ "${running_commit}" != "${target_commit}" ]; then
+  echo "Deploying commit ${target_commit}"
+  clever deploy --force
+else
+  echo "${target_commit} is already deployed, nothing to do"
+fi
index f9d84088d6d8bedc50945e34394b84f8ee7a6a1e..ae119218a77e034cec3d813f0e72263cdfb7b4ce 100644 (file)
@@ -47,7 +47,7 @@
   changed_when: false
 
 - name: Deploy to Clever-Cloud
-  shell: "clever deploy --force"
+  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-deploy.sh"
   args:
     chdir: "{{ clever_app_root }}"
   environment:
index 8a11772639258333bfac385f1feda783e9371ae0..89bc5185945d7fc8dbfab70b849d6c7dc0a1ae16 100644 (file)
@@ -27,6 +27,7 @@
     dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}/{{ item }}"
     mode: 0755
   with_items:
+    - clever-deploy.sh
     - clever-set-domain.sh
     - clever-set-drain.sh
     - clever-set-scalability.sh