Error migrating app from Heroku: "bundler: command not found: rails"

Background

I’m following the Migrate from Heroku documentation and successfully ran the fly launch command.

On Heroku, I ran the app without using Docker (in case that’s useful information).

fly launch generated a fly.toml, .dockerignore and Dockerfile for me.

Error Message

The next step was to run fly deploy which ultimately ends with this error message:

 > [stage-4 5/5] RUN bundle exec rails assets:precompile:                                                                                                                                                                                     
#23 0.417 bundler: command not found: rails
#23 0.417 Install missing gem executables with `bundle install`

Dockerfile

# syntax = docker/dockerfile:experimental
ARG RUBY_VERSION=3.1.1
ARG VARIANT=jemalloc-slim
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base

ARG NODE_VERSION=16
ARG BUNDLER_VERSION=2.3.7

ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV}

ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true

ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_PATH=vendor/bundle
ENV BUNDLE_PATH ${BUNDLE_PATH}
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}

RUN mkdir /app
WORKDIR /app
RUN mkdir -p tmp/pids

SHELL ["/bin/bash", "-c"]

RUN curl https://get.volta.sh | bash

ENV BASH_ENV ~/.bashrc
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:/usr/local/bin:$PATH

RUN volta install node@${NODE_VERSION} && volta install yarn

FROM base as build_deps

ARG DEV_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
ENV DEV_PACKAGES ${DEV_PACKAGES}

RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y ${DEV_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

FROM build_deps as gems

RUN gem install -N bundler -v ${BUNDLER_VERSION}

COPY Gemfile* ./
RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache

FROM build_deps as node_modules

COPY package*json ./
COPY yarn.* ./

RUN if [ -f "yarn.lock" ]; then \
    yarn install; \
    elif [ -f "package-lock.json" ]; then \
    npm install; \
    else \
    mkdir node_modules; \
    fi

FROM base

ARG PROD_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0"
ENV PROD_PACKAGES=${PROD_PACKAGES}

RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y \
    ${PROD_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

COPY --from=gems /app /app
COPY --from=node_modules /app/node_modules /app/node_modules

ENV SECRET_KEY_BASE 1

COPY . .

RUN bundle exec rails assets:precompile

ENV PORT 8080

ARG SERVER_COMMAND="bundle exec puma"
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

fly.toml

# fly.toml file generated for daily-iroh on 2022-09-03T20:37:43-04:00

app = "daily-iroh"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  [build.args]
    BUNDLER_VERSION = "2.0.2"
    NODE_VERSION = "14"
    RUBY_VERSION = "3.1.1"

[deploy]
  release_command = "bundle exec rails db:migrate"

[env]
  PORT = "8080"
  SERVER_COMMAND = "bundle exec puma"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[statics]]
  guest_path = "/app/public"
  url_prefix = "/"

What I’ve tried

I tried:

  • deploying normally with: fly deploy
  • deploying without cache: fly deploy --no-cache
  • sshing in with fly ssh console and got this error: Error host unavailable: host was not found in DNS
  • Searching community.fly.io for a similar error message (couldn’t find anything related)

This is the first app I’m trying to deploy and migrate over to fly.io and it’s a toy app I have. I’m starting with this one so I can learn the process and then move my more complicated apps over from Heroku afterwards.

Any help would be appreciated!

did you change the ruby version in the docker file?

This is an odd question, but is this app a Rails app? Can we see your Gemfile?

I ask because bundle install is in your Dockerfile (around line 50), yet rails isn’t installed when you run rails assets:precompile (around line 84).

Looking at your output, you are not running the latest flyctl. I suggest updating it, removing the Dockerfile, .dockerignore, and fly.toml files and trying again. You should now have a lib/tasks/fly.toml file too.

Starting with a toy app is a good idea, I recommend you run through Getting Started · Fly Docs first, particularly if you have problems.

Yes I did.

When I ran the initial fly launch command, it’s output said:

Your Rails app is prepared for deployment. Production will be set up with these versions of core runtime packages:

Ruby 3.1.1
Bundler 2.0.2
NodeJS 14

You can configure these in the [build] section in the generated fly.toml.

Ruby versions available are: 3.1.1, 3.0.3, 2.7.5, and 2.6.9. Learn more about the chosen Ruby stack, Fullstaq Ruby, here: https://github.com/evilmartians/fullstaq-ruby-docker.
We recommend using the highest patch level for better security and performance.

This is what the original Dockerfile looked like before my edits:

ARG RUBY_VERSION=2.7.3
ARG VARIANT=jemalloc-slim
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base

ARG NODE_VERSION=16
ARG BUNDLER_VERSION=2.3.9

ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV}

ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true

ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_PATH=vendor/bundle
ENV BUNDLE_PATH ${BUNDLE_PATH}
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}

