aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorClément Delafargue <39330590+clementd-fretlink@users.noreply.github.com>2020-07-03 15:16:54 +0200
committerGitHub <noreply@github.com>2020-07-03 15:16:54 +0200
commit315c7f51af48b54719bd793d9d28a4bb396a926a (patch)
treea9e2e081805d89fa1b924d6b2f85be342fd0cc54
parent90634ee04cc1a4ab983de6bf142f25978463bc4a (diff)
parent3d3287e0767d13b0a81e5936ce9376d58f42e34c (diff)
downloadansible-clever-315c7f51af48b54719bd793d9d28a4bb396a926a.tar.gz
ansible-clever-315c7f51af48b54719bd793d9d28a4bb396a926a.tar.zst
ansible-clever-315c7f51af48b54719bd793d9d28a4bb396a926a.zip
Merge pull request #74 from clementd-fretlink/service-dependenciesv2.7
Service dependencies
-rw-r--r--README.md2
-rw-r--r--defaults/main.yml8
-rw-r--r--dhall/Config.dhall4
-rw-r--r--dhall/ServiceDependency.dhall9
-rw-r--r--dhall/package.dhall6
-rw-r--r--tasks/addon.yml17
-rw-r--r--tasks/deploy.yml6
-rw-r--r--tasks/service-dep.yml17
-rw-r--r--tests/test-all.yml1
-rw-r--r--tests/test-service-deps.yml36
10 files changed, 88 insertions, 18 deletions
diff --git a/README.md b/README.md
index 51b9e3d..eaddbd5 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,8 @@ Variables for the application:
34- `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. 34- `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.
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- `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/>
38 Example: `[{ addon_id: addon_00000000-0000-0000-0000-000000000000 }, { app_id: app_00000000-0000-0000-0000-000000000000 }]`
37 39
38Variables specific to deployment, defaults should be fine: 40Variables specific to deployment, defaults should be fine:
39 41
diff --git a/defaults/main.yml b/defaults/main.yml
index 4e2ef8e..f117f15 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -15,4 +15,10 @@ clever_addons: []
15# example 15# example
16# clever_addons: 16# clever_addons:
17# - name: pg 17# - name: pg
18# - env_prefix: POSTGRESQL_ADDON 18# env_prefix: POSTGRESQL_ADDON
19
20clever_service_dependencies: []
21# example
22# clever_service_dependencies:
23# - addon_id: addon_00000000-0000-0000-0000-000000000000
24# - app_id: app_00000000-0000-0000-0000-000000000000
diff --git a/dhall/Config.dhall b/dhall/Config.dhall
index 9e46679..1e0f4ae 100644
--- a/dhall/Config.dhall
+++ b/dhall/Config.dhall
@@ -1,5 +1,7 @@
1let Addon = (./Addon.dhall).Type 1let Addon = (./Addon.dhall).Type
2 2
3let ServiceDependency = (./ServiceDependency.dhall).Type
4
3let Vault = ./Vault.dhall 5let Vault = ./Vault.dhall
4 6
5let FixedOrRange = 7let FixedOrRange =
@@ -28,6 +30,7 @@ let Config =
28 , clever_haskell_entry_point : Optional Text 30 , clever_haskell_entry_point : Optional Text
29 , clever_disable_metrics : Bool 31 , clever_disable_metrics : Bool
30 , clever_addons : List Addon 32 , clever_addons : List Addon
33 , clever_service_dependencies : List ServiceDependency
31 , clever_env : Environment 34 , clever_env : Environment
32 , clever_build_flavor : Optional Text 35 , clever_build_flavor : Optional Text
33 , clever_scaling : Optional ScalingParameters 36 , clever_scaling : Optional ScalingParameters
@@ -48,6 +51,7 @@ let mkConfig =
48 , clever_haskell_entry_point = None Text 51 , clever_haskell_entry_point = None Text
49 , clever_disable_metrics = False 52 , clever_disable_metrics = False
50 , clever_addons = [] : List Addon 53 , clever_addons = [] : List Addon
54 , clever_service_dependencies = [] : List ServiceDependency
51 , clever_env = {=} 55 , clever_env = {=}
52 , clever_build_flavor = None Text 56 , clever_build_flavor = None Text
53 , clever_scaling = None ScalingParameters 57 , clever_scaling = None ScalingParameters
diff --git a/dhall/ServiceDependency.dhall b/dhall/ServiceDependency.dhall
new file mode 100644
index 0000000..9cad9b4
--- /dev/null
+++ b/dhall/ServiceDependency.dhall
@@ -0,0 +1,9 @@
1let ServiceDependency =
2 < Addon : { addon_id : Text } | Application : { app_id : Text } >
3
4let addon = λ(addon_id : Text) → ServiceDependency.Addon { addon_id = addon_id }
5
6let application =
7 λ(app_id : Text) → ServiceDependency.Application { app_id = app_id }
8
9in { Type = ServiceDependency, addon = addon, application = application }
diff --git a/dhall/package.dhall b/dhall/package.dhall
index c653ddb..c430b44 100644
--- a/dhall/package.dhall
+++ b/dhall/package.dhall
@@ -1 +1,5 @@
1{ Addon = ./Addon.dhall, Config = ./Config.dhall, Vault = ./Vault.dhall } 1{ Addon = ./Addon.dhall
2, ServiceDependency = ./ServiceDependency.dhall
3, Config = ./Config.dhall
4, Vault = ./Vault.dhall
5}
diff --git a/tasks/addon.yml b/tasks/addon.yml
index 328664d..1ee8eff 100644
--- a/tasks/addon.yml
+++ b/tasks/addon.yml
@@ -1,18 +1,4 @@
1- name: Gather addon information for {{ addon.name }} (clever --version < 1.5.0) 1- name: Gather addon information for {{ addon.name }}
2 shell: >
3 set -o pipefail &&
4 clever env | grep {{ addon.env_prefix }}
5 | sed -e 's/{{ addon.env_prefix }}_//' -e 's/=/: \"/' -e 's/$/\"/'
6 > {{ clever_app_confdir }}/{{ addon.name }}_env.yml
7 args:
8 chdir: "{{ clever_app_root }}"
9 executable: "bash"
10 environment:
11 CONFIGURATION_FILE: "{{ clever_login_file }}"
12 changed_when: False
13 when: clever_returned_version.stdout is version('1.5.0', '<')
14
15- name: Gather addon information for {{ addon.name }} (clever --version >= 1.5.0)
16 shell: > 2 shell: >
17 set -o pipefail && 3 set -o pipefail &&
18 clever env | grep {{ addon.env_prefix }} 4 clever env | grep {{ addon.env_prefix }}
@@ -24,7 +10,6 @@
24 environment: 10 environment:
25 CONFIGURATION_FILE: "{{ clever_login_file }}" 11 CONFIGURATION_FILE: "{{ clever_login_file }}"
26 changed_when: False 12 changed_when: False
27 when: clever_returned_version.stdout is version('1.5.0', '>=')
28 13
29- name: Include addon var for {{ addon.name }} 14- name: Include addon var for {{ addon.name }}
30 include_vars: 15 include_vars:
diff --git a/tasks/deploy.yml b/tasks/deploy.yml
index ae11921..8dda5e0 100644
--- a/tasks/deploy.yml
+++ b/tasks/deploy.yml
@@ -38,6 +38,12 @@
38 MIN_FLAVOR: "{{ clever_scaling.flavor.min | default('') }}" 38 MIN_FLAVOR: "{{ clever_scaling.flavor.min | default('') }}"
39 MAX_FLAVOR: "{{ clever_scaling.flavor.max | default('') }}" 39 MAX_FLAVOR: "{{ clever_scaling.flavor.max | default('') }}"
40 40
41- name: Configure service dependencies
42 include_tasks: service-dep.yml
43 vars:
44 service_dep: "{{ item }}"
45 with_items: "{{ clever_service_dependencies }}"
46
41- name: Push Environment 47- name: Push Environment
42 shell: "clever env import --json < {{ clever_app_confdir }}/env" 48 shell: "clever env import --json < {{ clever_app_confdir }}/env"
43 args: 49 args:
diff --git a/tasks/service-dep.yml b/tasks/service-dep.yml
new file mode 100644
index 0000000..67621f6
--- /dev/null
+++ b/tasks/service-dep.yml
@@ -0,0 +1,17 @@
1- name: Make sure addon {{ service_dep.addon_id }} is linked
2 shell: >
3 clever service link-addon {{ service_dep.addon_id }}
4 args:
5 chdir: "{{ clever_app_root }}"
6 environment:
7 CONFIGURATION_FILE: "{{ clever_login_file }}"
8 when: service_dep.addon_id is defined
9
10- name: Make sure app {{ service_dep.app_id }} is linked
11 shell: >
12 clever service link-app {{ service_dep.app_id }}
13 args:
14 chdir: "{{ clever_app_root }}"
15 environment:
16 CONFIGURATION_FILE: "{{ clever_login_file }}"
17 when: service_dep.app_id is defined
diff --git a/tests/test-all.yml b/tests/test-all.yml
index 145b16d..8a6c0ba 100644
--- a/tests/test-all.yml
+++ b/tests/test-all.yml
@@ -4,4 +4,5 @@
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-scalability.yml 6- import_playbook: ./test-scalability.yml
7- import_playbook: ./test-service-deps.yml
7- import_playbook: ./test-restart-app.yml 8- import_playbook: ./test-restart-app.yml
diff --git a/tests/test-service-deps.yml b/tests/test-service-deps.yml
new file mode 100644
index 0000000..4e848e5
--- /dev/null
+++ b/tests/test-service-deps.yml
@@ -0,0 +1,36 @@
1---
2- name: Deploy an app & configure service dependencies 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_service_dependencies:
16 - app_id: app_00000000-2222-2222-2222-000000000000
17 - addon_id: addon_00000000-0000-0000-0000-000000000000
18 post_tasks:
19 - name: Check stubbed commands
20 shell: "{{ item.cmd }}"
21 ignore_errors: true
22 vars:
23 display: "{{ item.display }}"
24 with_list:
25 - cmd: "grep service ../clever-commands"
26 display: "Expected 'clever service' command to be called"
27 register: tests_results
28 - name: show results
29 debug:
30 msg:
31 - "failed_results: {{ failed_results }}"
32 - "success_results: {{ success_results }}"
33 failed_when: tests_results is failed
34 vars:
35 failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
36 success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"