Heroku的 Ruby构建包在第二次部署时崩溃

前端开发 2026-07-12

我把Ruby从 Ruby 3.1.7升级到Ruby 3.2.8;之后,我遇到一种情况:在Heroku部署的服务器上首次部署时Ruby bundle能正常工作,但随后的所有部署在bundle install这一步都失败。这个问题在我尝试的两台服务器上都能重现。用多种方式清除缓存都没解决问题,回滚服务器也不能重新部署,带着新改动且清除了缓存的重新部署也没解决问题。问题在本地环境中不会出现,开发/测试环境之间只是多了capybara、pry、rubocop等测试模块。下面是部署推送时遇到的错误:

remote: -----> Using Ruby version: ruby-3.2.8
remote: -----> Installing bundler 2.3.5
remote: -----> Installing dependencies using bundler 2.3.5
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        Bundle complete! 59 Gemfile dependencies, 138 gems now installed.
remote:        Gems in the groups 'development' and 'test' were not installed.
remote:        Bundled gems are installed into `./vendor/bundle`
remote:        Bundle completed (0.41s)
remote:        Cleaning up the bundler cache.
remote:        Running: bundle list
remote:        Could not find mini_portile2-2.8.8 in any of the sources
remote:        Install missing gems with `bundle install`.
remote:
remote:  !
remote:  !     Error detecting dependencies
remote:  !
remote:  !     The Ruby buildpack requires information about your application’s dependencies to
remote:  !     complete the build. Without this information, the Ruby buildpack cannot continue.
remote:  !
remote:  !     Command failed: `bundle list`
remote:  !
remote:  !     Could not find mini_portile2-2.8.8 in any of the sources
remote:  !     Install missing gems with `bundle install`.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to [app name]

使用

  • Rails版本6.1.7.10
  • Node版本16.13.2
  • Heroku-22堆栈
  • Ruby版本3.2.8。

当运行 heroku releases:output -a [app name] 时,我们得到以下错误:

