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

Add drupal .env file support #23

Merged
merged 4 commits into from
Sep 17, 2021
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
2 changes: 2 additions & 0 deletions molecule/drupal8-db-dump/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
steamengine_db_dump_url: https://delivery.steamulo.org/SteamEngineV2_tests/db_dump_drupal_8.zip
steamengine_build_url: https://delivery.steamulo.org/SteamEngineV2_tests/drupal_8.zip
steamengine_build_checksum: sha1:a354cceb222ef776644394f72f3f9278265ba6ae
steamengine_drupal_env: |
ENV_VAR_TEST=test_value
steamengine_drupal_project_setting: |
$databases['default']['default'] = array (
'database' => 'drupal',
Expand Down
7 changes: 7 additions & 0 deletions molecule/drupal8-db-dump/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ def test_app_listening(host):
def test_drupal_index_page(host):
resp = host.run("curl --resolve 'drupal.test:80:127.0.0.1' http://drupal.test/").stdout
assert '<a href="/" title="Accueil" rel="home">drupal</a>' in resp


def test_drupal_env_file(host):
env_file = host.file("/drupal/conf/.env")
assert env_file.exists
env_file_content = env_file.content_string
assert 'ENV_VAR_TEST=test_value' in env_file_content
2 changes: 2 additions & 0 deletions molecule/drupal8-drush/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
steamengine_drupal_install_use_existing_config: true
steamengine_build_url: https://delivery.steamulo.org/SteamEngineV2_tests/drupal_8.zip
steamengine_build_checksum: sha1:a354cceb222ef776644394f72f3f9278265ba6ae
steamengine_drupal_env: |
ENV_VAR_TEST=test_value
steamengine_drupal_project_setting: |
$databases['default']['default'] = array (
'database' => 'drupal',
Expand Down
7 changes: 7 additions & 0 deletions molecule/drupal8-drush/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ def test_app_listening(host):
def test_drupal_index_page(host):
resp = host.run("curl --resolve 'drupal.test:80:127.0.0.1' http://drupal.test/").stdout
assert '<a href="/" title="Accueil" rel="home">drupal</a>' in resp


def test_drupal_env_file(host):
env_file = host.file("/drupal/conf/.env")
assert env_file.exists
env_file_content = env_file.content_string
assert 'ENV_VAR_TEST=test_value' in env_file_content
14 changes: 14 additions & 0 deletions tasks/drupal/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@
tags:
- steamengine_deploy_drupal

# Add .env file for env_variables drupal modules: https://www.drupal.org/project/env_variables

- include_tasks:
file: "./deploy_env_file.yml"
apply:
tags:
- steamengine_deploy
- steamengine_deploy_drupal
when:
- steamengine_drupal_env is defined and steamengine_drupal_env
- new_build_to_deploy
tags:
- always

- name: Check if database is empty
command: "{{ steamengine_drush_launcher_path }} -r {{ steamengine_project_root_path_web }} sql-query 'show tables'"
register: database_table_number
Expand Down
24 changes: 24 additions & 0 deletions tasks/drupal/deploy_env_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---

- name: Remove potential env file
file:
state: absent
path: "{{ steamengine_project_root_path_web }}/.env"

- name: Create external env file
copy:
content: |
# This file is managed by Ansible, all changes will be lost.
{{ steamengine_drupal_env }}
dest: "{{ steamengine_conf_path }}/.env"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
mode: u=rw,g=r,o=

- name: Create env symlink
file:
state: link
src: "{{ steamengine_conf_path }}/.env"
dest: "{{ steamengine_project_root_path_web }}/.env"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"