Unable to deploy rail app

While I am trying to deploy the rail app, I am getting error message saying

Error: failed to fetch an image or build from source: app does not have a Dockerfile or buildpacks configured. See Fly Launch configuration (fly.toml) · Fly Docs

The app is even deployed in fly.io. Kindly check the screenshots attached and help me out.



Hi there,

The first screenshot shows the builder - it’s not actually your app but a free Docker builder that was spun up to try and build your app image for deployment.

And the error you’re seeing says there is no Dockerfile for your project, or the alternative which is a buildpack, and it’s asking you to maybe configure your fly.toml for your specific project build. You said it’s a Rails project, and I think for Rails, a Dockerfile and fly.toml file are automatically generated by fly launch. Did you run fly launch? if so, did you spot any errors during the run? Can you post your fly.toml file to see what might be the problem?

Regards,

  • Daniel

Hey Daniel, Thank you for your response. Yes I did run fly launch and it generated fly.toml file. I am attaching a screenshot of that file , please have a look. Also check if the root directory is correct

Hi there!

I suggest copying the text and pasting it in a comment. There’s a button on the compose window to turn it into “preformatted text” which will make it look readable. It’s much easier on bandwidth than using screenshots :slight_smile:

Your fly.toml is quite bare and I think it’s missing some sections, which I think is because when you created it initially, it failed to properly scan your Rails application and set all the configuration. If I recall correctly it should generate a much more complete fly.toml and also a Dockerfile which your error message suggests is not being generated in this case.

I would try moving fly.toml out of the way (rename it to fly-old.toml) and rerunning fly launch, taking care to capture the output in case there are relevant errors there.

  • Daniel

Key message: “Could not find a Dockerfile, nor detect a runtime or framework from source code”. Can you post the contents of your config.ru file?

Hey Ruby, here it is.

This file is used by Rack-based servers to start the application.

require_relative “config/environment”

run Rails.application
Rails.application.load_server

Hey Daniel, I did what you asked but still getting the same error. **


**

fly.toml app configuration file generated for blue-sunset-74 on 2023-08-15T23:30:01-04:00

See Fly Launch configuration (fly.toml) · Fly Docs for information about how to use this file.

app = “blue-sunset-74”
primary_region = “mia”

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = [“app”]

Error is

sumoncule@bhaswardweeps-MacBook-Air root % flyctl deploy
==> Verifying app config
Validating /Users/sumoncule/Flyhire/64363/app/views/root/fly.toml
Platform: machines
✓ Configuration is valid
→ Verified app config
==> Building image
Remote builder fly-builder-proud-cloud-9428 ready
Error: failed to fetch an image or build from source: app does not have a Dockerfile or buildpacks configured. See Fly Launch configuration (fly.toml) · Fly Docs

You need to run fly launch in the app’s source directory, which in your case, is the app directory.

Some docs might say “in the app’s root directory”, but this means you need to run it in the project source directory, not /root.

what’s the source directory? the app?

The top-level directory in your structure is named app? It looks like that’s the app’s source directory. You need to run fly launch in the app directory so that it can find your app’s files.

I just did that and got the same error. Deleted fly.toml from root directory.

I put the wrong screenshot. here is the correct one

Sorry, i’m not familiar with the rails structure. My last thought is to try it again from the top level. Try running fly launch in the 64363 directory. If that doesn’t work, I’ll leave it for the rails experts to follow up on :slight_smile:

1 Like

hi @bhaswar1212 ,

It doesn’t look to me like fly launch is detecting and properly configuring your Rails app. I created a simple Rails app following the Rails getting started guide, then I ran fly launch and you can see the output is quite different, it detects the Rails app, and then creates a set of files, crucially the Dockerfile, some configurations and an entrypoint:

