From f642276169b56be94e8537458d0ce2286dc71748 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Wed, 1 Jul 2020 11:34:40 +0200 Subject: Add dhall definitions for linked service dependencies --- dhall/Config.dhall | 4 ++++ dhall/ServiceDependency.dhall | 9 +++++++++ dhall/package.dhall | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 dhall/ServiceDependency.dhall 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 @@ let Addon = (./Addon.dhall).Type +let ServiceDependency = (./ServiceDependency.dhall).Type + let Vault = ./Vault.dhall let FixedOrRange = @@ -28,6 +30,7 @@ let Config = , clever_haskell_entry_point : Optional Text , clever_disable_metrics : Bool , clever_addons : List Addon + , clever_service_dependencies : List ServiceDependency , clever_env : Environment , clever_build_flavor : Optional Text , clever_scaling : Optional ScalingParameters @@ -48,6 +51,7 @@ let mkConfig = , clever_haskell_entry_point = None Text , clever_disable_metrics = False , clever_addons = [] : List Addon + , clever_service_dependencies = [] : List ServiceDependency , clever_env = {=} , clever_build_flavor = None Text , 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 @@ +let ServiceDependency = + < Addon : { addon_id : Text } | Application : { app_id : Text } > + +let addon = λ(addon_id : Text) → ServiceDependency.Addon { addon_id = addon_id } + +let application = + λ(app_id : Text) → ServiceDependency.Application { app_id = app_id } + +in { 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 @@ -{ Addon = ./Addon.dhall, Config = ./Config.dhall, Vault = ./Vault.dhall } +{ Addon = ./Addon.dhall +, ServiceDependency = ./ServiceDependency.dhall +, Config = ./Config.dhall +, Vault = ./Vault.dhall +} -- cgit v1.2.3 From 45a5c1337b777f34c06d2ce99931414ba9f57ecd Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Wed, 1 Jul 2020 11:48:04 +0200 Subject: Add support for linking service dependencies --- README.md | 2 ++ defaults/main.yml | 6 ++++++ tasks/deploy.yml | 6 ++++++ tasks/service-dep.yml | 17 +++++++++++++++++ tests/test-all.yml | 1 + tests/test-service-deps.yml | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 tasks/service-dep.yml create mode 100644 tests/test-service-deps.yml 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: - `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.
+ 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: diff --git a/defaults/main.yml b/defaults/main.yml index 4e2ef8e..68e3abe 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 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 @@ 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 index 0000000..67621f6 --- /dev/null +++ b/tasks/service-dep.yml @@ -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 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 @@ - 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 index 0000000..4e848e5 --- /dev/null +++ b/tests/test-service-deps.yml @@ -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 }}" -- cgit v1.2.3 From 24a153433105ce2b20b31201ecfb966817c7a66e Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Wed, 1 Jul 2020 11:48:51 +0200 Subject: Fix `clever_addons` example --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 68e3abe..f117f15 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,7 +15,7 @@ clever_addons: [] # example # clever_addons: # - name: pg -# - env_prefix: POSTGRESQL_ADDON +# env_prefix: POSTGRESQL_ADDON clever_service_dependencies: [] # example -- cgit v1.2.3 From 3d3287e0767d13b0a81e5936ce9376d58f42e34c Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Wed, 1 Jul 2020 11:49:27 +0200 Subject: Remove compatibility code for now-unsupported clever-tools versions --- tasks/addon.yml | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) 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 @@ -- name: Gather addon information for {{ addon.name }} (clever --version < 1.5.0) - shell: > - set -o pipefail && - clever env | grep {{ addon.env_prefix }} - | sed -e 's/{{ addon.env_prefix }}_//' -e 's/=/: \"/' -e 's/$/\"/' - > {{ clever_app_confdir }}/{{ addon.name }}_env.yml - args: - chdir: "{{ clever_app_root }}" - executable: "bash" - environment: - CONFIGURATION_FILE: "{{ clever_login_file }}" - changed_when: False - when: clever_returned_version.stdout is version('1.5.0', '<') - -- name: Gather addon information for {{ addon.name }} (clever --version >= 1.5.0) +- name: Gather addon information for {{ addon.name }} shell: > set -o pipefail && clever env | grep {{ addon.env_prefix }} @@ -24,7 +10,6 @@ environment: CONFIGURATION_FILE: "{{ clever_login_file }}" changed_when: False - when: clever_returned_version.stdout is version('1.5.0', '>=') - name: Include addon var for {{ addon.name }} include_vars: -- cgit v1.2.3