Skip to content

Instantly share code, notes, and snippets.

@hannesl
Created August 28, 2016 20:19
Show Gist options
  • Save hannesl/a45ecf7304596a3b0d2784449c29a630 to your computer and use it in GitHub Desktop.
Save hannesl/a45ecf7304596a3b0d2784449c29a630 to your computer and use it in GitHub Desktop.
CleverCloud: Insert environment variables in declarative config files at deploy
{
...
"hooks": {
"postDeploy": "./clevercloud/post-deploy.sh"
},
...
}
#!/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