0

I'm using ruby27 in GAE Standard for Ruby. It currently resolves to 2.7.7. Previously, under 2.7.6, the GAE builder successfully precompiled assets. Now, even with /public/assets properly in .gcloudignore and ruby ~> "2.7.0" in Gemfile, the GAE depoyment build logs show errors like:

Step #2 - "build": Running Rails asset precompilation
Step #2 - "build": 2023/01/31 08:15:26 [DEBUG] GET https://registry.npmjs.org/yarn
Step #2 - "build": DEBUG: ***** CACHE HIT: "yarn"
Step #2 - "build": Yarn cache hit, skipping installation.
Step #2 - "build": DEBUG: Setting environment variable PATH=/layers/google.ruby.rails/yarn/bin:/layers/google.ruby.runtime/ruby/bin:/builder/google-cloud-sdk/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Step #2 - "build": --------------------------------------------------------------------------------
Step #2 - "build": Running "bundle exec ruby bin/rails assets:precompile (RAILS_ENV=production MALLOC_ARENA_MAX=2 RAILS_LOG_TO_STDOUT=true LANG=C.utf8)"
Step #2 - "build": rails aborted!
Step #2 - "build": ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
Step #2 - "build": /layers/google.ruby.bundle/gems/.bundle/gems/ruby/2.7.0/gems/execjs-2.8.1/lib/execjs/runtimes.rb:58:in `autodetect'
...

Some have similar problem because Yarn isn't installed, though we see above it is. I noticed that in the traceback, it references ruby 2.7.0 instead of 2.7.7. I also noticed that the buildpack seems to use Ruby 3.0

Step #2 - "build": Pulling image: us.gcr.io/gae-runtimes/buildpacks/google-gae-18/ruby/builder:ruby30_20230123a_3_0_5_RC00
Step #2 - "build": ruby30_20230123a_3_0_5_RC00: Pulling from gae-runtimes/buildpacks/google-gae-18/ruby/builder

Is the problem I'm seeing due to a weird ruby version mismatch within GAE's Cloud Builder system?

Lastly, we can see in the same GAE build logs that NodeJS is installed, and that the expected Ruby 2.7.7 is also installed for at least part of the build process:

Step #2 - "build": Setting Nodejs runtime version GOOGLE_NODEJS_VERSION: 12.22.12
Step #2 - "build": DEBUG: ***** CACHE MISS: "ruby"
Step #2 - "build": Installing Ruby Runtime v2.7.7.
Step #2 - "build": 2023/01/31 08:09:48 [DEBUG] GET https://dl.google.com/runtimes/ubuntu1804/ruby/ruby-2.7.7.tar.gz
Step #2 - "build": --------------------------------------------------------------------------------

We also see from the logs that execjs is installed even though it's not in the Gemfile.

Step #2 - "build": Fetching execjs 2.8.1
Step #2 - "build": Installing execjs 2.8.1

This gem should autodetect a JS interpreter in the system (NodeJS), yet it doesn't seem to be. How can i fix this? Or more to the point, how can I get GAE to precompile Ruby on Rails assets again?

hamx0r
  • 4,081
  • 1
  • 33
  • 46

1 Answers1

0

To avoid version mismatch you can refer this stackoverflow thread where they suggested

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.

To precompile Ruby on Rails assets, You can try either of the way

  1. Use the Ruby language-specific builder at gcr.io/gae-runtimes/buildpacks/ruby/builder
  2. Do asset precompilation locally (bundle exec ruby bin/rails assets:precompile) and then create the application image.

Or use latest gcr.io/buildpacks/builder image and retry your build as discussed here

Also check this github issue

Roopa M
  • 2,171
  • 4
  • 12
  • Regarding your block comment, i do have 'ruby ~> "2.7.0" in Gemfile' (using pessimistic operator already). I'm using GAE Standard, so I don't get to choose the builder, right? I think I'm stuck with `us.gcr.io/gae-runtimes/buildpacks/google-gae-18/ruby/builder:ruby30_20230123a_3_0_5_RC00` – hamx0r Feb 01 '23 at 05:23
  • @hamx0r I think you can use builder for sepcific version as mention [here](https://github.com/GoogleCloudPlatform/buildpacks#app-engine-and-cloud-function-builders-and-buildpacks) – Roopa M Feb 01 '23 at 08:11
  • @hamx0r are you still facing the issue? – Roopa M Feb 03 '23 at 06:26
  • Yes, I don't know how to select a specific builder when deploying with `gcloud app deploy app.yaml`. What `gcloud` flags do I use, or what `app.yaml` settings do I enter to select the buildpack? – hamx0r Feb 06 '23 at 16:55
  • 1
    @hamx0r Can you share the minimal reproducible steps? – Roopa M Feb 07 '23 at 08:03
  • M thanks for trying to help - I created a blank Rails project in Ruby Mine and copied over my "real" app.yaml, Gemfile and Gemfile.lock. I deployed and expected it to fail, yet it succeeded (though the app does nothing since there's no real code). If I can reproduce with minimal code, I'll share here. – hamx0r Feb 15 '23 at 11:17