From facc275a703d3bccc320e5577eb3d050f99dff0e Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Wed, 24 Jun 2020 11:34:28 +0200 Subject: Don't run `clever deploy` if the app is up-to-date 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 | 15 +++++++++++++++ tasks/deploy.yml | 2 +- tasks/setup.yml | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 files/clever-deploy.sh diff --git a/files/clever-deploy.sh b/files/clever-deploy.sh new file mode 100755 index 0000000..c301a89 --- /dev/null +++ b/files/clever-deploy.sh @@ -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 diff --git a/tasks/deploy.yml b/tasks/deploy.yml index f9d8408..ae11921 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml @@ -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: diff --git a/tasks/setup.yml b/tasks/setup.yml index 8a11772..89bc518 100644 --- a/tasks/setup.yml +++ b/tasks/setup.yml @@ -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 -- cgit v1.2.3