Google-cloud-ruby: unable to deploy rails app to ruby 2.5 app engine standard environment

Created on 13 Nov 2019  路  5Comments  路  Source: googleapis/google-cloud-ruby

No matter what I do, I can't get a blank Rails app to deploy to the app engine ruby 2.5 standard environment. I've already tried everything you will find if you extensively google this issue.

Existing stackoverflow issue I created that has no answer yet: https://stackoverflow.com/questions/58839261/proper-ruby-version-for-google-app-engine-ruby-standard-environment-w-rails

Environment details

  • OS: Macos Catalina
  • Ruby version: have tried 2.5.5 and 2.5.7
  • Gem name and version: rails 6.0.1

Steps to reproduce

  1. Clone this repo: [email protected]:sam0x17/ruby_standard_environment_version_issue.git
  2. Try to deploy it gcloud app deploy .

If I use Ruby 2.5.5 locally and in my .ruby-version and Gemfile, the deploy fails with:

Your Ruby version is 2.5.7, but your Gemfile specified 2.5.5.

If I use Ruby 2.5.7 locally and in my Gemfile and .ruby-version file, the deploy succeeds, but visiting the app results in the following error in the logs:

bundler: failed to load command: rails (/srv/vendor/bundle/ruby/2.5.0/bin/rails)
Bundler::RubyVersionMismatch: Your Ruby version is 2.5.5, but your Gemfile specified 2.5.7

And note that I have properly set up .gcloudignore to include .ruby-version and other important dotfiles that are ignored by default by app engine.

I've tried everything I can think of, but everything always results in one of the above two errors. And yes, I am ensuring that I am setting my default in rvm to the current one I am trying to deploy, and re-loading my terminal, etc., when doing so.

question

All 5 comments

Hi @sam0x17,

Strictly speaking, your question is unrelated to this project, which is home to client libraries for services such as Google Cloud Storage, etc. However, we certainly care a lot about Rubyists being successful with the App Engine Ruby runtime, so I'm glad you opened this issue here as well as asking on Stack Overflow. We might be able to help you troubleshoot it.

I've already tried everything you will find if you extensively google this issue.

On that note, in order to improve the situation for future searches, if you can, please follow up by providing any solution here. Thanks for linking your Stack Overflow question from this issue.

@quartzmo thanks I appreciate it -- over the years I have come here in lieu of a more appropriate venue when stackoverflow doesn't yield any results

@sam0x17 I added a comment on stack overflow.

@dazuma thanks, changing the version constraint to ruby "~> 2.5.5" in my Gemfile fixed it!!

This is the answer @dazuma posted on SO:


Here's the official word from the Ruby App Engine runtime team.

If you have a Ruby version constraint in your Gemfile, always use a pessimistic version constraint (or other mechanism to allow more recent patchlevels), rather than locking to a specific patchlevel. For example, use something like ruby "~> 2.5.5" to indicate 2.5.5 or any newer patchlevel, rather than ruby "2.5.5" or ruby "2.5.7". This isn't a temporary workaround, but an actual requirement and best practice for App Engine standard.

The reason is twofold. During a rollout of a new Ruby version, there may be a short period where the bundle install is run on a different Ruby patchlevel than the app itself. This is what you ran into, and it apparently is the expected behavior because the "bundle builder" component is rolled out independently from the runtime image.

But more importantly, App Engine standard may upgrade your Ruby patchlevel at any time. Your app might be running on Ruby 2.5.6 today, but tomorrow you might find it upgraded to Ruby 2.5.7, even if you didn't redeploy explicitly. This is App Engine's intended behavior: it transparently applies critical updates and security patches, and that may include updating the patchlevel of the Ruby interpreter. (Note that App Engine only updates the Ruby patchlevel. It will never update your app from, say, Ruby 2.5 to Ruby 2.6 unless you explicitly tell it to use a Ruby 2.6 runtime.) Because of this feature, if your Gemfile specifies the Ruby version, it needs to be able to handle patchlevel updates, for example by using a pessimistic version constraint.

As a secondary note, .ruby-version is ignored on App Engine standard environment. Note this is different from App Engine flexible environment, which uses the file as a way for your app to request a specific Ruby version to run on. The standard environment, however, chooses and controls the Ruby version for you, and you don't get a say.

Apologies for the predicament. I'll work with the team to try to clarify our documentation on this.

Was this page helpful?
0 / 5 - 0 ratings