From 244339e70a1be830ac02306e1feb4383fe73572b Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Thu, 18 Jun 2020 16:09:46 +0200 Subject: Use JSON import for environment variables The env can be provided as a JSON list `[{"name": "PORT", "value": "8080"}]`. The `dict2items` filter provided by ansible is _almost_ what we want, but it keeps the value original types (a boolean is kept as a boolean in the JSON value). Since environment variables are strings and `clever-tools` does not want to make the implicit coercion for us, we need to do it ourselves. --- templates/env.j2 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'templates') diff --git a/templates/env.j2 b/templates/env.j2 index 30bda82..e97ef43 100644 --- a/templates/env.j2 +++ b/templates/env.j2 @@ -1,9 +1,10 @@ -{% for key, value in (clever_base_env | combine(clever_env)).items() %} -{{ key }}={{ value | to_json }} -{% endfor %} - -{%- if clever_haskell_entry_point %} +{% set static_env = clever_base_env | combine(clever_env) %} +{% set dynamic_env = {} %} +{% if clever_haskell_entry_point %} {# Haskell only #} {# https://www.clever-cloud.com/doc/get-help/reference-environment-variables/#haskell #} -CC_RUN_COMMAND={{'~/.local/bin/' + clever_haskell_entry_point | to_json }} +{% set dynamic_env = { 'CC_RUN_COMMAND': '~/.local/bin/' + clever_haskell_entry_point } %} {% endif %} +{# dict2items is not enough here, all the values have to be stringified #} +{# git-blame this line for more explanations #} +{{ static_env | combine(dynamic_env) | json_env_map | to_json }} -- cgit v1.2.3