Rails getting started guide - Gem not found error during `RUN bin/rails fly:build`

Hello, I tried following the Fly.io Rails Getting Started Guide, and trying a couple of fresh times I got the following error:

% fly deploy
==> Verifying app config
--> Verified app config
==> Building image
Remote builder [builder] ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon  22.04kB
[+] Building 28.8s (20/20) FINISHED
 => [internal] load remote build context                                                                                                 0.0s
 => copy /context /                                                                                                                      0.0s
 => resolve image config for docker.io/docker/dockerfile:experimental                                                                    0.2s
 => CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496  0.0s
 => [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:3.1.2-jemalloc-slim                                                        0.1s
 => [base 1/4] FROM quay.io/evl.ms/fullstaq-ruby:3.1.2-jemalloc-slim@sha256:3faf649a9f30b694f38fefe0b4f1b4b28cefae604530a7cfe989f04db26  0.0s
 => CACHED [base 2/4] RUN mkdir /app                                                                                                     0.0s
 => CACHED [base 3/4] WORKDIR /app                                                                                                       0.0s
 => CACHED [base 4/4] RUN mkdir -p tmp/pids                                                                                              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-  0.0s
 => CACHED [gems 1/3] RUN gem update --system --no-document &&     gem install -N bundler -v 2.3.19                                      0.0s
 => [gems 2/3] COPY Gemfile* ./                                                                                                          0.0s
 => [gems 3/3] RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache                                                                 25.7s
 => CACHED [stage-3 1/7] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=prod-a  0.0s
 => [stage-3 2/7] COPY --from=gems /app /app                                                                                             0.5s
 => [stage-3 3/7] COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions                                       0.4s
 => [stage-3 4/7] COPY --from=gems /usr/local/bundle /usr/local/bundle                                                                   0.1s
 => [stage-3 5/7] COPY . .                                                                                                               0.0s
 => [stage-3 6/7] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe/ruby/' /app/bin/* &&     sed -i '/^#!/aDir.chdir File.expand_path("  0.3s
 => ERROR [stage-3 7/7] RUN bin/rails fly:build                                                                                          0.5s
------
 > [stage-3 7/7] RUN bin/rails fly:build:
#20 0.520 /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/resolver.rb:271:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'debug' in locally installed gems. (Bundler::GemNotFound)
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/resolver.rb:254:in `map!'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/resolver.rb:254:in `verify_gemfile_dependencies_are_found!'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/resolver.rb:49:in `start'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/resolver.rb:24:in `resolve'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/definition.rb:480:in `reresolve'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/definition.rb:283:in `resolve'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/definition.rb:488:in `materialize'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/definition.rb:191:in `specs'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/definition.rb:247:in `specs_for'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/runtime.rb:18:in `setup'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler.rb:163:in `setup'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/setup.rb:20:in `block in <top (required)>'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/ui/shell.rb:136:in `with_level'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/ui/shell.rb:88:in `silence'
#20 0.520 	from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/setup.rb:20:in `<top (required)>'
#20 0.520 	from <internal:/usr/lib/fullstaq-ruby/versions/3.1.2-jemalloc/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
#20 0.520 	from <internal:/usr/lib/fullstaq-ruby/versions/3.1.2-jemalloc/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
#20 0.520 	from /app/config/boot.rb:3:in `<top (required)>'
#20 0.520 	from bin/rails:4:in `require_relative'
#20 0.520 	from bin/rails:4: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

Assuming it’s something to do with dev vs. prod gem environments, but not sure what to try next. Wondering what might be off about my following of the guide / local environment if anything.

Something to do with the ARG BUNDLE_WITHOUT=development:test in the Dockerfile?

Possibly related issues making it through the guide: basic rails app fails to deploy - #37 by Tunde

Possibly related: ruby on rails - Rake Assets Precompile without Gems in Development or Test Groups - Stack Overflow

Are you following the guide (creating a new application and making a one line change) or providing your own application?

If you are following the guide, what version of Ruby and Rails are you using? And what OS?

If you are providing your own application, can you share the relevant parts of your Gemfile?

Hmm… I was running into the same error.

In theory, that line inside the Dockerfile should make it IGNORE development and test Gem groups, but I had to remove it in order to successfully deploy.

What gives?

I’m not seeing it with the application in the guide. I’m using Rails 7.0.4 on MacOS.

Are you seeing it with the application in the guide? If so, what version of Rails and what OS are you on?

If not, can you share the relevant portions of your Gemfile?