fly launch --name rails-sample-pro --no-deploy --org personal  --region yul 
Creating app in /src/rails-sample-pro/sample
Scanning source code
Your Gemfile lists the gem tzinfo-data (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
Detected a Rails app
App will use 'yul' region as primary

Created app 'rails-sample-pro' in organization 'personal'
Admin URL: https://fly.io/apps/rails-sample-pro
Hostname: rails-sample-pro.fly.dev
Set secrets on rails-sample-pro: RAILS_MASTER_KEY
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
      create  Dockerfile
      create  .dockerignore
      create  bin/docker-entrypoint
      create  config/initializers/sentry.rb
      create  config/dockerfile.yml
Wrote config file fly.toml
Validating /src/rails-sample-pro/sample/fly.toml
Platform: machines
✓ Configuration is valid

Your Rails app is prepared for deployment.

Before proceeding, please review the posted Rails FAQ:
https://fly.io/docs/rails/getting-started/dockerfiles/.

Once ready: run 'fly deploy' to deploy your Rails app.

The fly.toml file is different from yours:

# fly.toml app configuration file generated for rails-sample-pro on 2023-08-16T09:46:56-04:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "rails-sample-pro"
primary_region = "yul"
console_command = "/rails/bin/rails console"

[build]

[[mounts]]
  source = "data"
  destination = "/data"

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

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

(particularly note the correct internal_port default for Rails apps).

I won’t post the Dockerfile because it’s quite long, but it was generated properly, unlike what you are seeing. Your deploy will most certainly not work until you manage to get your app properly recognized by fly launch to get a proper Dockerfile and other files as required.

  • Daniel

The difference is that you ran fly launch in the same directory the config.ru, Gemfile and other files are. Once @bhaswar1212 does this, I’m sure that things will work better.

If you scroll up and check the config.ru screenshot I have sent, you can see its on 64363 directory and I tried running fly launch from there too and got the same error. So no, it doesn’t work too

That is indeed the correct directory to run the command.

Commands to try:

flyctl version
ruby --version
rake --version
bundle --version

Can you ensure that there is no fly.toml or Dockerfile in that directory and run fly launch again?

Hey Rubys,

I ran it on the directory you specified and got the following error.

sumoncule@bhaswardweeps-MacBook-Air Flyhire % cd 64363
sumoncule@bhaswardweeps-MacBook-Air 64363 % fly launch
Creating app in /Users/sumoncule/Flyhire/64363
Scanning source code
Your Ruby version is 2.6.8, but your Gemfile specified 3.1.2
Error: Failed to install bundle, exiting: exit status 18

Tried to update the ruby version and also installed bundler but again getting errors. Please help.

sumoncule@bhaswardweeps-MacBook-Air 64363 % rbenv install 3.1.2

To follow progress, use ‘tail -f /var/folders/2w/4vxhb7_s4kjbyvw7_lbghyvw0000gn/T/ruby-build.20230816214350.58071.log’ or pass --verbose
Downloading openssl-3.1.0.tar.gz…
https://dqw8nmjcqpjn7.cloudfront.net/aaa925ad9828745c4cad9d9efeb273deca820f2cdcf2c3ac7d7c1212b7c497b4
Installing openssl-3.1.0…
Installed openssl-3.1.0 to /Users/sumoncule/.rbenv/versions/3.1.2

Downloading ruby-3.1.2.tar.gz…
https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2…
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
Installed ruby-3.1.2 to /Users/sumoncule/.rbenv/versions/3.1.2

**sumoncule@bhaswardweeps-MacBook-Air 64363 % fly launch **
Creating app in /Users/sumoncule/Flyhire/64363
Scanning source code
Your Ruby version is 2.6.8, but your Gemfile specified 3.1.2
Error: Failed to install bundle, exiting: exit status 18

**sumoncule@bhaswardweeps-MacBook-Air 64363 % rbenv local 3.1.2 **

**sumoncule@bhaswardweeps-MacBook-Air 64363 % fly launch **
Creating app in /Users/sumoncule/Flyhire/64363
Scanning source code
Your Ruby version is 2.6.8, but your Gemfile specified 3.1.2
Error: Failed to install bundle, exiting: exit status 18

sumoncule@bhaswardweeps-MacBook-Air 64363 % gem install bundler
bundle install

Fetching bundler-2.4.18.gem
ERROR: While executing gem … (Gem::FilePermissionError)
** You don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory.**
Your Ruby version is 2.6.8, but your Gemfile specified 3.1.2
**sumoncule@bhaswardweeps-MacBook-Air 64363 % rbenv global 3.1.2 **

sumoncule@bhaswardweeps-MacBook-Air 64363 % gem install bundler
bundle install

ERROR: While executing gem … (Gem::FilePermissionError)
** You don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory.**
Your Ruby version is 2.6.8, but your Gemfile specified 3.1.2
sumoncule@bhaswardweeps-MacBook-Air 64363 %

One solution is to simply remove the line in your Gemfile that specifies 3.1.2 and continue with Ruby 2.6.8.

That merely makes ruby 3.1.2 available to you. You can list all of the versions you have installed with rbenv list. To select one you would run a command like rbenv local 3.1.2. See GitHub - rbenv/rbenv: Manage your app's Ruby environment for more details.

I finally managed to deploy it. Thanks everyone for your valuable assistance :slight_smile: