]> git.immae.eu Git - github/fretlink/ansible-clever.git/commitdiff
Add support for linking service dependencies
authorClement Delafargue <clement.delafargue@fretlink.com>
Wed, 1 Jul 2020 09:48:04 +0000 (11:48 +0200)
committerClement Delafargue <clement.delafargue@fretlink.com>
Thu, 2 Jul 2020 09:44:09 +0000 (11:44 +0200)
README.md
defaults/main.yml
tasks/deploy.yml
tasks/service-dep.yml [new file with mode: 0644]
tests/test-all.yml
tests/test-service-deps.yml [new file with mode: 0644]

index 51b9e3d49e180cdefee74472bcc8a6747d481a16..eaddbd524db93461042fb7494f7f4d51bdbecdf3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -34,6 +34,8 @@ Variables for the application:
 - `clever_env_output_file`: as a post deploy task you might need to retrieve the full Clever environment configuration (i.e. with addon env variables). If this variable is set to a filename then the env will be retrieved after a successful deploy and written to this file. Beware, the resulting file will contain sensitive information (addon passwords, …). Optional.
 - `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.
 - `clever_scaling`: an optional object used to configure the runtime instances flavours and numbers. If not defined, it delegates to clever cloud default behaviour.
+- `clever_service_dependencies`: a list of the service dependencies needed by the application (each service being a dict containing either an `app_id` field, or an `addon_id` field), optional.<br/>
+  Example: `[{ addon_id: addon_00000000-0000-0000-0000-000000000000 }, { app_id: app_00000000-0000-0000-0000-000000000000 }]`
 
 Variables specific to deployment, defaults should be fine:
 
index 4e2ef8e023159098cab3638d1ac310a29b6668b0..68e3abedb03751c65b764839cf5b4e1b89e54f14 100644 (file)
@@ -16,3 +16,9 @@ clever_addons: []
 # clever_addons:
 #   - name: pg
 #   - env_prefix: POSTGRESQL_ADDON
+
+clever_service_dependencies: []
+# example
+# clever_service_dependencies:
+#   - addon_id: addon_00000000-0000-0000-0000-000000000000
+#   - app_id: app_00000000-0000-0000-0000-000000000000
index ae119218a77e034cec3d813f0e72263cdfb7b4ce..8dda5e0f7dc82673e91a1da91525a32708692e98 100644 (file)
     MIN_FLAVOR: "{{ clever_scaling.flavor.min | default('') }}"
     MAX_FLAVOR: "{{ clever_scaling.flavor.max | default('') }}"
 
+- name: Configure service dependencies
+  include_tasks: service-dep.yml
+  vars:
+    service_dep: "{{ item }}"
+  with_items: "{{ clever_service_dependencies }}"
+
 - name: Push Environment
   shell: "clever env import --json < {{ clever_app_confdir }}/env"
   args:
diff --git a/tasks/service-dep.yml b/tasks/service-dep.yml
new file mode 100644 (file)
index 0000000..67621f6
--- /dev/null
@@ -0,0 +1,17 @@
+- name: Make sure addon {{ service_dep.addon_id }} is linked
+  shell: >
+    clever service link-addon {{ service_dep.addon_id }}
+  args:
+    chdir: "{{ clever_app_root }}"
+  environment:
+    CONFIGURATION_FILE: "{{ clever_login_file }}"
+  when: service_dep.addon_id is defined
+
+- name: Make sure app {{ service_dep.app_id }} is linked
+  shell: >
+    clever service link-app {{ service_dep.app_id }}
+  args:
+    chdir: "{{ clever_app_root }}"
+  environment:
+    CONFIGURATION_FILE: "{{ clever_login_file }}"
+  when: service_dep.app_id is defined
index 145b16d2b1f867d6aa0453dc012779b94ff95f11..8a6c0ba362552ea5f8bbad5695ff56cca47824db 100644 (file)
@@ -4,4 +4,5 @@
 - import_playbook: ./test-haskell-app.yml
 - import_playbook: ./test-noop-deploy.yml
 - import_playbook: ./test-scalability.yml
+- import_playbook: ./test-service-deps.yml
 - import_playbook: ./test-restart-app.yml
diff --git a/tests/test-service-deps.yml b/tests/test-service-deps.yml
new file mode 100644 (file)
index 0000000..4e848e5
--- /dev/null
@@ -0,0 +1,36 @@
+---
+- name: Deploy an app & configure service dependencies 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
+        clever_service_dependencies:
+          - app_id: app_00000000-2222-2222-2222-000000000000
+          - addon_id: addon_00000000-0000-0000-0000-000000000000
+  post_tasks:
+    - name: Check stubbed commands
+      shell: "{{ item.cmd }}"
+      ignore_errors: true
+      vars:
+        display: "{{ item.display }}"
+      with_list:
+        - cmd: "grep service ../clever-commands"
+          display: "Expected 'clever service' command to be called"
+      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 }}"