Created
August 28, 2016 20:19
-
-
Save hannesl/a45ecf7304596a3b0d2784449c29a630 to your computer and use it in GitHub Desktop.
CleverCloud: Insert environment variables in declarative config files at deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"hooks": { | |
"postDeploy": "./clevercloud/post-deploy.sh" | |
}, | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Replace ${VARIABLE} in a file with the corresponding environment variables. | |
replace_variables () { | |
# http://stackoverflow.com/a/5274448/2061091 | |
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg; s/\$\{([^}]+)\}//eg' $1 >$2 | |
} | |
# Move config_local.production.yml to config_local.yml while inserting | |
# variables environment. | |
replace_variables app/config/config_local.production.yml app/config-en/config_local.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment