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

前端 未结 1 1102
鱼传尺愫
鱼传尺愫 2020-12-18 08:44

I am trying to deploy my code to AWS using elastic beanstalk but keep running into errors when deploying.

I added a gem \'rb-readline\' and when I check the logs I s

相关标签:
1条回答
  • 2020-12-18 09:09

    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

    0 讨论(0)
提交回复
热议问题