Elastic Beanstalk Ruby/Rails need to install git so bundle install works.. but is not

后端 未结 5 1878
一整个雨季
一整个雨季 2020-12-02 13:09

I\'m having an issue deploying our rails app.. I created a hook like the example on the AWS blog howto http://ruby.awsblog.com/post/Tx2AK2MFX0QHRIO/Deploying-Ruby-Applicatio

相关标签:
5条回答
  • 2020-12-02 13:36

    (Note that the following workaround should only be used if you must use Git sources for dependencies. It is recommended not to install dependencies from external Git repositories if it can be avoided. See below for details on why that is.)

    When using Git backed libraries in a Gemfile with Passenger, you must disable shared gems in an installation (in addition to installing Git in the hook you listed above). You can do this by setting the BUNDLE_DISABLE_SHARED_GEMS Bundler environment variable in your existing .ebextensions/ruby.config file like so:

    option_settings:
      - option_name: BUNDLE_DISABLE_SHARED_GEMS
        value: "1"
      - option_name: BUNDLE_PATH
        value: "vendor/bundle"
    
    packages:
      yum:
        git: []
    

    Disabling shared gems will force all dependencies to be vendored into your application in vendor/bundle as specified by the BUNDLE_PATH variable.

    Note that, whenever possible, you should avoid installing public libraries from Git sources with your application. Using Git for library locations introduces another point of failure for a deployment install, since the Git repository may be temporarily unavailable or even permanently moved. Also keep in mind that forcing vendored installs in a deployment will cause your Elastic Beanstalk deployments to be much slower on subsequent deploys of an app with the same dependencies. This is because the libraries will be re-installed at each deploy instead of taking advantage of the system-wide installation that Elastic Beanstalk has Bundler perform by default.

    In short, if there is an official RubyGem release of the library in question, you should use that version instead; and if not, you should suggest to the library author that an official RubyGem release be made available.

    FYI a similar question about this Git problem with regular Passenger/Rails deployments was previously asked: Rails 3: Passenger can't find git gems installed by bundler

    0 讨论(0)
  • 2020-12-02 13:41

    After trying the accepted answer, I found that a simpler .ebextensions/ruby.config was the only config that worked:

    packages:
      yum:
        git: []
    
    0 讨论(0)
  • 2020-12-02 13:52

    Another option is to package the gem source directly with your application and then point bundler at that.

    Copy the gem source into vendor/gems/mygem

    Then, in your Gemfile:

    gem 'mygem', path: File.join(File.dirname(__FILE__), 'vendor', 'gems', 'mygem')
    

    See more here: http://viget.com/extend/bundler-best-practices

    0 讨论(0)
  • 2020-12-02 13:55

    Amazon's Elastic Beanstalk Ruby AMI needs a little tweaking in order to allow you to bundle gems from git without sacrificing deployment speed, behavior you get out of the box with Capistrano and Heroku.

    Fortunately, the Elastic Beanstalk configuration API makes the necessary tweaks possible without requiring you to maintain a custom AMI.

    Here's the Elastic Beanstalk configuration that I use to get the desired, conventional Ruby deployment behavior with Amazon's own AMI: https://github.com/gkop/elastic-beanstalk-ruby .

    0 讨论(0)
  • 2020-12-02 13:58
    • ok well after lot of research and testing I figure this was related to Amazon having some issues with the passenger env values...
    • I was able to run manually rails s and then it worked fine and all gems loaded.. but with passenger it did not so find that if I run

      bundle pack --all

    • --all so it also packs the git gems..

    • it will then run like a charm..

    • to be able to have this run in the mean time Amazon fixes this issue with bundle I create a hook and force it to run after every install. not the best way but works.

    Note: using the hook I cant seen to run the command on EB updates so I git add the vendor/cache and it uploads it all by default.

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