aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorpaulrbr-fl <43074087+paulrbr-fl@users.noreply.github.com>2020-08-06 16:01:39 +0200
committerGitHub <noreply@github.com>2020-08-06 16:01:39 +0200
commit9a29ce38c3a73e448a1a636888899a9a31229573 (patch)
treef03e1db57031f574657838a8a15c41319b1c18be
parent315c7f51af48b54719bd793d9d28a4bb396a926a (diff)
parentc3e2ff5e0f31c61eae330a1a41d7a8a83435d9bd (diff)
downloadansible-clever-9a29ce38c3a73e448a1a636888899a9a31229573.tar.gz
ansible-clever-9a29ce38c3a73e448a1a636888899a9a31229573.tar.zst
ansible-clever-9a29ce38c3a73e448a1a636888899a9a31229573.zip
Merge pull request #75 from paulrbr-fl/clever-restart-when-askedv2.8
deploy: try to restart the app when the CLI asks to do it
-rw-r--r--tasks/deploy.yml7
-rw-r--r--tasks/restart.yml9
-rwxr-xr-xtests/fake.sh14
-rw-r--r--tests/test-all.yml1
-rw-r--r--tests/test-restart-deploy.yml37
5 files changed, 65 insertions, 3 deletions
diff --git a/tasks/deploy.yml b/tasks/deploy.yml
index 8dda5e0..39b5845 100644
--- a/tasks/deploy.yml
+++ b/tasks/deploy.yml
@@ -85,6 +85,13 @@
85 - job_result.stderr is defined 85 - job_result.stderr is defined
86 - job_result.stderr is search("Failed to read git object") 86 - job_result.stderr is search("Failed to read git object")
87 87
88- name: Restart app on clever-cloud when error asks to restart
89 include_tasks: restart.yml
90 when:
91 - not job_result.finished or not job_result.rc == 0
92 - job_result.stderr is defined
93 - job_result.stderr is search("clever restart")
94
88- name: Deploy logs (stdout) 95- name: Deploy logs (stdout)
89 debug: 96 debug:
90 var: job_result.stdout_lines 97 var: job_result.stdout_lines
diff --git a/tasks/restart.yml b/tasks/restart.yml
index e2a8891..1c52032 100644
--- a/tasks/restart.yml
+++ b/tasks/restart.yml
@@ -1,6 +1,13 @@
1--- 1---
2- name: Get current HEAD commit revision
3 command: "git rev-parse HEAD" # noqa 303
4 register: git_head_revision
5 args:
6 chdir: "{{ clever_app_root }}"
7 changed_when: false
8
2- name: Restart app on Clever-Cloud 9- name: Restart app on Clever-Cloud
3 shell: "clever restart" 10 shell: "clever restart --commit {{ git_head_revision.stdout_lines | first }}"
4 args: 11 args:
5 chdir: "{{ clever_app_root }}" 12 chdir: "{{ clever_app_root }}"
6 environment: 13 environment:
diff --git a/tests/fake.sh b/tests/fake.sh
index 65ff819..776907b 100755
--- a/tests/fake.sh
+++ b/tests/fake.sh
@@ -3,6 +3,9 @@
3binary="${0/*\/}" 3binary="${0/*\/}"
4localCommit="${PRETEND_LOCAL_COMMIT:-aaa000aaa000aaa000aaa000aaa000aaa000aaa0}" 4localCommit="${PRETEND_LOCAL_COMMIT:-aaa000aaa000aaa000aaa000aaa000aaa000aaa0}"
5remoteCommit="${PRETEND_REMOTE_COMMIT:-bbb000bbb000bbb000bbb000bbb000bbb000bbb0}" 5remoteCommit="${PRETEND_REMOTE_COMMIT:-bbb000bbb000bbb000bbb000bbb000bbb000bbb0}"
6uptodateDeployment="${DEPLOY_UP_TO_DATE_APP:-}"
7
8echo "${1}" >> "${binary}-commands"
6 9
7if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then 10if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then
8 echo "2.6.1" 11 echo "2.6.1"
@@ -10,10 +13,17 @@ elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then
10 echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${remoteCommit} Git" 13 echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${remoteCommit} Git"
11elif [ "${binary}" = "clever" ] && [ "${1}" = "status" ]; then 14elif [ "${binary}" = "clever" ] && [ "${1}" = "status" ]; then
12 echo "test-app: running (1*pico, Commit: ${remoteCommit})" 15 echo "test-app: running (1*pico, Commit: ${remoteCommit})"
16elif [ "${binary}" = "clever" ] && [ "${1}" = "deploy" ]; then
17 if [ -z "${uptodateDeployment}" ]; then
18 echo "Clever deploy done."
19 else
20 # Mimic the current behavior until https://github.com/CleverCloud/clever-tools/issues/422 is solved
21 >&2 echo "The clever-cloud application is up-to-date. Try this command to restart the application:"
22 >&2 echo " clever restart"
23 exit 1
24 fi
13elif [ "${binary}" = "git" ]; then 25elif [ "${binary}" = "git" ]; then
14 echo "${localCommit}" 26 echo "${localCommit}"
15else 27else
16 echo "${binary} called with arguments: ${*}" 28 echo "${binary} called with arguments: ${*}"
17fi 29fi
18
19echo "${1}" >> "${binary}-commands"
diff --git a/tests/test-all.yml b/tests/test-all.yml
index 8a6c0ba..b9c5dea 100644
--- a/tests/test-all.yml
+++ b/tests/test-all.yml
@@ -3,6 +3,7 @@
3- import_playbook: ./test-configure-app.yml 3- import_playbook: ./test-configure-app.yml
4- import_playbook: ./test-haskell-app.yml 4- import_playbook: ./test-haskell-app.yml
5- import_playbook: ./test-noop-deploy.yml 5- import_playbook: ./test-noop-deploy.yml
6- import_playbook: ./test-restart-deploy.yml
6- import_playbook: ./test-scalability.yml 7- import_playbook: ./test-scalability.yml
7- import_playbook: ./test-service-deps.yml 8- import_playbook: ./test-service-deps.yml
8- import_playbook: ./test-restart-app.yml 9- import_playbook: ./test-restart-app.yml
diff --git a/tests/test-restart-deploy.yml b/tests/test-restart-deploy.yml
new file mode 100644
index 0000000..cbd6cdd
--- /dev/null
+++ b/tests/test-restart-deploy.yml
@@ -0,0 +1,37 @@
1---
2- name: Launch a restart when commit is already up-to-date on clever
3 hosts: localhost
4 remote_user: root
5 pre_tasks:
6 - file:
7 state: absent
8 path: ../clever-commands
9 roles:
10 - role: clever
11 vars:
12 clever_token: 123abc
13 clever_secret: cba321
14 clever_app: app_00000000-0000-0000-0000-000000000000
15 environment:
16 DEPLOY_UP_TO_DATE_APP: true
17 post_tasks:
18 - name: Check stubbed commands
19 shell: "{{ item.cmd }}"
20 ignore_errors: true
21 with_list:
22 - cmd: "grep deploy ../clever-commands"
23 display: "Expected 'clever deploy' command to be called"
24 - cmd: "grep restart ../clever-commands"
25 display: "Expected 'clever restart' command to be called"
26 vars:
27 display: "{{ item.display }}"
28 register: tests_results
29 - name: show results
30 debug:
31 msg:
32 - "failed_results: {{ failed_results }}"
33 - "success_results: {{ success_results }}"
34 failed_when: tests_results is failed
35 vars:
36 failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
37 success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"