bundler: failed to load command: rake (/app/vendor/bundle/ruby/3.2.0/bin/rake) /app/vendor/ruby-3.2.8/lib/ruby/3.2.0/bundler/definition.rb:910:in `block in verify_changed_sources!': Could not find gem 'capybara' in locally installed gems (Bundler::GemNotFound)

我们对下一步的解决建议有什么吗?我有点束手无策。


Edit: 为了帮助排查,我把Gemfile放在底部。让我觉得有意思的一点是,前一次执行 heroku releases:output -a [app name] 时是在非开发服务器上,我们看到输出中提到了开发环境的gem capybara。当前正在关注这个问题。

所使用的平台包括:

  • Bundler v2.3.5(在早期排错过程中从Bundler v2.1.4改为v2.3.5)
  • ruby 3.2.8p263

在Heroku服务器上运行 bundle platform 的结果为:

[DEPRECATED] Your lockfile contains a single rubygems source section with multiple remotes, which is insecure. Make sure you run `bundle install` in non frozen mode and commit the result to make your lockfile secure.
Your app has gems that work on these platforms:
* ruby
Your Gemfile specifies a Ruby version requirement:
* ruby 3.2.8
Your current platform satisfies the Ruby version requirement.

Gemfile在做了小幅修改后:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# TODO TEMP: Psych4 gem incompatible with Rails 6.1. Remove line after Rails 7.0.4+
gem 'psych', '< 4.0'
# TODO TEMP: keep concurrent-ruby to 1.3.4 until Rails 7.1
# https://stackoverflow.com/questions/79360526/uninitialized-constant-activesupportloggerthreadsafelevellogger-nameerror
gem 'concurrent-ruby', '1.3.4'

#dotenv recomends being the first gem included
gem 'dotenv-rails', groups: [:development, :test] # application environment vars

# RAILS DEFAULTS

gem 'rails', '~> 6.1.7.10'         # Provides rails framework
gem 'pg', '~> 1.2'              # Use postgres with Active Record
gem 'puma', '>= 5.6.4'            # Use Puma as the app server
gem 'sass-rails', '>= 6'      # Use SCSS for stylesheets
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
gem 'jquery-rails', '>=4.3.4'   # Use jquery as the Javascript library
gem 'turbo-rails'               # Hotwire's SPA-like page accelerator, to replace the old turbolink
gem 'redis', '~> 4.5'           # In memory datastore, required by actioncable
                                # and sidekiq
# Use Active Storage variant
gem "spring", group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.7.5', require: false
# bootsnap requires this, but from ruby 2.7, this is no longer bundled with ruby
# it's likely an issue fixed for higher rails version,
# but for now we need to add it manually
# https://github.com/ruby/ruby/blob/v2_7_0_preview2/NEWS#compatibility-issues-excluding-feature-bug-fixes-
gem 'scanf'
# as of ruby 3.0, rexml is no longer a default gem for ruby, and since it's used by simplecov and webdriver
gem 'rexml'

# CUSTOM GEMS (omitted, very few in numbers)

# OUR FAVORITE GEMS

gem 'devise'                      # User authentication
gem 'devise-security'             # Additional security options
gem 'pundit'                      # Controller action permissions
gem 'will_paginate'               # Simple pagination helpers
gem "sidekiq", '<7'               # Enables ActiveJob
gem 'sinatra', require: false     # dependency of sidekiqs web console
gem 'paperclip'                   # file attachments to models
gem 'aws-sdk-s3'                  # s3 file storage
gem 'aws-sdk-states'              # aws step functions
gem 'scout_apm'                   # performance monitor
gem 'pgsync'                      # sync data across postgres dbs https://github.com/ankane/pgsync

# FRONTEND

gem 'font_awesome5_rails'         # Loads of icons
gem 'd3-rails'                    # d3 for info visualization
gem 'rubyXL'                      # parse a template and modify .xlsx file
gem 'gradient'                    # color gradient in ruby https://github.com/zeeraw/gradient
gem "view_component", '~> 3.0.0'  # using ViewComponent for reusable frontend elements

# APP SPECIFIC

gem 'oj'                          # Better json parser
gem 'sidekiq-scheduler', '<5'     # schedule cron-like jobs with sidekiq https://github.com/moove-it/sidekiq-scheduler
gem 'fugit'                       # cron expression parser

group :production do
  # For mail on heroku
  gem 'postmark-rails', '>= 0.10.0'
end

group :development, :test do
  gem 'pry-byebug'                          # Debugging console
  gem 'simplecov'                           # Code coverage for tests
  gem 'simplecov-cobertura', require: false # Code coverage report
  gem 'capybara', '~> 3.35'                 # integration testing tool
  gem 'selenium-webdriver', '~> 4.11'       # manages test browser
  gem 'database_cleaner'                    # Used by Datum::Transactions module
  gem 'minitest-retry'                      # For retrying flaky system tests
end

group :development do
  gem 'listen', '~> 3.5.1'        # Dependency of spring
  gem 'memory_profiler'           # For memory profiling
  gem 'rack-mini-profiler'        # in app profiler
  gem 'rubocop', '~>1.37.1', require: false
  gem 'rubocop-minitest', '~> 0.13.0'
  gem 'rubocop-rails'
  gem 'rubocop-performance'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

# security checks
gem 'brakeman'

# Reek code smelling
gem 'reek'

# sentry for exception reporting
gem "sentry-ruby"
## integrations for sentry
gem "sentry-rails"
gem "sentry-sidekiq"

# Contributed System credential for paid GEMs
source "https://gems.contribsys.com/" do
  gem 'sidekiq-pro'                        # advanced sidekiq package
end

ruby "3.2.8"

解决方案

你的问题似乎是

Could not find mini_portile2-2.8.8 in any of the sources

我猜是在你的应用中某处使用了它,或作为一个依赖,但它只在开发或测试环境中被包含,因此Heroku没有安装它。你能也贴出Gemfile.lock吗?

Heroku在运行bundle install之后又要执行“bundle list”,但该命令失败了。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章