datto / parameter-auto-env
Composer plugin to add support for "env-map": "auto"
Installs: 2 033
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 8
Forks: 1
Open Issues: 0
Type:composer-plugin
Requires
- php: >=5.3.3
- composer-plugin-api: ^1.1
- incenteev/composer-parameter-handler: ~1.0|~2.0
- symfony/yaml: ~2.3|~3.0
Requires (Dev)
- composer/composer: 1.0.*@dev
- squizlabs/php_codesniffer: >=1.5.0
This package is not auto-updated.
Last update: 2021-09-17 13:10:58 UTC
README
Composer plugin to add support for "env-map": "auto"
to
Incenteev/ParameterHandler
This allows for simple deployment when configuration values are set as environment variables on CI workers but not on development or production machines. Developers can continue with their original parameter workflow.
Installation
composer req datto/parameter-auto-env
With the plugin installed you can now use the new configuration options inside of extra.incenteev-parameters
:
"env-map": "auto"
to enable automatic mapping of environment variables to parameters for the file"auto-env-prefix": ""
optional prefix for all environment variables (default "")"auto-env-fullname": true
use full name for variable names, e.g.parameters.database_host
instead ofdatabase_host
(default true)
Basic Example:
"incenteev-parameters": {
"file": "app/config/parameters.yml",
"env-map": "auto"
}
Usage with run-script:
"env-map": "auto"
will automatically apply to any Composer install or update events that include a call to
Incenteev/ParameterHandler
. However, to work during other events or manual script execution you must explicitly add
the call to buildMap in your scripts object before the buildParameters call. e.g.
"scripts": {
"update-parameters": [
"Datto\\Composer\\ParameterAutoEnv\\AutoEnvPlugin::buildMap",
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
],
"post-install-cmd": [
"@update-parameters"
],
"post-update-cmd": [
"@update-parameters"
]
}
Execution will now function correctly when running composer run-script update-parameters
Environment variable names
Each parameter detected in configured files will attempt to be auto-set by a similarly named environment variable. These
will be uppercase and any .
is replaced with two _
s. e.g:
parameters.secret_key
will expectPARAMETERS__SECRET_KEY
parameters.api-url
will expectPARAMETERS__API-URL
parameters.database.name
will expectPARAMETERS__DATABASE__NAME
The composer auto-env-check
command can be run to check expected environment variable names.
Deployment environment
Environment variables are parsed as inline Yaml values and follow standard behaviour in Incenteev/ParameterHandler for env-map parameters.
This plugin supplies the composer command composer auto-env-check
to ensure all parameters have a corresponding
environment variables when run, returning 0 if successful and 1 if any are missing. This can be run in the test phase
of your CI pipeline.
Mixed environment
All parameters in a file must be mapped automatically on deployment if any are. If exceptions are needed these should be
placed in a separate file without the "env-map": "auto"
setting, see: Managing multiple ignored files
Example:
"incenteev-parameters": [
{
"file": "app/config/parameters.yml"
},
{
"file": "app/config/secrets.yml",
"env-map": "auto"
}
]