Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON import for environment variables #64

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ clever_app_confdir: "{{ clever_app_root }}/.clever_cloud"
clever_login_file: "{{ clever_app_confdir }}/login"

clever_haskell_entry_point: "{{ clever_entry_point | default(None) }}"
clever_haskell_env: {}
clever_env: {}

clever_disable_metrics: false
Expand Down
8 changes: 8 additions & 0 deletions filter_plugins/env_json_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python

class FilterModule(object):
def filters(self):
return {'json_env_map': self.json_env_map}

def json_env_map(self, env):
return [{'name': k, 'value': str(v)} for k,v in env.items()]
2 changes: 1 addition & 1 deletion tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
CONFIGURATION_FILE: "{{ clever_login_file }}"

- name: Push Environment
shell: "clever env import < {{ clever_app_confdir }}/env"
shell: "clever env import --json < {{ clever_app_confdir }}/env"
args:
chdir: "{{ clever_app_root }}"
environment:
Expand Down
10 changes: 10 additions & 0 deletions tasks/environment.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
- name: Setup haskell-specific environment variables
set_fact:
clever_haskell_env:
CC_RUN_COMMAND: "~/.local/bin/{{ clever_haskell_entry_point }}"
when: clever_haskell_entry_point is defined

- name: Assemble full environment
set_fact:
clever_env: "{{ clever_base_env | combine(clever_haskell_env) | combine(clever_env) }}"

- name: Create environment file
template:
src: env.j2
Expand Down
12 changes: 3 additions & 9 deletions templates/env.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{% for key, value in (clever_base_env | combine(clever_env)).items() %}
{{ key }}={{ value | to_json }}
{% endfor %}

{%- 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 }}
{% endif %}
{# dict2items is not enough here, all the values have to be stringified #}
{# git-blame this line for more explanations #}
{{ clever_env | json_env_map | to_json }}