Middleman (Ruby) build fails only when cached

This is about GitHub - henrik/hond.ae: Honda e knowledge base site. being deployed to https://hondae.netlify.app/.

It uses the Ruby “middleman” static site generator. Whenever I do a clean build, it succeeds. But incremental, cached builds consistently fail.

Here is a full failed log:

10:24:14 PM: Build ready to start
10:24:20 PM: build-image version: 195fbe127e5c374d9c4758652cb62e3b8936a395 (focal)
10:24:20 PM: build-image tag: v4.6.0
10:24:20 PM: buildbot version: 43c70c62bfed821cfaaabbb50f00238dd4bdd2d6
10:24:20 PM: Fetching cached dependencies
10:24:20 PM: Starting to download cache of 160.9MB
10:24:22 PM: Finished downloading cache in 1.786107474s
10:24:22 PM: Starting to extract cache
10:24:27 PM: Finished extracting cache in 5.027137419s
10:24:27 PM: Finished fetching cache in 6.857056898s
10:24:27 PM: Starting to prepare the repo for build
10:24:27 PM: Preparing Git Reference refs/heads/main
10:24:28 PM: Parsing package.json dependencies
10:24:29 PM: Starting build script
10:24:29 PM: Installing dependencies
10:24:29 PM: Python version set to 2.7
10:24:30 PM: Started restoring cached node version
10:24:31 PM: Finished restoring cached node version
10:24:32 PM: v16.14.2 is already installed.
10:24:33 PM: Now using node v16.14.2 (npm v8.5.0)
10:24:33 PM: Started restoring cached build plugins
10:24:33 PM: Finished restoring cached build plugins
10:24:33 PM: Required ruby-3.1.1 is not installed.
10:24:33 PM: To install do: 'rvm install "ruby-3.1.1"'
10:24:33 PM: Attempting ruby version 3.1.1, read from .ruby-version file
10:24:34 PM: Started restoring cached ruby version
10:24:34 PM: Finished restoring cached ruby version
10:24:38 PM: Using ruby version 3.1.1
10:24:38 PM: Using bundler version 2.3.10 from Gemfile.lock
10:24:39 PM: Successfully installed bundler-2.3.10
10:24:39 PM: 1 gem installed
10:24:39 PM: Using PHP version 8.0
10:24:39 PM: Started restoring cached ruby gems
10:24:39 PM: Finished restoring cached ruby gems
10:24:39 PM: Installing gem bundle
10:24:39 PM: Creating deploy upload records
10:24:39 PM: /opt/buildhome/.rvm/gems/ruby-3.1.1/bin/bundle: 6: exec: /opt/buildhome/.rvm/gems/ruby-3.1.1/bin/ruby: not found
10:24:39 PM: Error during gem install
10:24:39 PM: Build was terminated: Build script returned non-zero exit code: 1
10:24:39 PM: Failing build: Failed to build site
10:24:39 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
10:24:39 PM: Finished processing build request in 19.545191114s

Build settings:

Base directory: Not set
Build command: bundle exec middleman build
Publish directory: build
Deploy log visibility: Logs are public
Builds: Active

The error makes me think it’s trying to run “ruby” as though it’s a Gem binary, but I don’t yet understand why. Any ideas?

Try removing the.ruby-version file. For more detailed logs, use bundle exec middleman build --verbose or middleman build --verbose.


Thank you, @tomrutgers! After removing the .ruby-version file it does seem to work.

It then picks Ruby 2.7.2, “Attempting ruby version 2.7.2, read from environment” which is fine by me.

I notice the deploys seem pretty slow – it says it restores cached Ruby gems, but then still spends a few minutes fetching and installing them – but that’s a separate problem, and not a big deal for me :slight_smile:

Is it still slow when you redeploy?

Thank you. The first one after the “Remove .ruby-version” commit was also slow (both of them ~4m 30s) so I assumed it didn’t cache correctly, but I see every push since has deployed in ~30s! Very good.

That second also-slow build started logging right after the first build said the site was live but a few seconds before the last log line, so perhaps the cache wasn’t yet in place or whatever.

It’s reading the gem cache and concluding there’s differences between the cache and the gemfile, therefore bundler is running its install command. The next time you redeploy, there are no differences between the cache and the gemfile, so bundle install is skipped resulting in a much faster build. Whenever a build fails, the cache from that build is not saved, as there might be gems causing the failure.