Rails 6 "fly deploy" fails with "gem not found"

fly deplpy output:

--> Verified app config
==> Building image
Remote builder fly-builder-morning-paper-1021 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 2.9s (0/1)                                                                                                                              
[+] Building 1.3s (26/26) FINISHED                                                                                                                   
 => [internal] load remote build context                                                                                                        0.0s
 => copy /context /                                                                                                                             0.2s
 => resolve image config for docker.io/docker/dockerfile:experimental                                                                           0.2s
 => CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5      0.0s
 => [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:3.0.2-jemalloc-slim                                                               0.1s
 => [base 1/6] FROM quay.io/evl.ms/fullstaq-ruby:3.0.2-jemalloc-slim@sha256:a3cffbcdadc3bf81ebec5a9fe283d0bebb4cb7a950dc2fb574876e22c1896fbc    0.0s
 => CACHED [base 2/6] RUN mkdir /app                                                                                                            0.0s
 => CACHED [base 3/6] WORKDIR /app                                                                                                              0.0s
 => CACHED [base 4/6] RUN mkdir -p tmp/pids                                                                                                     0.0s
 => CACHED [base 5/6] RUN curl https://get.volta.sh | bash                                                                                      0.0s
 => CACHED [base 6/6] RUN volta install node@10.19.0 yarn                                                                                       0.0s
 => CACHED [stage-4 1/8] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=prod-apt-lib,  0.0s
 => CACHED [build_deps 1/1] RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=dev-apt-lib  0.0s
 => CACHED [gems 1/3] RUN gem update --system --no-document &&     gem install -N bundler -v 2.2.22                                             0.0s
 => CACHED [gems 2/3] COPY Gemfile* ./                                                                                                          0.0s
 => CACHED [gems 3/3] RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache                                                                  0.0s
 => CACHED [stage-4 2/8] COPY --from=gems /app /app                                                                                             0.0s
 => CACHED [stage-4 3/8] COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions                                       0.0s
 => CACHED [stage-4 4/8] COPY --from=gems /usr/local/bundle /usr/local/bundle                                                                   0.0s
 => CACHED [node_modules 1/3] COPY package*json ./                                                                                              0.0s
 => CACHED [node_modules 2/3] COPY yarn.* ./                                                                                                    0.0s
 => CACHED [node_modules 3/3] RUN yarn install                                                                                                  0.0s
 => CACHED [stage-4 5/8] COPY --from=node_modules /app/node_modules /app/node_modules                                                           0.0s
 => CACHED [stage-4 6/8] COPY . .                                                                                                               0.0s
 => CACHED [stage-4 7/8] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe/ruby/' /app/bin/* &&     sed -i '/^#!/aDir.chdir File.expand_path("  0.0s
 => ERROR [stage-4 8/8] RUN bin/rails fly:build                                                                                                 0.6s
------
 > [stage-4 8/8] RUN bin/rails fly:build:
#26 0.591 /usr/lib/fullstaq-ruby/versions/3.0.2-jemalloc/lib/ruby/site_ruby/3.0.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'spring' (= 4.1.0) among 173 total gem(s) (Gem::MissingSpecError)
#26 0.591 Checked in 'GEM_PATH=/app/vendor/bundle/ruby/3.0.0:/root/.local/share/gem/ruby/3.0.0:/usr/lib/fullstaq-ruby/versions/3.0.2-jemalloc/lib/ruby/gems/3.0.0:/usr/local/bundle' , execute `gem env` for more information
#26 0.592 	from /usr/lib/fullstaq-ruby/versions/3.0.2-jemalloc/lib/ruby/site_ruby/3.0.0/rubygems/dependency.rb:323:in `to_spec'
#26 0.592 	from /usr/lib/fullstaq-ruby/versions/3.0.2-jemalloc/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
#26 0.592 	from /app/bin/spring:15:in `<top (required)>'
#26 0.592 	from bin/rails:8:in `load'
#26 0.592 	from bin/rails:8:in `<main>'
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/bash -o pipefail -c ${BUILD_COMMAND}]: exit code: 1

Gemfile:

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

ruby '3.0.2'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem "font-awesome-rails"

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'stimulus-rails'
gem 'turbo-rails'
gem 'pdf-reader'
gem 'sidekiq'
gem 'phaxio'
gem 'uri'
gem 'net-http'
gem 'http'
gem 'paypal-checkout-sdk'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'mocha'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
  gem 'vcr'
  gem 'webmock'
end

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

I tried reproducing with your Gemfile, but I’m not seeing the problem here.

  • Spring is a development time preloader - it shouldn’t be needed in production
  • In your gemfile, spring is inside a “group :development” block
  • The Dockerfile that we produce for you has ARG BUNDLE_WITHOUT=development:test

So while spring should not be needed for production, and I’m not seeing the problem here, two things come to mind for you to try:

  • Move spring outside of the “group :development” block in your Gemfile
  • Either remove development, from the BUNDLE_WITHOUT line in your Gemfile or remove that line entirely.
  • Remove spring entirely from your Gemfile. It is optional, and is dropped in Rails 7.

Removed the spring gem, thanks!