Caching rvm ruby version in build/deploy?

I’m trying to streamline my build and one of the things I see it doing is downloading Ruby every time. I’m using a newer version of Ruby than the Ubuntu default.

What takes 5 seconds locally takes 50 seconds on Netlify because 40 seconds are setup. I know a minute is not a lot, but small gains would help my workflow.

I had read that Ruby should be cached but that does not seem to be the case?

If not, your selected version will be installed using rvm and then cached to speed up subsequent builds.

So, I’d like to know how to cache Ruby, and/or any other small gains in my build time.

Many thanks!
matt

1:14:28 AM: build-image version: 8d7bce6c4bf50ad5a72d21731c81d47e9b46a4a1 (focal)
1:14:28 AM: buildbot version: 8d7bce6c4bf50ad5a72d21731c81d47e9b46a4a1
1:14:28 AM: Fetching cached dependencies
1:14:28 AM: Starting to download cache of 284.2MB
1:14:31 AM: Finished downloading cache in 2.549s
1:14:31 AM: Starting to extract cache
1:14:33 AM: Finished extracting cache in 1.697s
1:14:33 AM: Finished fetching cache in 4.296s
1:14:33 AM: Starting to prepare the repo for build
1:14:33 AM: Preparing Git Reference refs/heads/master
1:14:34 AM: Parsing package.json dependencies
1:14:35 AM: Starting to install dependencies
1:14:35 AM: Python version set to 3.8
1:14:35 AM: Required ruby-3.2.1 is not installed.
1:14:35 AM: To install do: 'rvm install "ruby-3.2.1"'
1:14:35 AM: Attempting Ruby version 3.2.1, read from .ruby-version file
1:14:35 AM: Required ruby-3.2.1 is not installed - installing.
1:14:35 AM: Searching for binary rubies, this might take some time.
1:14:36 AM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-3.2.1.tar.bz2
1:14:36 AM: Checking requirements for ubuntu.
1:14:36 AM: Requirements installation successful.
1:14:36 AM: ruby-3.2.1 - #configure
1:14:36 AM: ruby-3.2.1 - #download
1:14:36 AM: No checksum for downloaded archive, recording checksum in user configuration.
1:14:36 AM: ruby-3.2.1 - #validate archive
1:14:42 AM: ruby-3.2.1 - #extract
1:14:44 AM: ruby-3.2.1 - #validate binary
1:14:45 AM: ruby-3.2.1 - #setup
1:14:45 AM: ruby-3.2.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-3.2.1@global
1:14:45 AM: ruby-3.2.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
1:14:46 AM: ruby-3.2.1 - #generating global wrappers........
1:14:46 AM: ruby-3.2.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-3.2.1
1:14:46 AM: ruby-3.2.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
1:14:46 AM: ruby-3.2.1 - #generating default wrappers........
1:14:47 AM: Using /opt/buildhome/.rvm/gems/ruby-3.2.1
1:14:47 AM: Using Ruby version 3.2.1
1:14:47 AM: Using Bundler version 2.4.6 from Gemfile.lock
1:14:47 AM: Started restoring cached ruby gems
1:14:47 AM: Finished restoring cached ruby gems
1:14:47 AM: Installing gem bundle
1:14:47 AM: [DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local path '/opt/build/cache/bundle'`, and stop using this flag
1:14:47 AM: [DEPRECATED] The --binstubs option will be removed in favor of `bundle binstubs --all`
1:14:50 AM: Fetching gem metadata from https://rubygems.org/...........
1:14:50 AM: Resolving dependencies...
1:14:50 AM: Using bundler 2.4.6
1:14:50 AM: Using eventmachine 1.2.7
1:14:50 AM: Using ffi 1.15.5
1:14:50 AM: Using forwardable-extended 2.6.0
1:14:50 AM: Using google-protobuf 3.22.2 (x86_64-linux)
1:14:50 AM: Using rb-fsevent 0.11.2
1:14:50 AM: Using rexml 3.2.5
1:14:50 AM: Using mercenary 0.4.0
1:14:50 AM: Using safe_yaml 1.0.5
1:14:50 AM: Using unicode-display_width 2.4.2
1:14:50 AM: Using webrick 1.8.1
1:14:50 AM: Using jekyll-paginate 1.1.0
1:14:50 AM: Using nuggets 1.6.1
1:14:50 AM: Using public_suffix 5.0.1
1:14:50 AM: Using colorator 1.1.0
1:14:50 AM: Using concurrent-ruby 1.2.2
1:14:50 AM: Using http_parser.rb 0.8.0
1:14:50 AM: Using liquid 4.0.4
1:14:50 AM: Using rouge 4.1.0
1:14:50 AM: Using pathutil 0.16.2
1:14:50 AM: Using rb-inotify 0.10.1
1:14:50 AM: Using sass-embedded 1.59.3 (x86_64-linux-gnu)
1:14:50 AM: Using kramdown 2.4.0
1:14:50 AM: Using kramdown-parser-gfm 1.1.0
1:14:50 AM: Using jekyll-tagging 1.1.0
1:14:50 AM: Using addressable 2.8.1
1:14:50 AM: Using i18n 1.12.0
1:14:50 AM: Using jekyll-sass-converter 3.0.0
1:14:50 AM: Using listen 3.8.0
1:14:50 AM: Using terminal-table 3.0.2
1:14:50 AM: Using liquid-c 4.0.1
1:14:50 AM: Using em-websocket 0.5.3
1:14:50 AM: Using jekyll-watch 2.2.1
1:14:50 AM: Using jekyll 4.3.2
1:14:50 AM: Using jekyll-include-cache 0.2.1
1:14:50 AM: Using jekyll-seo-tag 2.8.0
1:14:50 AM: Using jekyll-sitemap 1.4.0
1:14:50 AM: Bundle complete! 12 Gemfile dependencies, 37 gems now installed.
1:14:50 AM: Bundled gems are installed into `/opt/build/cache/bundle`
1:14:50 AM: Gem bundle installed
1:14:50 AM: Started restoring cached go cache
1:14:50 AM: Finished restoring cached go cache
1:14:50 AM: Installing Go version 1.19.5 (requested 1.19.5)
1:14:55 AM: go version go1.19.5 linux/amd64
1:14:55 AM: go version go1.19.5 linux/amd64
1:14:55 AM: go version go1.19.5 linux/amd64
1:14:56 AM: Started restoring cached Node.js version
1:14:57 AM: Finished restoring cached Node.js version
1:14:57 AM: v12.18.0 is already installed.
1:14:57 AM: Now using node v12.18.0 (npm v6.14.4)
1:14:57 AM: Started restoring cached build plugins
1:14:57 AM: Finished restoring cached build plugins
1:14:57 AM: go version go1.19.5 linux/amd64
1:14:58 AM: go version go1.19.5 linux/amd64
1:14:58 AM: go version go1.19.5 linux/amd64
1:14:58 AM: Using PHP version 8.0
1:14:58 AM: go version go1.19.5 linux/amd64
1:14:58 AM: Install dependencies script success
1:14:58 AM: Starting build script
1:14:58 AM: Using stage install dependencies
1:14:58 AM: go version go1.19.5 linux/amd64
1:14:59 AM: Detected 1 framework(s)
1:14:59 AM: "jekyll" at version "unknown"
1:14:59 AM: Section completed: initializing
1:15:00 AM: ​
1:15:00 AM:   Netlify Build                                                 
1:15:00 AM: ────────────────────────────────────────────────────────────────
1:15:00 AM: ​
1:15:00 AM: ❯ Version
1:15:00 AM:   @netlify/build 29.7.0
1:15:00 AM: ​
1:15:00 AM: ❯ Flags
1:15:00 AM:   baseRelDir: true
1:15:00 AM:   buildId: 641904f0e19c150008617c88
1:15:00 AM:   deployId: 641904f0e19c150008617c8a
1:15:00 AM: ​
1:15:00 AM: ❯ Current directory
1:15:00 AM:   /opt/build/repo
1:15:00 AM: ​
1:15:00 AM: ❯ Config file
1:15:00 AM:   No config file was defined: using default values.
1:15:00 AM: ​
1:15:00 AM: ❯ Context
1:15:00 AM:   production
1:15:01 AM: ​
1:15:01 AM: ❯ Loading plugins
1:15:01 AM:    - netlify-plugin-jekyll-cache@1.0.0 from Netlify app
1:15:02 AM: ​
1:15:02 AM:   1. netlify-plugin-jekyll-cache (onPreBuild event)             
1:15:02 AM: ────────────────────────────────────────────────────────────────
1:15:02 AM: ​
1:15:03 AM: Restoring Jekyll cache
1:15:03 AM: ​
1:15:03 AM: (netlify-plugin-jekyll-cache onPreBuild completed in 939ms)
1:15:03 AM: ​
1:15:03 AM:   2. Build command from Netlify app                             
1:15:03 AM: ────────────────────────────────────────────────────────────────
1:15:03 AM: ​
1:15:03 AM: $ bundle exec jekyll build
1:15:03 AM: Configuration file: /opt/build/repo/_config.yml
1:15:03 AM:             Source: /opt/build/repo
1:15:03 AM:        Destination: /opt/build/repo/_site
1:15:03 AM:  Incremental build: disabled. Enable with --incremental
1:15:03 AM:       Generating...
1:15:12 AM:                     done in 8.613 seconds.
1:15:12 AM:  Auto-regeneration: disabled. Use --watch to enable.
1:15:12 AM: ​
1:15:12 AM: (build.command completed in 9.1s)
1:15:12 AM: ​
1:15:12 AM:   3. netlify-plugin-jekyll-cache (onPostBuild event)            
1:15:12 AM: ────────────────────────────────────────────────────────────────
1:15:12 AM: ​
1:15:13 AM: Jekyll cache stored
1:15:13 AM: ​
1:15:13 AM: (netlify-plugin-jekyll-cache onPostBuild completed in 850ms)
1:15:13 AM: ​
1:15:13 AM:   4. Deploy site                                                
1:15:13 AM: ────────────────────────────────────────────────────────────────
1:15:13 AM: ​
1:15:13 AM: Starting to deploy site from '_site'
1:15:13 AM: Calculating files to upload
1:15:15 AM: 1 new files to upload
1:15:15 AM: 0 new functions to upload
1:15:15 AM: Section completed: deploying
1:15:15 AM: Site deploy was successfully initiated
1:15:15 AM: ​
1:15:15 AM: (Deploy site completed in 2.5s)
1:15:15 AM: Starting post processing
1:15:15 AM: ​
1:15:15 AM:   Netlify Build Complete                                        
1:15:15 AM: ────────────────────────────────────────────────────────────────
1:15:16 AM: Post processing - HTML
1:15:15 AM: ​
1:15:15 AM: (Netlify Build completed in 14.9s)
1:15:16 AM: Caching artifacts
1:15:16 AM: Started saving ruby gems
1:15:16 AM: Finished saving ruby gems
1:15:16 AM: Started saving build plugins
1:15:16 AM: Finished saving build plugins
1:15:16 AM: Started saving pip cache
1:15:16 AM: Finished saving pip cache
1:15:16 AM: Started saving emacs cask dependencies
1:15:16 AM: Finished saving emacs cask dependencies
1:15:16 AM: Started saving maven dependencies
1:15:16 AM: Finished saving maven dependencies
1:15:16 AM: Started saving boot dependencies
1:15:16 AM: Finished saving boot dependencies
1:15:16 AM: Started saving rust rustup cache
1:15:16 AM: Finished saving rust rustup cache
1:15:16 AM: Started saving go dependencies
1:15:16 AM: Finished saving go dependencies
1:15:17 AM: Build script success
1:15:17 AM: Section completed: building
1:15:17 AM: Post processing - header rules
1:15:17 AM: Post processing - redirect rules
1:15:18 AM: Post processing done
1:15:18 AM: Section completed: postprocessing
1:15:18 AM: Uploading Cache of size 284.3MB
1:15:18 AM: Site is live ✨
1:15:20 AM: Section completed: cleanup
1:15:20 AM: Finished processing build request in 52.133s
1 Like

As far as I know, we don’t try to cache versions of ruby that were not preinstalled, but I’ve asked our builds team if my understanding is correct.

Thanks for your patience - seems like a bug, so we’ve gotten it filed. I don’t have any commitment nor timeline to fix it since this isn’t blocking your work, but the team was interested to hear it and hope to fix it someday.

1 Like

Thanks! Always nice to know I’m not going crazy.

I appreciate that fixing such a problem that will reduce the amount of minutes people are spending at Netlify will impact your bottom line. Hopefully you will do the right thing!

Hello the community :wave:,

Do we have any news on this one ?

It seems it is still an issue.
Following log suggests Ruby 3.0 is downloaded and installed, in every build I make:

4:36:50 PM: Attempting Ruby version 3.0, read from environment
4:36:50 PM: Required ruby-3.0.0 is not installed - installing.
4:36:50 PM: Searching for binary rubies, this might take some time.
4:36:50 PM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-3.0.0.tar.bz2
4:36:50 PM: Checking requirements for ubuntu.
4:36:51 PM: Requirements installation successful.
4:36:51 PM: ruby-3.0.0 - #configure
4:36:51 PM: ruby-3.0.0 - #download
4:36:51 PM: Downloaded archive checksum did not match, archive was removed!
4:36:51 PM: If you wish to continue with not matching download add "--verify-downloads 2" after the command.
4:36:51 PM: Downloading https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-3.0.0.tar.bz2 failed.
4:36:51 PM: Mounting remote ruby failed with status 2, trying to compile.
4:36:51 PM: Checking requirements for ubuntu.
4:36:51 PM: Requirements installation successful.
4:36:51 PM: Installing Ruby from source to: /opt/buildhome/.rvm/rubies/ruby-3.0.0, this may take a while depending on your cpu(s)...
4:36:51 PM: ruby-3.0.0 - #downloading ruby-3.0.0, this may take a while depending on your connection...
4:36:52 PM: ruby-3.0.0 - #extracting ruby-3.0.0 to /opt/buildhome/.rvm/src/ruby-3.0.0.....
4:37:14 PM: ruby-3.0.0 - #configuring.........................................................................
4:37:14 PM: ruby-3.0.0 - #post-configuration..
4:38:46 PM: ruby-3.0.0 - #compiling..........................................................................................
4:38:48 PM: ruby-3.0.0 - #installing.....................
4:38:48 PM: ruby-3.0.0 - #making binaries executable...
4:38:49 PM: Installed rubygems 3.2.3 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
4:38:49 PM: ruby-3.0.0 - #gemset created /opt/buildhome/.rvm/gems/ruby-3.0.0@global
4:38:50 PM: ruby-3.0.0 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems......................................................................
4:38:51 PM: ruby-3.0.0 - #generating global wrappers........
4:38:51 PM: ruby-3.0.0 - #gemset created /opt/buildhome/.rvm/gems/ruby-3.0.0
4:38:51 PM: ruby-3.0.0 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
4:38:51 PM: ruby-3.0.0 - #generating default wrappers........
4:38:51 PM: ruby-3.0.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
4:38:51 PM: Install of ruby-3.0.0 - #complete
4:38:51 PM: Ruby was built without documentation, to build it run: rvm docs generate-ri
4:38:51 PM: Using /opt/buildhome/.rvm/gems/ruby-3.0.0
4:38:52 PM: Using Ruby version 3.0.0

BR

Okay before writing the message I had already tried to clear cache and waited… but not long enough apparently. Everything seems to work well.
Sorry for inconvenience.
Have a nice day !