Trouble creating elastic beanstalk environment for Ruby on Rails 6 (rvm, rbenv, .ruby-version issues)

假如想象 提交于 2021-01-04 06:50:25

问题


I've been trying to figure out how to deploy a simple rails app to elastic beanstalk using the cli on my macOS, but every time I get to eb create I get this error:

2020/08/06 07:22:56.626563 [INFO] Executing instruction: StageApplication
2020/08/06 07:22:56.626674 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2020/08/06 07:22:56.626695 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2020/08/06 07:22:56.638657 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2020/08/06 07:22:56.640331 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/08/06 07:22:56.640351 [INFO] The dir .platform/hooks/prebuild/ does not exist in the application. Skipping this step...
2020/08/06 07:22:56.640356 [INFO] Executing instruction: stage ruby application
2020/08/06 07:22:56.640360 [INFO] stage ruby application ....
2020/08/06 07:22:56.640386 [INFO] Running command /bin/sh -c bundle config set --local deployment true
2020/08/06 07:22:56.669550 [ERROR] An error occurred during execution of command [app-deploy] - [stage ruby application]. Stop running the command. Error: install dependencies in Gemfile failed with error Command /bin/sh -c bundle config set --local deployment true failed with error exit status 1. Stderr:rbenv: version `ruby-2.7.0' is not installed (set by /var/app/staging/.ruby-version)

And then I run eb terminate so that I don't get charged for anything. The error just says I don't have 2.7.0 installed even though my Gemfile lists 2.7.1 and I ran bundle install without any issues.

For the eb platform version I selected the first option listed here, so that would be Ruby 2.7.1-p83, which is what my ruby -v currently returns so I'm not sure why it's looking for 2.7.0...

I used rvm in order to update to the latest Ruby, previously I had Ruby 2.6.3 and the error at the bottom said 'ruby-2.6.3' is not installed'. It was difficult to use rbenv to update to the latest version of Ruby on my mac, I think because it had issues with my systems version of Ruby? So I removed rbenv from brew and started using rvm instead. But I feel this is where the problem lies, since it looks like elastic beanstalk is using rbenv to try and find the correct version of Ruby? Stderr:rbenv: version `ruby-2.7.0' is not installed

Any help or direction would be appreciated, even just an understanding of what ".ruby-version" is or if rvm shouldn't be used for deployment.


回答1:


".ruby-version" is a file saved at the root of your project that indicates what ruby version you are using, so it reads the version automatically. (if that's what you asked)

For your problem, there are a couple of things you've got to make sure to ensure that the ruby version is applied correctly.

  1. Check the ruby version installed in the EC2 instance.

You can check this via ssh eb ssh and then ruby -v The result would be the ruby version that you need to use. (prefer to check it directly on the EC2 instance, it may differ if you check it through EB )

  1. Make sure your .gemfile and your .ruby-version files have the correct version declared.

If you do not have a .ruby-version file yet, Create one with the version you got in step 1.

I was dealing with the same issue, and the ruby version installed in the EC2 instance was different from what the one returned if I made eb health --refresh, so I followed the steps above and then rebuild my environment and it worked, so you may also need to rebuild your environment



来源:https://stackoverflow.com/questions/63291168/trouble-creating-elastic-beanstalk-environment-for-ruby-on-rails-6-rvm-rbenv

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