RUN mkdir /app
WORKDIR /app
RUN mkdir -p tmp/pids

SHELL ["/bin/bash", "-c"]

RUN curl https://get.volta.sh | bash

ENV BASH_ENV ~/.bashrc
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:/usr/local/bin:$PATH

RUN volta install node@${NODE_VERSION} && volta install yarn

FROM base as build_deps

ARG DEV_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
ENV DEV_PACKAGES ${DEV_PACKAGES}

RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y ${DEV_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

FROM build_deps as gems

RUN gem install -N bundler -v ${BUNDLER_VERSION}

COPY Gemfile* ./
RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache

FROM build_deps as node_modules

COPY package*json ./
COPY yarn.* ./

RUN if [ -f "yarn.lock" ]; then \
    yarn install; \
    elif [ -f "package-lock.json" ]; then \
    npm install; \
    else \
    mkdir node_modules; \
    fi

FROM base

ARG PROD_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0"
ENV PROD_PACKAGES=${PROD_PACKAGES}

RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y \
    ${PROD_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

COPY --from=gems /app /app
COPY --from=node_modules /app/node_modules /app/node_modules

ENV SECRET_KEY_BASE 1

COPY . .

RUN bundle exec rails assets:precompile

ENV PORT 8080

ARG SERVER_COMMAND="bundle exec puma"
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

Note the RUBY_VERSION and BUNDLER_VERSION variables I updated to match what was in the fly.toml file.

Was that a mistake? Should I revert them?

Yes this is a Rails app.

Since the output from fly launch said they do not support Ruby 2.5.1, I updated my Gemfile to use 3.1.1.

Original Gemfile

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

ruby '2.5.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.4', '>= 5.2.4.1'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# 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.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', 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', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end


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


gem 'pry-rails'
gem 'dotenv-rails', groups: [:development, :test]
gem 'rack-cors'
gem 'slack-ruby-client'
gem 'faraday'

Updated Ruby Version in Gemfile

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

ruby '3.1.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.4', '>= 5.2.4.1'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# 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.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', 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', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end


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


gem 'pry-rails'
gem 'dotenv-rails', groups: [:development, :test]
gem 'rack-cors'
gem 'slack-ruby-client'
gem 'faraday'

Ah, rails 5 which I haven’t tested recently.

Rails for many releases now (and I checked, and this includes Rails 5) includes binstubs that can be used to reliably find the right version of Rails installed. Prior to release 0.0.384 of flyctl the Dockerfile and fly.toml files did not make use of these binstubs.

I encourage you to undo the launch, upgrade flyctl, and launch again.

To undo the launch, run fly apps destroy -y <name>, and remove your Dockerfile, .dockerignore, and fly.toml files. You likely have a database that can be destroyed the same way. Run fly apps list to see.

Upgrade flyctl to at least 0.0.384. This can be done via flyctl version update and verified using flyctl version.

Then run launch again. Verify that you have a libs/tasks/fly.rake file generated.

The changes you made to pick a more modern Ruby looks file. fly launch will pick that up and put it in your fly.toml file.

Again, it has been a while since I’ve looked at Rails 5, but you may also have a .ruby-version file that also will need to be updated.

Ok I followed your steps and destroyed all of my existing apps and generated files and re-ran fly launch followed by fly deploy and it still failed - but this time with a different error.

I noticed that fly launch generated a Dockerfile once again with the Ruby image set to 2.7.3.

Deploy log

==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-snowy-dew-9297 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.33kB
[+] Building 56.2s (23/23) FINISHED                                                                                                                                                                                                           
 => [internal] load remote build context                                                                                                                                                                                                 0.0s
 => copy /context /                                                                                                                                                                                                                      0.1s
 => resolve image config for docker.io/docker/dockerfile:experimental                                                                                                                                                                    0.5s
 => docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5                                                                                                      3.5s
 => => resolve docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5                                                                                                          0.0s
 => => sha256:d7f0373ffb1d5ac3477b10ab7f91cba7c5df586c72e7e4a12649024efdc0d531 9.64MB / 9.64MB                                                                                                                                           3.3s
 => => sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5 1.69kB / 1.69kB                                                                                                                                           0.0s
 => => sha256:3c244c0c6fc9d6aa3ddb73af4264b3a23597523ac553294218c13735a2c6cf79 528B / 528B                                                                                                                                               0.0s
 => => sha256:b587adb6abfd8d6c87b1f649c2e924d53f148ae1c7f0ceaaded70b27b44dccb5 1.21kB / 1.21kB                                                                                                                                           0.0s
 => => extracting sha256:d7f0373ffb1d5ac3477b10ab7f91cba7c5df586c72e7e4a12649024efdc0d531                                                                                                                                                0.2s
 => [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:3.1.1-jemalloc-slim                                                                                                                                                        0.5s
 => [base 1/6] FROM quay.io/evl.ms/fullstaq-ruby:3.1.1-jemalloc-slim@sha256:20d3c380783dd570b6258230425d6fa9f3d7b5891a18f738e3a1bf432ba71c9d                                                                                             2.4s
 => => resolve quay.io/evl.ms/fullstaq-ruby:3.1.1-jemalloc-slim@sha256:20d3c380783dd570b6258230425d6fa9f3d7b5891a18f738e3a1bf432ba71c9d                                                                                                  0.0s
 => => sha256:c229119241af7b23b121052a1cae4c03e0a477a72ea6a7f463ad7623ff8f274b 31.38MB / 31.38MB                                                                                                                                         0.5s
 => => sha256:ca28a8471987f7a474fa2868e936d86dd04616c905994a0b09360d8bd7fec369 18.18MB / 18.18MB                                                                                                                                         0.8s
 => => sha256:20d3c380783dd570b6258230425d6fa9f3d7b5891a18f738e3a1bf432ba71c9d 741B / 741B                                                                                                                                               0.0s
 => => sha256:9a738ffacc352376d7c14d15a588ca2ea7b8a85b0b775634dff0a8cfa71569c2 3.72kB / 3.72kB                                                                                                                                           0.0s
 => => extracting sha256:c229119241af7b23b121052a1cae4c03e0a477a72ea6a7f463ad7623ff8f274b                                                                                                                                                1.0s
 => => extracting sha256:ca28a8471987f7a474fa2868e936d86dd04616c905994a0b09360d8bd7fec369                                                                                                                                                0.7s
 => [base 2/6] RUN mkdir /app                                                                                                                                                                                                            0.4s
 => [base 3/6] WORKDIR /app                                                                                                                                                                                                              0.0s
 => [base 4/6] RUN mkdir -p tmp/pids                                                                                                                                                                                                     0.3s
 => [base 5/6] RUN curl https://get.volta.sh | bash                                                                                                                                                                                      2.7s
 => [base 6/6] RUN volta install node@18.1.0 && volta install yarn                                                                                                                                                                       3.7s
 => [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,sharing=locked,target=/var/lib/apt     apt-get update -qq &&     apt-get install --no-install-  15.3s 
 => [stage-4 1/5] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt     apt-get update -qq &&     apt-get install --no-install-re  6.6s 
 => [gems 1/3] RUN gem install -N bundler -v 2.3.7                                                                                                                                                                                       0.9s 
 => [node_modules 1/3] COPY package*json ./                                                                                                                                                                                              0.0s 
 => [node_modules 2/3] COPY yarn.* ./                                                                                                                                                                                                    0.0s 
 => [node_modules 3/3] RUN if [ -f "yarn.lock" ]; then     yarn install;     elif [ -f "package-lock.json" ]; then     npm install;     else     mkdir node_modules;     fi                                                              0.4s 
 => [gems 2/3] COPY Gemfile* ./                                                                                                                                                                                                          0.0s 
 => [gems 3/3] RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache                                                                                                                                                                 22.0s 
 => [stage-4 2/5] COPY --from=gems /app /app                                                                                                                                                                                             0.6s 
 => [stage-4 3/5] COPY --from=node_modules /app/node_modules /app/node_modules                                                                                                                                                           0.0s 
 => [stage-4 4/5] COPY . .                                                                                                                                                                                                               0.0s 
 => ERROR [stage-4 5/5] RUN bin/rails fly:build                                                                                                                                                                                          2.2s 
------                                                                                                                                                                                                                                        
 > [stage-4 5/5] RUN bin/rails fly:build:                                                                                                                                                                                                     
#23 2.127 rails aborted!                                                                                                                                                                                                                      
#23 2.127 ArgumentError: wrong number of arguments (given 3, expected 2)                                                                                                                                                                      
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/actionpack-5.2.8.1/lib/action_dispatch/middleware/static.rb:111:in `initialize'                                                                                                                  
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/actionpack-5.2.8.1/lib/action_dispatch/middleware/stack.rb:37:in `new'                                                                                                                           
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/actionpack-5.2.8.1/lib/action_dispatch/middleware/stack.rb:37:in `build'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/actionpack-5.2.8.1/lib/action_dispatch/middleware/stack.rb:101:in `block in build'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/actionpack-5.2.8.1/lib/action_dispatch/middleware/stack.rb:101:in `each'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/actionpack-5.2.8.1/lib/action_dispatch/middleware/stack.rb:101:in `inject'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/actionpack-5.2.8.1/lib/action_dispatch/middleware/stack.rb:101:in `build'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/engine.rb:510:in `block in app'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/engine.rb:506:in `synchronize'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/engine.rb:506:in `app'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:32:in `instance_exec'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:32:in `run'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:61:in `block in run_initializers'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:60:in `run_initializers'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/application.rb:361:in `initialize!'
#23 2.127 /app/config/environment.rb:5:in `<main>'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/application.rb:337:in `require_environment!'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/command.rb:48:in `invoke'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/railties-5.2.8.1/lib/rails/commands.rb:18:in `<main>'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#23 2.127 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#23 2.127 bin/rails:9:in `<main>'
#23 2.127 Tasks: TOP => environment
#23 2.128 (See full trace by running task with --trace)
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/bash -c bin/rails fly:build]: exit code: 1

OK, those changes worked, inasmuch as you are now actually running Rails.

It looks like Rails 5 isn’t compatible with Ruby 3. Perhaps try 2.7.6.

The ARG you see in the Dockerfile provides a default in case nothing is specified elsewhere. The toml file overrides this.

You can tell that you are running Ruby 3.1.x and Ruby 5.2.8 from the stack traceback.

You are not the first to see the symptoms above, here are the same symptoms on Stack Overflow: ruby - Getting "ArgumentError (wrong number of arguments (given 3, expected 2))" when running rails server - Stack Overflow

I ended up just upgrading to Rails 6.
Since this is just a toy app, I’m fine with that.
It doesn’t need active record/active storage/etc so I stripped all of that out as well.

Seems to get further in the deploy process now. It’s failing with the fly rake tasks because I don’t have any assets for it to compile or a server for it to run and have it listen for incoming requests. This used to be an app that would hit an API for me and post a message to slack once a day. I had the Heroku scheduler run a rake task which kicked off the entire thing scheduled at noon every day.

Do you know if something like that is possible with Fly? Got any docs that you can link I can read through?

Deploy Error Log

➜  daily-iroh git:(master) ✗ fly deploy
==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-throbbing-field-2662 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  27.39kB
[+] Building 59.9s (25/25) FINISHED                                                                                                                                                                                                           
 => [internal] load remote build context                                                                                                                                                                                                 0.0s
 => copy /context /                                                                                                                                                                                                                      0.1s
 => resolve image config for docker.io/docker/dockerfile:experimental                                                                                                                                                                    0.5s
 => docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5                                                                                                      0.3s
 => => resolve docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5                                                                                                          0.0s
 => => extracting sha256:d7f0373ffb1d5ac3477b10ab7f91cba7c5df586c72e7e4a12649024efdc0d531                                                                                                                                                0.2s
 => => sha256:3c244c0c6fc9d6aa3ddb73af4264b3a23597523ac553294218c13735a2c6cf79 528B / 528B                                                                                                                                               0.0s
 => => sha256:b587adb6abfd8d6c87b1f649c2e924d53f148ae1c7f0ceaaded70b27b44dccb5 1.21kB / 1.21kB                                                                                                                                           0.0s
 => => sha256:d7f0373ffb1d5ac3477b10ab7f91cba7c5df586c72e7e4a12649024efdc0d531 9.64MB / 9.64MB                                                                                                                                           0.1s
 => => sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5 1.69kB / 1.69kB                                                                                                                                           0.0s
 => [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:3.1.1-jemalloc-slim                                                                                                                                                        0.3s
 => [base 1/6] FROM quay.io/evl.ms/fullstaq-ruby:3.1.1-jemalloc-slim@sha256:20d3c380783dd570b6258230425d6fa9f3d7b5891a18f738e3a1bf432ba71c9d                                                                                             3.3s
 => => resolve quay.io/evl.ms/fullstaq-ruby:3.1.1-jemalloc-slim@sha256:20d3c380783dd570b6258230425d6fa9f3d7b5891a18f738e3a1bf432ba71c9d                                                                                                  0.0s
 => => sha256:20d3c380783dd570b6258230425d6fa9f3d7b5891a18f738e3a1bf432ba71c9d 741B / 741B                                                                                                                                               0.0s
 => => sha256:9a738ffacc352376d7c14d15a588ca2ea7b8a85b0b775634dff0a8cfa71569c2 3.72kB / 3.72kB                                                                                                                                           0.0s
 => => sha256:c229119241af7b23b121052a1cae4c03e0a477a72ea6a7f463ad7623ff8f274b 31.38MB / 31.38MB                                                                                                                                         1.0s
 => => sha256:ca28a8471987f7a474fa2868e936d86dd04616c905994a0b09360d8bd7fec369 18.18MB / 18.18MB                                                                                                                                         0.7s
 => => extracting sha256:c229119241af7b23b121052a1cae4c03e0a477a72ea6a7f463ad7623ff8f274b                                                                                                                                                1.4s
 => => extracting sha256:ca28a8471987f7a474fa2868e936d86dd04616c905994a0b09360d8bd7fec369                                                                                                                                                0.7s
 => [base 2/6] RUN mkdir /app                                                                                                                                                                                                            0.5s
 => [base 3/6] WORKDIR /app                                                                                                                                                                                                              0.0s
 => [base 4/6] RUN mkdir -p tmp/pids                                                                                                                                                                                                     0.3s
 => [base 5/6] RUN curl https://get.volta.sh | bash                                                                                                                                                                                      2.6s
 => [base 6/6] RUN volta install node@18.1.0 && volta install yarn                                                                                                                                                                       3.1s
 => [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,sharing=locked,target=/var/lib/apt     apt-get update -qq &&     apt-get install --no-install-  17.2s 
 => [stage-4 1/6] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt     apt-get update -qq &&     apt-get install --no-install-re  7.9s 
 => [gems 1/3] RUN gem install -N bundler -v 2.3.7                                                                                                                                                                                       1.5s 
 => [node_modules 1/3] COPY package*json ./                                                                                                                                                                                              0.0s 
 => [node_modules 2/3] COPY yarn.* ./                                                                                                                                                                                                    0.0s 
 => [node_modules 3/3] RUN if [ -f "yarn.lock" ]; then     yarn install;     elif [ -f "package-lock.json" ]; then     npm install;     else     mkdir node_modules;     fi                                                              0.5s 
 => [gems 2/3] COPY Gemfile* ./                                                                                                                                                                                                          0.0s 
 => [gems 3/3] RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache                                                                                                                                                                 24.5s 
 => [stage-4 2/6] COPY --from=gems /app /app                                                                                                                                                                                             0.7s 
 => [stage-4 3/6] COPY --from=node_modules /app/node_modules /app/node_modules                                                                                                                                                           0.0s 
 => [stage-4 4/6] COPY . .                                                                                                                                                                                                               0.0s 
 => [stage-4 5/6] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe/ruby/' /app/bin/* &&     sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*                                                                         0.3s 
 => [stage-4 6/6] RUN bin/rails fly:build                                                                                                                                                                                                2.0s 
 => exporting to image                                                                                                                                                                                                                   1.5s 
 => => exporting layers                                                                                                                                                                                                                  1.5s
 => => writing image sha256:d7fc8ca52a46848b0c0c8cb5f171cd122d3cc1c123c43cd4eb4aa2eb492323a7                                                                                                                                             0.0s
 => => naming to registry.fly.io/daily-iroh:deployment-01GCAP07RDXZPYV4VVC1VG7CJN                                                                                                                                                        0.0s
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/daily-iroh]
0228bc5fd4b3: Pushed 
0faa4a2ef521: Pushed 
209744e52a13: Pushed 
abc5df83e0cf: Pushed 
4a49d0f80855: Pushed 
8672d79fe4a7: Pushed 
abd99a65c9c8: Pushed 
c9bfcd325ab0: Pushed 
32d2d429dbcb: Pushed 
5f70bf18a086: Pushed 
065afbc3cfb4: Pushed 
2bff5884c8b6: Pushed 
608f3a074261: Pushed 
deployment-01GCAP07RDXZPYV4VVC1VG7CJN: digest: sha256:156badf67dc406c0bd21ff936eb4e956f247cd11bd5c4ee07ff8fd74e9ebe8de size: 3045
--> Pushing image done
image: registry.fly.io/daily-iroh:deployment-01GCAP07RDXZPYV4VVC1VG7CJN
image size: 547 MB
==> Creating release
--> release v2 created

--> You can detach the terminal anytime without stopping the deployment
==> Release command detected: bin/rails fly:release

--> This release will not be available until the release command succeeds.
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Configuring firecracker
	 Starting init (commit: 249766e)...
	 Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
	 no label, UUID=a2c5a5db-a877-45d5-90d3-b02e7b6d5555
	 2022/09/07 00:38:16 listening on [fdaa:0:95b4:a7b:2c00:51ae:d940:2]:22 (DNS: [fdaa::3]:53)
	 Rails version        6.1.6.1
	 Ruby version         ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) +jemalloc [x86_64-linux]
	 Rack version         2.2.4
	 JavaScript Runtime   Node.js (V8)
	 Environment          production
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Configuring firecracker
	 Starting virtual machine
	 Starting init (commit: 249766e)...
	 Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
	 no label, UUID=a2c5a5db-a877-45d5-90d3-b02e7b6d5555
	 Preparing to run: `bin/rails fly:release` as root
	 2022/09/07 00:38:16 listening on [fdaa:0:95b4:a7b:2c00:51ae:d940:2]:22 (DNS: [fdaa::3]:53)
	 JavaScript Runtime   Node.js (V8)
	 Middleware           ActionDispatch::HostAuthorization, Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::ActionableExceptions, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ContentSecurityPolicy::Middleware, ActionDispatch::PermissionsPolicy::Middleware, Rack::Head, Rack::ConditionalGet, Rack::ETag, Rack::TempfileReaper
	 Environment          production
	 Starting clean up.
	 Starting clean up.
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Configuring firecracker
	 Starting virtual machine
	 Starting init (commit: 249766e)...
	 Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
	 no label, UUID=a2c5a5db-a877-45d5-90d3-b02e7b6d5555
	 Preparing to run: `bin/rails fly:release` as root
	 2022/09/07 00:38:16 listening on [fdaa:0:95b4:a7b:2c00:51ae:d940:2]:22 (DNS: [fdaa::3]:53)
	 About your application's environment
	 Rails version        6.1.6.1
	 Ruby version         ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) +jemalloc [x86_64-linux]
	 RubyGems version     3.3.7
	 Rack version         2.2.4
	 JavaScript Runtime   Node.js (V8)
	 Middleware           ActionDispatch::HostAuthorization, Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::ActionableExceptions, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ContentSecurityPolicy::Middleware, ActionDispatch::PermissionsPolicy::Middleware, Rack::Head, Rack::ConditionalGet, Rack::ETag, Rack::TempfileReaper
	 Application root     /app
	 Environment          production
	 Starting clean up.
==> Monitoring deployment

 1 desired, 1 placed, 0 healthy, 1 unhealthy [restarts: 2] [health checks: 1 total]
Failed Instances

Failure #1

Instance
ID      	PROCESS	VERSION	REGION	DESIRED	STATUS 	HEALTH CHECKS	RESTARTS	CREATED 
c7aca979	app    	0      	mia   	run    	pending	1 total      	2       	32s ago	

Recent Events
TIMESTAMP           	TYPE      	MESSAGE                         
2022-09-07T00:38:36Z	Received  	Task received by client        	
2022-09-07T00:38:36Z	Task Setup	Building Task Directory        	
2022-09-07T00:38:40Z	Started   	Task started by client         	
2022-09-07T00:38:44Z	Terminated	Exit Code: 1                   	
2022-09-07T00:38:44Z	Restarting	Task restarting in 1.215154776s	
2022-09-07T00:38:53Z	Started   	Task started by client         	
2022-09-07T00:38:57Z	Terminated	Exit Code: 1                   	
2022-09-07T00:38:57Z	Restarting	Task restarting in 1.038241424s	

2022-09-07T00:39:08Z   [info]rails aborted!
2022-09-07T00:39:08Z   [info]Command failed with status (1): [bin/rails server...]
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/file_utils.rb:67:in `block in create_shell_runner'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/file_utils.rb:57:in `sh'
2022-09-07T00:39:08Z   [info]/app/lib/tasks/fly.rake:21:in `block (2 levels) in <main>'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/command.rb:50:in `invoke'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands.rb:18:in `<main>'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2022-09-07T00:39:08Z   [info]/app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2022-09-07T00:39:08Z   [info]Tasks: TOP => fly:server
2022-09-07T00:39:08Z   [info](See full trace by running task with --trace)
2022-09-07T00:39:08Z   [info]Starting clean up.
--> v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v1 

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

For context, I changed my lib/tasks/fly.rake to the following because there’s nothing to do for build and release steps. I just wanted to get something working so I swapped in the about task:

# commands used to deploy a Rails application
namespace :fly do
  # BUILD step:
  #  - changes to the filesystem made here DO get deployed
  #  - NO access to secrets, volumes, databases
  #  - Failures here prevent deployment
  task :build => 'about'

  # RELEASE step:
  #  - changes to the filesystem made here are DISCARDED
  #  - full access to secrets, databases
  #  - failures here prevent deployment
  task :release => 'about'

  # SERVER step:
  #  - changes to the filesystem made here are deployed
  #  - full access to secrets, databases
  #  - failures here result in VM being stated, shutdown, and rolled back
  #    to last successful deploy (if any).
  task :server do
    sh 'bin/rails server'
  end
end

A Rails application without a server. That’s something I haven’t encountered before.

Is it possible? Yes. Though it is a matter of “some assembly required”. If you are willing, I’ll talk you through it.

First, some links, though you don’t have to read them now - they might be useful later. fly-apps/supercronic and aptible/supercronic.

The net is that you don’t need most of what you currently have in your Dockerfile and fly.toml. In fact, you might be able to get away with only the following for your fly.toml:

app = "daily-iroh"

Now for your Dockerfile, all you probably need is to install supercronic, copy your app and run bundle install. Your Dockerfile will look something like this:

FROM quay.io/evl.ms/fullstaq-ruby:3.1.1-jemalloc-slim

ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.1/supercronic-linux-amd64 \
    SUPERCRONIC=supercronic-linux-amd64 \
    SUPERCRONIC_SHA1SUM= d7f4c0886eb85249ad05ed592902fa6865bb9d70

RUN curl -fsSLO "$SUPERCRONIC_URL" \
 && echo "${SUPERCRONIC_SHA1SUM}  ${SUPERCRONIC}" | sha1sum -c - \
 && chmod +x "$SUPERCRONIC" \
 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

RUN mkdir /app
WORKDIR /app

COPY Gemfile* ./
RUN bundle install

COPY . .

CMD supercronic /app/crontab

Now this might be stripped down too much - I haven’t seen your application so I can’t know for sure. But if you try it and get an error because something isn’t installed, I can talk you through adding it.

You will need one more file, a crontab. If you are not familiar with this file there are lots of good resources on the internet which describe the format. For example: