--- /dev/null
+#!/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
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:
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
#!/usr/bin/env bash
binary="${0/*\/}"
-fakeCommit="aaa000aaa000aaa000aaa000aaa000aaa000aaa0"
+localCommit="${PRETEND_LOCAL_COMMIT:-aaa000aaa000aaa000aaa000aaa000aaa000aaa0}"
+remoteCommit="${PRETEND_REMOTE_COMMIT:-bbb000bbb000bbb000bbb000bbb000bbb000bbb0}"
if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then
echo "2.6.1"
elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then
- echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${fakeCommit} Git"
+ echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${remoteCommit} Git"
+elif [ "${binary}" = "clever" ] && [ "${1}" = "status" ]; then
+ echo "test-app: running (1*pico, Commit: ${remoteCommit})"
elif [ "${binary}" = "git" ]; then
- echo "${fakeCommit}"
+ echo "${localCommit}"
else
- echo "${1}" >> "${binary}-commands"
echo "${binary} called with arguments: ${*}"
fi
+
+echo "${1}" >> "${binary}-commands"
- import_playbook: ./test-simple-app.yml
- import_playbook: ./test-configure-app.yml
- import_playbook: ./test-haskell-app.yml
+- import_playbook: ./test-noop-deploy.yml
- import_playbook: ./test-scalability.yml
- import_playbook: ./test-restart-app.yml
msg: "CC_RUN_COMMAND env variable should not be present in the environment dict"
when: clever_env.CC_RUN_COMMAND is defined
- name: Check stubbed commands
- command: "{{ item.cmd }}"
+ shell: "{{ item.cmd }}"
ignore_errors: true
vars:
display: "{{ item.display }}"
display: "Expected 'clever domain' command to be called"
- cmd: "grep drain ../clever-commands"
display: "Expected 'clever drain' command to be called"
- - cmd: "grep -v restart ../clever-commands"
+ - cmd: "! grep restart ../clever-commands"
display: "Expected 'clever restart' command to NOT be called"
register: tests_results
- name: show results
--- /dev/null
+---
+- name: Do nothing if the app is up-to-date on clever
+ hosts: localhost
+ remote_user: root
+ pre_tasks:
+ - file:
+ state: absent
+ path: ../clever-commands
+ roles:
+ - role: clever
+ vars:
+ clever_token: 123abc
+ clever_secret: cba321
+ clever_app: app_00000000-0000-0000-0000-000000000000
+ environment:
+ PRETEND_REMOTE_COMMIT: aaa000aaa000aaa000aaa000aaa000aaa000aaa0
+ post_tasks:
+ - name: Check stubbed commands
+ shell: "{{ item.cmd }}"
+ ignore_errors: true
+ with_list:
+ - cmd: "! grep deploy ../clever-commands"
+ display: "Expected 'clever deploy' command to NOT be called"
+ vars:
+ display: "{{ item.display }}"
+ register: tests_results
+ - name: show results
+ debug:
+ msg:
+ - "failed_results: {{ failed_results }}"
+ - "success_results: {{ success_results }}"
+ failed_when: tests_results is failed
+ vars:
+ failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
+ success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"
clever_restart_only: true
post_tasks:
- name: Check stubbed commands
- command: "{{ item.cmd }}"
+ shell: "{{ item.cmd }}"
ignore_errors: true
vars:
display: "{{ item.display }}"
with_list:
- cmd: "grep restart ../clever-commands"
display: "Expected 'clever restart' command to be called"
- - cmd: "grep -v deploy ../clever-commands"
+ - cmd: "! grep deploy ../clever-commands"
display: "Expected 'clever deploy' command to NOT be called"
- - cmd: "grep -v scale ../clever-commands"
+ - cmd: "! grep scale ../clever-commands"
display: "Expected 'clever scale' command to NOT be called"
register: tests_results
- name: show results
flavors: { min: "nano", max: "XS" }
post_tasks:
- name: Check stubbed commands
- command: "{{ item.cmd }}"
+ shell: "{{ item.cmd }}"
ignore_errors: true
vars:
display: "{{ item.display }}"
display: "Expected 'clever deploy' command to be called"
- cmd: "grep scale ../clever-commands"
display: "Expected 'clever scale' command to be called"
- - cmd: "grep -v restart ../clever-commands"
+ - cmd: "! grep restart ../clever-commands"
display: "Expected 'clever restart' command to NOT be called"
register: tests_results
- name: show results