Skip to content

Instantly share code, notes, and snippets.

@airdrummingfool
Last active February 24, 2017 20:58
Show Gist options
  • Save airdrummingfool/29e73d6dfa68ec5da92e to your computer and use it in GitHub Desktop.
Save airdrummingfool/29e73d6dfa68ec5da92e to your computer and use it in GitHub Desktop.
A new version of the Elastic Beanstalk container removed the very useful $EB_CONFIG_* environment variables. This puts them back, as $EB_CONTAINER_*.
# The Ruby script at /opt/elasticbeanstalk/support/get_envvars.rb is responsible for compiling a list of
# environment variables for use throughout the system. This patches that file to add the EB container variables.
# Most of the added $EB_CONTAINER_* directly match the old $EB_CONFIG_* variables that Elastic Beanstalk did away with
# in a recent container version update; however, $EB_CONFIG_APP_CURRENT is now $EB_CONTAINER_APP_DEPLOY.
# Note: Since we're using `git apply` as a "better GNU patch" we need to pass `--unsafe-paths` in Git >=2.3.0
# See https://gist.github.com/airdrummingfool/29e73d6dfa68ec5da92e for updates and changelog
files:
"/tmp/add_container_envvars.patch" :
mode: "000755"
owner: root
group: users
content: |
--- ./get_envvars.rb 2015-01-28 01:52:31.000000000 +0000
+++ ./get_envvars.rb 2015-03-11 23:05:09.224547106 +0000
@@ -5,8 +5,10 @@
def get_env_vars
env_vars = JSON.parse(`/opt/elasticbeanstalk/bin/get-config environment`)
php_env_vars = JSON.parse(`/opt/elasticbeanstalk/bin/get-config optionsettings -n "aws:elasticbeanstalk:container:php:phpini"`)
+ container_vars = JSON.parse(`/opt/elasticbeanstalk/bin/get-config container`)
php_env_vars.each { |key, value| env_vars['PHP_' + key.upcase] = value }
+ container_vars.each { |key, value| next if !value.is_a?(String); env_vars['EB_CONTAINER_' + key.chomp("_dir").upcase] = value }
env_vars['PHP_DATE_TIMEZONE'] = 'UTC';
commands:
01-patch_get_envvars.rb:
command: grep --silent "container_vars" /opt/elasticbeanstalk/support/get_envvars.rb || git apply /tmp/add_container_envvars.patch --directory=/opt/elasticbeanstalk/support --ignore-whitespace --unsafe-paths
@airdrummingfool
Copy link
Author

The 6th revision simply adds a link back to this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment