You know that feeling when your CI/CD pipeline is supposed to "just work"—but instead, it throws cryptic errors, and you're left scratching your head? Yeah, that was me last week.
I was setting up CircleCI for a Ruby on Rails project, and everything was running smoothly… until it wasn’t. Suddenly, my test suite failed with:
🚨 ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime
🔑 GPG error: NO_PUBKEY 32EE5355A6BC6E42
At first, I thought, "No big deal, just install Node and update Chrome, right?" But nope—things got messier. The default CircleCI Ruby image lacked a JavaScript runtime, Chrome needed a new GPG key, and my pipeline was stuck in failure mode.
After a few hours (okay, maybe more) of debugging, I finally cracked the code. In this post, I’ll walk you through the exact problem, what didn’t work, and how I ultimately fixed my CircleCI config to make my Rails tests run smoothly again. Let’s dive in! 🔧✨
How I Fixed CircleCI’s Missing JavaScript Runtime & Chrome GPG Key Errors in My Rails Pipeline
When setting up CircleCI for a Ruby on Rails project, I ran into two annoying issues that completely broke my pipeline:
- ExecJS couldn’t find a JavaScript runtime (because the Ruby image didn’t include Node.js).
- Google Chrome’s GPG key had changed, causing apt-get update to fail with a NO_PUBKEY error.
If you’re dealing with a similar problem, don’t panic! I’ll walk you through how I fixed it, step by step.
The Problem: My Tests Started Failing in CircleCI
At first, my tests were running fine. But then, one day, I saw this error when running rake db:create in my CI logs:
ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime.
See https://github.com/rails/execjs for a list of available runtimes.
Then, while trying to install Chrome for my system tests, this lovely error showed up:
GPG error: https://dl.google.com/linux/chrome/deb stable InRelease:
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 32EE5355A6BC6E42
Without a JS runtime, Rails couldn’t compile assets. Without a valid GPG key, I couldn’t install Chrome.
Pipeline = Dead. 🚨
🔎 Step 1: Switch to a Ruby Image That Includes Node.js
Since ExecJS needs a JavaScript runtime, my first move was to use a Ruby image that comes with Node built-in. Instead of using:
docker:
- image: cimg/ruby:3.1.4
I switched to cimg/ruby:3.1.4-node, which includes both Ruby and Node.js:
docker:
- image: cimg/ruby:3.1.4-node
💡 Why? Because Rails uses ExecJS (via gems like autoprefixer-rails) to compile assets, and Node.js provides the runtime ExecJS expects.
Step 2: Fix the Google Chrome GPG Key Issue
Google recently rotated their signing key, which broke apt-get update for Chrome installations. To fix this, I manually added the updated key before running apt-get update:
- run:
name: Add Google Chrome public key
command: |
sudo apt-get update -y
sudo apt-get install -y wget
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
💡 Why? This allows apt-get to trust Google’s repo again, letting Chrome install without errors.
🛠Step 3: Install Chrome & Chromedriver for System Tests
Even though I was using the -node image (instead of -browsers), I still needed Chrome for feature/system tests. Instead of installing it manually, I used CircleCI’s browser-tools orb:
orbs:
browser-tools: circleci/browser-tools@1.5.0
Then, inside my test job (run_rspec), I installed both Chrome and Chromedriver:
- browser-tools/install-chrome
- browser-tools/install-chromedriver
💡 Why? This is a cleaner, more stable way to install Chrome compared to managing it manually with apt-get install google-chrome-stable.
Step 4: Run Tests with Everything in Place
Once I had:
✅ A JavaScript runtime (Node.js)
✅ A valid GPG key for Chrome
✅ Chrome & Chromedriver installed
My RSpec tests could finally run without breaking:
- run:
name: Run RSpec tests
command: |
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--color \
--out tmp/rspec/test-results/rspec.xml \
$TEST_FILES
🎉 Final Thoughts: No More CircleCI Headaches!
✅ Switching to cimg/ruby:3.1.4-node fixed the missing JavaScript runtime issue.
✅ Manually adding Google’s updated signing key solved the Chrome installation issue.
✅ Using the browser-tools orb made installing Chrome & Chromedriver much easier.
Now, my Rails CI/CD pipeline runs smoothly again, and I can actually focus on writing code instead of debugging CircleCI configs! 🚀
If you’re running into the same issues, try these fixes and let me know if they work for you! 💬
Top comments (0)