Support .conf extension for config files (#388)

* Support .conf extension for config files

* Update the docs for env variables
This commit is contained in:
Pavel Andreyev 2019-09-24 19:22:00 +04:00 committed by Geoff Bourne
parent 2900062df5
commit b67580af2c
2 changed files with 13 additions and 5 deletions

View File

@ -240,6 +240,9 @@ There are some limitations to what characters you can use.
| Name | `0-9a-zA-Z_-` | | Name | `0-9a-zA-Z_-` |
| Value | `0-9a-zA-Z_-:/=?.+` | | Value | `0-9a-zA-Z_-:/=?.+` |
Variables will be replaced in files with the following extensions:
`.yml`, `.yaml`, `.txt`, `.cfg`, `.conf`, `.properties`.
Here is a full example where we want to replace values inside a `database.yml`. Here is a full example where we want to replace values inside a `database.yml`.
```yml ```yml

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
if [ "$REPLACE_ENV_VARIABLES" = "TRUE" ]; then if [ "${REPLACE_ENV_VARIABLES^^}" = "TRUE" ]; then
echo "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..." echo "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..."
while IFS='=' read -r name value ; do while IFS='=' read -r name value ; do
# check if name of env variable matches the prefix # check if name of env variable matches the prefix
# sanity check environment variables to avoid code injections # sanity check environment variables to avoid code injections
if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] && [[ $value =~ ^[0-9a-zA-Z_:/=?.+\-]*$ ]] && [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] \
echo "Replacing $name with $value ..." && [[ $value =~ ^[0-9a-zA-Z_:/=?.+\-]*$ ]] \
find /data/ -type f \( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" -or -name "*.properties" \) -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \; && [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then
echo "Replacing $name with $value ..."
find /data/ -type f \
\( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \
-or -name "*.conf" -or -name "*.properties" \) \
-exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \;
fi fi
done < <(env) done < <(env)
fi fi