How to resolve Rail 6 deploy error on AWS Elastic Beanstalk for ruby 2.7.1

Viewed 1141

I am trying to deploy a Rails 6 app on AWS via Elastic Beanstalk.

When I run eb deploy, it fails. When I look at the logs, I see this message

2020/06/03 14:19:51.457403 [ERROR] rbenv: version `2.7.0' is not installed (set by /var/app/staging/.ruby-version)

2020/06/03 14:19:51.457439 [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 `2.7.0' is not installed (set by /var/app/staging/.ruby-version)

However, when I eb ssh and run ruby -v I see that I am running ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

So I updated my Gemfile and .ruby-version to ruby 2.7.1 to match my AWS environment.

When I cd /var/app/staging and cat .ruby-version I get 2.7.1

So why is this deploy failing? I am not requiring ruby 2.7.0 anywhere in my project.

I've made sure to git push, so I know my Gemfile is pushed my to repo. I am going crazy trying to get this Rails App deployed.

3 Answers

I think you can set up ruby and make it as default based on your requirement. Just set up some config file in .ebextensions and set instructions to install ruby version you require and make it default. e.g.

  1. Create file in .ebextensions 00_ruby_install.config
  2. Add content which will install ruby
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/09_ruby_install.sh" :
    mode: "000775"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash
      ... Add ruby install instructions here ...

there is a .ruby-version file in the root of your directory that states a different ruby version, like in your case it would be ruby-2.7.0, just change it to ruby-2.7.1 or whatever is in your Gemfile.

Related