Name: environmental_config
Owner: PwC Experience Center
Description: Overrides the configuration to be sync based on the server environment
Created: 2017-01-22 17:05:53.0
Updated: 2017-04-12 11:56:10.0
Pushed: 2017-04-12 11:49:56.0
Homepage: null
Size: 42
Language: PHP
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Environmental_config is a module that helps you automatically importing environment specific configuration without any hassle.
It's ideal when you need different settings for a specific module or system configuration in your development/staging or live server.
It runs with the standard Drupal Configuration Synchronisation and doesn't require much configuration, in fact there is no UI provided by this module.
You have your Google Analytics module with a live API key saved in the Drupal configuration. You don't want to manually change the API key every time you deploy a new development server.
You have another third-party module that connects with your client's CRM live database and you don't want to risk to alter or have access to sensitive data on non-live environments.
You have your development bunch of modules that have to bee manually re-enabled every time a live db import happens.
Environmental_config can help you by managing environment-based configuration files and auto-importing them with the standard Drupal configuration synchronisation or through a specific Drupal console command.
It has been designed especially to work in CI environments where there are limited options to work with custom system environment variables and settings.
Config_split provides similar functionality but works with a
pre-configured profile editable from the UI, it also offers export
functionality.
Environmental_config doesn't provide a UI, it only needs a valid configuration in the settings.php file where to extract the current environment name. Once the settings are valid its work is based on the environment detected and will work without further user input (ideal for CI environments).
===============
===============
path/to/drupal/root
oser require drupal/environmental_config
al module:install environmental_config
================
Make sure to have followed the installation steps, especially step number 2
.
Environmental_config needs to know the environment where the website is running on and the location of the configuration files to import for the current environment, if no environment is detected, no override will be applied and the default configuration will be imported.
In two simple steps:
dev
sites/default/config/dev/
Environmental_config will not interact with the export process, so you will need to manually place any environmental configuration in the environment folder you created.
The following steps will explain multiple ways to define and discover an environment name and how to specify a configuration folder for your environment.
To specify the folder where your environmental files are stored, use the standard Drupal config_directories array as you would have done for any other configuration directory.
Assuming that you named your development environment dev
and you want to
store all the dev configuration under sites/default/config/dev
,
just add this line in your settings.php
file:
fig_directories['dev'] = 'sites/default/config/dev';
Note that in the folder sites/default/config/dev
you will only store
the configuration you want to keep “environment related” and not the full
website configuration.
To specify on which environment the site is running, you have different options (and many others can be added via plugin, see developers section):
At the bottom of you Settings.php file add the current line:
tings['environmental_config']
plugins']['settingsfile']['env'] = 'ENVIRONMENT';
Replace YOUR_ENVIRONMENT
with the name of your environment.
In your vHost or through CLI just declare the environmental variable
ENVIRONMENTAL_CONFIG_ENV
assigning as value the environment name you
want to use.
Create a .yml file with the filename you wish and add the environment name based on the base_url:
Please note that the URL must be defined as output by the global $base_url
without any trailing slash or http(s) prefix.
box.dev:
v: dev
ing.mysite.it:
v: staging
In the file above we defined that if we are running the site with the URL
sandbox.dev
the relative environment name will be dev
, while on
staging.mysite.it
the environment name will be staging
.
Last step is to let environmental_config know the path of our newly created
yml file, just add this line at the bottom of your settings.php
file assuming
that our custom file is placed just outside the docroot folder:
tings['environmental_config']['plugins']['customfile'] = [
nvironments_file_path' => '/../../../mycustomfile.yml',
========
You can use environmental_config via:
config:envimport
Visit the standard drupal page admin/config/development/configuration
.
If there are any files overridden you will see a list showing them.
Just click Import all
to start the import process.
In case your environmental files aren't showing, you can rebuild the temp
folder by clicking Rebuild environmental configuration folder
or by
clearing the site cache.
You can use the power of environmental_config also by command line by
running the command drupal config:envimport
with a few options:
By default, if environmental_config fails to retrieve the environment, it won't import anything.
Example of usage:
==================
======
========
Environmental_config only works on the Synchronisation tab (Import all) and not on the single Import tab.
Please note that environmental_config doesn't act in the export process. You will need to manually create your environmental configuration files and put in your environmental config directory.
====================
Current maintainers:
====================
In order to correctly alter the config import from the Web UI,
Environmental_config needs to override the service config.storage.staging
.
As you know, if more than one module is overriding a single service, this can
fall in an unexpected series of unpredictable events so, make sure
you are not using any other module that rewrites the service above.
If you need to create your own environment detector plugin to suit your website
requirements, what you only need to do is create an EnvironmentDetector
plugin that returns an environment string.
By extending the class EnvPluginBase
you will inherit the correct interface
to make your job easier.