Introduction
If you’ve been following the Rails upgrade path over the years you already know that each new Rails release can bring both powerful enhancements and unexpected hurdles (and headaches). In this quick post we’ll tackle upgrading from Rails 7.1 to Rails 7.2, where an ActiveStorage + S3 issue can derail your build process - especially when you’re precompiling assets in Docker.
Read on to discover exactly why these errors occur and how to sidestep them with a clever workaround we came up with here at WebVolta before we are able to update to Rails 8.x when time and energy permits.
Whether your application is mission-critical or just on the cusp of the next version jump, these insights should help you maintain a smooth deployment pipeline and keep your Rails environment in peak condition.
Fixing an ActiveStorage + S3 Issue After Upgrading to Rails 7.2 in Docker
We recently upgraded an app from Rails 7.1 to 7.2 and ran into an unexpected issue when precompiling assets as part of a Docker production build.
The Problem
During assets:precompile, I hit the following errors:
ArgumentError (missing required option :name)
and
Aws::Errors::MissingRegionError: No region was provided.
Digging into the backtrace, I found that the problem stemmed from ActiveStorage::Blob being loaded too early—before the AWS region was configured. This change appears to have been introduced in Rails 7.2 and isfixed in Rails 8.x.
The Workaround
Until we can fully upgrade to Rails 8.x, we implemented a workaround by conditionally setting ActiveStorage to use local disk storage during the precompile phase.
Step 1: Modify the Dockerfile
Change the RUN command for precompiling assets:
Before:
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
After:
RUN PRECOMPILE_ASSETS=true SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
Step 2: Modify config/environments/production.rb
Modify the ActiveStorage service configuration to use local disk storage only when precompiling assets:
if ENV.fetch('PRECOMPILE_ASSETS', nil) =~ /true/i
puts "Using local disk for ActiveStorage in production."
config.active_storage.service = :test
else
puts "Using Amazon S3 for ActiveStorage in production."
config.active_storage.service = :amazon
end
This ensures that ActiveStorage avoids initializing AWS during the precompile step.
The Result
With this change, assets precompile successfully, and ActiveStorage switches back to S3 once the app is running.
Cleaning Up
This workaround is temporary and can be removed once I upgrade to Rails 8.x, where the issue has been addressed.
Hope this saves you a little time, and if you have any questions or need help with your own Rails project, feel free to reach out to us at https://www.webvolta.com/contact.