Store settings in environment instead of config to avoid git merges overwriting an environment's specific settings

Created on 21 June 2021, over 3 years ago
Updated 5 August 2024, 4 months ago

Problem/Motivation

In a development workflow, if we have live, staging and development, then the corresponding external SAML provider may be different, or we may actually disable it on development platforms for convenience.

However, such variation will be written to config yml files and there's the risk that setting written to those files in git will overwrite those for another platform at deploment time.

Steps to reproduce

As above.

Proposed resolution

Provide a means to store settings as environment variables, outside of config.

Current work around is to remove specific config yml file from git using git rm --cached and .gitignore it so that it won't be in git. Perhaps store a backup copy in a non-active separate docs folder if needed.

Remaining tasks

tbd

User interface changes

tbd

API changes

tbd

Data model changes

tbd

Feature request
Status

Active

Version

2.22

Component

Code

Created by

🇬🇧United Kingdom therobyouknow

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇷Brazil Diego_Mow

    Here i'm using config_split module to have specific environment configs, and added miniorange_saml to it.
    That solves a lot of issues.
    I think we can close this this one.

  • 🇬🇧United Kingdom therobyouknow

    Drupal allows for config to be set in settings.php, so jwwj comment #2 will work, or variations of it: https://www.drupal.org/project/miniorange_saml/issues/3219912#comment-14... Store settings in environment instead of config to avoid git merges overwriting an environment's specific settings Active

    Also, good to see an example of config_split provided by Diego_Mow. Though with jwwj's solution, it can be achieved without config_split.

    So going with the jwwj approach (and that in https://www.drupal.org/project/miniorange_saml/issues/3219912#comment-14... Store settings in environment instead of config to avoid git merges overwriting an environment's specific settings Active ), the way I do it for generally storing platform specific config outside of the git source tree, is I would have a git-version controlled settings.php (with no environment specific settings, nor sensitive credentials, which references, via the include keyword, a settings.local.php which is environment specific that contains the specific settings and credentials, including for the general drupal database. settings.local.php would be a symlink to a place outside of the git source tree. The symlink itself would be in the same subfolder as settings.php.

    web/sites/default/ :
    settings.php <-- git version controlled
    settings.local.php - a symlink e.g. ../../../../../../settings/1/settings.local.php

    In settings.php:

    /* settings.local.php (symlink) is in same folder as settings.php */
    if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
      include $app_root . '/' . $site_path . '/settings.local.php';
    }
    

    In settings.local.php (outside of git source), you would write the config as follows. Essentially it's writing the equivalent php nested array structure to reflect the series of labels and their indentations in yaml, so if your original yml config file looked like:

    config_item_a:
      config_item_b:
        config_item_c:
          config_item_d: 'value1, value2, value3'
    

    then your equivalent php code in settings.local.php would look like:

    $config['config_item_a']['config_item_b']['config_item_c']['config_item_d'] =  'value1, value2, value3';
    

    Further notes:
    You could of course git ignore settings.local.php as a file in the source tree, but symlinking it out of there avoids accidental committing to the git source tree.

    The environment specific data and credentials could be set and referenced from the OS's i.e. Linux's own environment variables, as might imagine could be a common place practice for containerized environments.

Production build 0.71.5 2024