issue deploying rails 5 application to AWS using Elastic Beanstalk due to rb-readline

烂漫一生 提交于 2019-11-29 07:46:43

I had a similar error, but with dot-env rails gem. It looks like it might be same root cause.

It appeared to be because $HOME was not set by AWS during the deploy, and a call to File.expand_path dies when it's not set.

Possible fixes:

  1. Remove rbreadline
  2. Add a HOME environment variable into your EB configuration or eb setenv (and redeploy)
  3. Add a config file that overwrites the existing deploy script & adds a $HOME variable before the bundle install command is run

I successfully tried the first and last option, and settled with using a forked version of the Gem that handled a missing $HOME correctly.

I suspect the 2nd version is the more correct way to do it, but to be honest it's unclear why Amazon didn't set a $HOME to begin with, and what it should actually be.

The app will exist in either /var/app/ondeck or /var/app/current so either one of those two folders, or /home/webapp (per the error) all might be a good value to start with.

This may not be 100% the root cause because I've had varying degrees of luck with replicating this locally with different versions of Ruby. However, the expand_path docs do say HOME must be set correctly so this may be the cause.

https://ruby-doc.org/core-2.4.2/File.html#method-c-expand_path

More detail on working solutions:

I found two solutions that worked (try one or the other)

At one point I did submit a PR with dotenv to fix this issue. https://github.com/bkeepers/dotenv/pull/314. As far as I recall, this fixes it, and doesn't break anything else. The issue was marked as wontfix by the automated bot, but has recently been re-opened by the new maintainers

I ultimately switched back to the ebextensions approach after it was clear my PR wouldn't be merged, but last I recall it was functioning as expected (and I think the better approach)

The other solution I used was to create a new config file that replaced the /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh file.

  • Get the current version of that file from an existing application server
  • Create an ebextension config that creates that file (it will overwrite the original) but include a line to set the $HOME variable before the bundle install command is run.
  • Set the $HOME value to whatever it would be for the default user

The documentation for creating such a file using ebextensions are here:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!