aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorpaulrbr-fl <43074087+paulrbr-fl@users.noreply.github.com>2020-06-23 11:20:46 +0200
committerGitHub <noreply@github.com>2020-06-23 11:20:46 +0200
commitca1a71c946fa7c51e0059b8d4342b24507aa8c64 (patch)
treed3a0759aee49d8aa595417a88e20978f6f6586c3
parent44af02cef61e043b971f03aa5cec5a4caa6d6875 (diff)
parent4525f9489fe792b0d7ee4ca76dc0c3706784d256 (diff)
downloadansible-clever-ca1a71c946fa7c51e0059b8d4342b24507aa8c64.tar.gz
ansible-clever-ca1a71c946fa7c51e0059b8d4342b24507aa8c64.tar.zst
ansible-clever-ca1a71c946fa7c51e0059b8d4342b24507aa8c64.zip
Merge pull request #70 from paulrbr-fl/clever-restart
feature: add a new 'clever_restart_only' flag to restart an app
-rw-r--r--.travis.yml5
-rw-r--r--README.md3
-rw-r--r--tasks/main.yml9
-rw-r--r--tasks/restart.yml22
-rwxr-xr-xtests/fake.sh1
-rw-r--r--tests/test-all.yml6
-rw-r--r--tests/test-configure-app.yml30
-rw-r--r--tests/test-restart-app.yml38
-rw-r--r--tests/test-scalability.yml27
9 files changed, 136 insertions, 5 deletions
diff --git a/.travis.yml b/.travis.yml
index 92f6295..7ce4540 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,10 +26,7 @@ script:
26 - mkdir -p ~/.local/bin 26 - mkdir -p ~/.local/bin
27 - cp tests/fake.sh ~/.local/bin/clever 27 - cp tests/fake.sh ~/.local/bin/clever
28 - cp tests/fake.sh ~/.local/bin/git 28 - cp tests/fake.sh ~/.local/bin/git
29 - ansible-playbook tests/test-simple-app.yml -i tests/inventory 29 - ansible-playbook -i tests/inventory tests/test-all.yml
30 - ansible-playbook tests/test-haskell-app.yml -i tests/inventory
31 - ansible-playbook tests/test-configure-app.yml -i tests/inventory
32 - ansible-playbook tests/test-scalability.yml -i tests/inventory
33 30
34notifications: 31notifications:
35 slack: fretlink:pTIylIN7zkwRFuL3aHERmsbB 32 slack: fretlink:pTIylIN7zkwRFuL3aHERmsbB
diff --git a/README.md b/README.md
index 22c70b4..51b9e3d 100644
--- a/README.md
+++ b/README.md
@@ -35,13 +35,14 @@ Variables for the application:
35- `clever_build_flavor`: an optional text value used to configure the size of the dedicated build instance (for instance `S` or `XL`). If not defined, it delegates to clever cloud default behaviour. Setting `disabled` disables the dedicated build instance altogether. 35- `clever_build_flavor`: an optional text value used to configure the size of the dedicated build instance (for instance `S` or `XL`). If not defined, it delegates to clever cloud default behaviour. Setting `disabled` disables the dedicated build instance altogether.
36- `clever_scaling`: an optional object used to configure the runtime instances flavours and numbers. If not defined, it delegates to clever cloud default behaviour. 36- `clever_scaling`: an optional object used to configure the runtime instances flavours and numbers. If not defined, it delegates to clever cloud default behaviour.
37 37
38Variables specific to deployment, default should be fine: 38Variables specific to deployment, defaults should be fine:
39 39
40- `clever_cli_version`: Version of clever cli tools, default to `2.6.1`. 40- `clever_cli_version`: Version of clever cli tools, default to `2.6.1`.
41- `clever_user_path`: Path relative to ansible_user home dir where cli tools and helpers are installed default to `.local/bin`. 41- `clever_user_path`: Path relative to ansible_user home dir where cli tools and helpers are installed default to `.local/bin`.
42- `clever_app_root`: Path of the application to deploy, default to `app_root` if defined or `"{{ playbook_dir }}/.."` otherwise. I.e. the default behavior will work fine if you define a playbook using this role in a one level deep directory (e.g. `deployment/`) of the root of the application. 42- `clever_app_root`: Path of the application to deploy, default to `app_root` if defined or `"{{ playbook_dir }}/.."` otherwise. I.e. the default behavior will work fine if you define a playbook using this role in a one level deep directory (e.g. `deployment/`) of the root of the application.
43- `clever_app_confdir`: Path where to store clever cloud data specific to this application, default to `"{{ clever_app_root }}/.clever_cloud"` 43- `clever_app_confdir`: Path where to store clever cloud data specific to this application, default to `"{{ clever_app_root }}/.clever_cloud"`
44- `clever_login_file`: Path to store login information. Default to `"{{ clever_app_confdir }}/login"`. 44- `clever_login_file`: Path to store login information. Default to `"{{ clever_app_confdir }}/login"`.
45- `clever_restart_only`: set to `true` to skip any deployment related tasks (domain, scaling, env, deploy, …) and only restart the application. Optional.
45 46
46Variables specific to Haskell applications: 47Variables specific to Haskell applications:
47 48
diff --git a/tasks/main.yml b/tasks/main.yml
index 3c59c90..002dc9c 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -24,13 +24,22 @@
24 24
25- name: Deploy app 25- name: Deploy app
26 import_tasks: deploy.yml 26 import_tasks: deploy.yml
27 when: not clever_restart_only is defined or not clever_restart_only
27 tags: 28 tags:
28 - clever 29 - clever
29 - clever-deploy 30 - clever-deploy
30 31
31- name: Post deploy tasks 32- name: Post deploy tasks
32 import_tasks: post_deploy.yml 33 import_tasks: post_deploy.yml
34 when: not clever_restart_only is defined or not clever_restart_only
33 tags: 35 tags:
34 - clever 36 - clever
35 - clever-deploy 37 - clever-deploy
36 - clever-env 38 - clever-env
39
40- name: Restart app
41 import_tasks: restart.yml
42 when: clever_restart_only is defined and clever_restart_only
43 tags:
44 - clever
45 - clever-restart
diff --git a/tasks/restart.yml b/tasks/restart.yml
new file mode 100644
index 0000000..e2a8891
--- /dev/null
+++ b/tasks/restart.yml
@@ -0,0 +1,22 @@
1---
2- name: Restart app on Clever-Cloud
3 shell: "clever restart"
4 args:
5 chdir: "{{ clever_app_root }}"
6 environment:
7 CONFIGURATION_FILE: "{{ clever_login_file }}"
8 async: 300 # 5 minutes
9 poll: 0
10 ignore_errors: true
11 register: clever_deploy
12 tags:
13 - skip_ansible_lint
14
15- name: Wait up to 5 minutes for restart completion
16 async_status:
17 jid: "{{ clever_deploy.ansible_job_id }}"
18 register: job_result
19 until: job_result.finished
20 ignore_errors: true
21 delay: 30
22 retries: 10 # 5 minutes (10 * 30 secs delay)
diff --git a/tests/fake.sh b/tests/fake.sh
index 75bc051..bbb4380 100755
--- a/tests/fake.sh
+++ b/tests/fake.sh
@@ -10,5 +10,6 @@ elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then
10elif [ "${binary}" = "git" ]; then 10elif [ "${binary}" = "git" ]; then
11 echo "${fakeCommit}" 11 echo "${fakeCommit}"
12else 12else
13 echo "${1}" >> "${binary}-commands"
13 echo "${binary} called with arguments: ${*}" 14 echo "${binary} called with arguments: ${*}"
14fi 15fi
diff --git a/tests/test-all.yml b/tests/test-all.yml
new file mode 100644
index 0000000..64eb239
--- /dev/null
+++ b/tests/test-all.yml
@@ -0,0 +1,6 @@
1---
2- import_playbook: ./test-simple-app.yml
3- import_playbook: ./test-configure-app.yml
4- import_playbook: ./test-haskell-app.yml
5- import_playbook: ./test-scalability.yml
6- import_playbook: ./test-restart-app.yml
diff --git a/tests/test-configure-app.yml b/tests/test-configure-app.yml
index 06e5e92..15987fd 100644
--- a/tests/test-configure-app.yml
+++ b/tests/test-configure-app.yml
@@ -2,6 +2,10 @@
2- name: Deploy an app & configure system details on clever 2- name: Deploy an app & configure system details on clever
3 hosts: localhost 3 hosts: localhost
4 remote_user: root 4 remote_user: root
5 pre_tasks:
6 - file:
7 state: absent
8 path: ../clever-commands
5 roles: 9 roles:
6 - role: clever 10 - role: clever
7 vars: 11 vars:
@@ -16,3 +20,29 @@
16 fail: 20 fail:
17 msg: "CC_RUN_COMMAND env variable should not be present in the environment dict" 21 msg: "CC_RUN_COMMAND env variable should not be present in the environment dict"
18 when: clever_env.CC_RUN_COMMAND is defined 22 when: clever_env.CC_RUN_COMMAND is defined
23 - name: Check stubbed commands
24 command: "{{ item.cmd }}"
25 ignore_errors: true
26 vars:
27 display: "{{ item.display }}"
28 with_list:
29 - cmd: "grep deploy ../clever-commands"
30 display: "Expected 'clever deploy' command to be called"
31 - cmd: "grep scale ../clever-commands"
32 display: "Expected 'clever scale' command to be called"
33 - cmd: "grep domain ../clever-commands"
34 display: "Expected 'clever domain' command to be called"
35 - cmd: "grep drain ../clever-commands"
36 display: "Expected 'clever drain' command to be called"
37 - cmd: "grep -v restart ../clever-commands"
38 display: "Expected 'clever restart' command to NOT be called"
39 register: tests_results
40 - name: show results
41 debug:
42 msg:
43 - "failed_results: {{ failed_results }}"
44 - "success_results: {{ success_results }}"
45 failed_when: tests_results is failed
46 vars:
47 failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
48 success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"
diff --git a/tests/test-restart-app.yml b/tests/test-restart-app.yml
new file mode 100644
index 0000000..4c13a14
--- /dev/null
+++ b/tests/test-restart-app.yml
@@ -0,0 +1,38 @@
1---
2- name: Restart app 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 clever_restart_only: true
16 post_tasks:
17 - name: Check stubbed commands
18 command: "{{ item.cmd }}"
19 ignore_errors: true
20 vars:
21 display: "{{ item.display }}"
22 with_list:
23 - cmd: "grep restart ../clever-commands"
24 display: "Expected 'clever restart' command to be called"
25 - cmd: "grep -v deploy ../clever-commands"
26 display: "Expected 'clever deploy' command to NOT be called"
27 - cmd: "grep -v scale ../clever-commands"
28 display: "Expected 'clever scale' command to NOT be called"
29 register: tests_results
30 - name: show results
31 debug:
32 msg:
33 - "failed_results: {{ failed_results }}"
34 - "success_results: {{ success_results }}"
35 failed_when: tests_results is failed
36 vars:
37 failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
38 success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"
diff --git a/tests/test-scalability.yml b/tests/test-scalability.yml
index fefc86c..6bb90d2 100644
--- a/tests/test-scalability.yml
+++ b/tests/test-scalability.yml
@@ -15,6 +15,10 @@
15- name: Configure scalability (no instances and ranged flavors) 15- name: Configure scalability (no instances and ranged flavors)
16 hosts: localhost 16 hosts: localhost
17 remote_user: root 17 remote_user: root
18 pre_tasks:
19 - file:
20 state: absent
21 path: ../clever-commands
18 roles: 22 roles:
19 - role: clever 23 - role: clever
20 vars: 24 vars:
@@ -23,6 +27,29 @@
23 clever_app: app_00000000-0000-0000-0000-000000000000 27 clever_app: app_00000000-0000-0000-0000-000000000000
24 clever_scaling: 28 clever_scaling:
25 flavors: { min: "nano", max: "XS" } 29 flavors: { min: "nano", max: "XS" }
30 post_tasks:
31 - name: Check stubbed commands
32 command: "{{ item.cmd }}"
33 ignore_errors: true
34 vars:
35 display: "{{ item.display }}"
36 with_list:
37 - cmd: "grep deploy ../clever-commands"
38 display: "Expected 'clever deploy' command to be called"
39 - cmd: "grep scale ../clever-commands"
40 display: "Expected 'clever scale' command to be called"
41 - cmd: "grep -v restart ../clever-commands"
42 display: "Expected 'clever restart' command to NOT be called"
43 register: tests_results
44 - name: show results
45 debug:
46 msg:
47 - "failed_results: {{ failed_results }}"
48 - "success_results: {{ success_results }}"
49 failed_when: tests_results is failed
50 vars:
51 failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
52 success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"
26 53
27- name: Configure scalability (incomplete flavors) 54- name: Configure scalability (incomplete flavors)
28 hosts: localhost 55 hosts: localhost