Try adding the following to your Dockerfile, after the COPY . . line:
RUN sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*
The reason why these commands don’t work is that a number of Rails commands issue Rake commands on your behalf, and Rake looks for a Rakefile in your current working directory.
We are continuing to look for other fixes to this problem, but for now adjusting your binstubs gets you around this problem. The change above will make the next release of flyctl so projects
that issue fly launch once that is released will have this fix.
In the past 2 weeks, I noticed you put effort to improve the Rails experience, so I understand a lot is still work in progress. I’ll make sure to run fly launch on a regular basis to see how the defaults change.
That’s nice to hear. In case you are interested, you can find my backstory here. Don’t be shy - questions, feedback, and suggestions will help me make fly.io better for everyone.
Hello
I have the same problem but the fix does not work for me.
When i run :
fly ssh console -C "rails/bin/rails routes"
This command returns the roots as expected but when i run db:seed, i get the same message :
Connecting to fdaa:1:523f:a7b:ae02:3e85:995e:2... complete
rails aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/command.rb:51:in `invoke'
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands.rb:18:in `<main>'
/rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
rails/bin/rails:4:in `<main>'
(See full trace by running task with --trace)
So i pasted the line you gave in Dockerfile.
But then i can’t deploy :
=> ERROR [build 8/10] RUN sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/* 0.3s
------
> [build 8/10] RUN sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*:
#19 0.274 sed: can't read /app/bin/*: No such file or directory
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*]: exit code: 2
i event tried to modify the line because i don’t have the same path for the rails command (don’t know why)
RUN sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /rails/bin/*
And i still can’t deploy (it fails later now) :
--> You can detach the terminal anytime without stopping the deployment
==> Monitoring deployment
Logs: https://fly.io/apps/airjewels/monitoring
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
9a0dd563 app 10 cdg run pending 1 total 2 21s ago
Recent Events
TIMESTAMP TYPE MESSAGE
2023-02-15T01:12:48Z Received Task received by client
2023-02-15T01:12:48Z Task Setup Building Task Directory
2023-02-15T01:12:59Z Started Task started by client
2023-02-15T01:13:01Z Terminated Exit Code: 2
2023-02-15T01:13:01Z Restarting Task restarting in 1.171793983s
2023-02-15T01:13:07Z Started Task started by client
2023-02-15T01:13:09Z Terminated Exit Code: 2
2023-02-15T01:13:10Z Restarting Task restarting in 1.15411959s
2023-02-15T01:12:59Z [info]2023/02/15 01:12:59 listening on [fdaa:1:523f:a7b:aec1:9a0d:d563:2]:22 (DNS: [fdaa::3]:53)
2023-02-15T01:12:59Z [info]/rails/bin/docker-entrypoint: line 2: syntax error near unexpected token `('
2023-02-15T01:12:59Z [info]/rails/bin/docker-entrypoint: line 2: `Dir.chdir File.expand_path("..", __dir__)'
2023-02-15T01:13:00Z [info]Starting clean up.
2023-02-15T01:13:05Z [info]Starting instance
2023-02-15T01:13:05Z [info]Configuring virtual machine
2023-02-15T01:13:05Z [info]Pulling container image
2023-02-15T01:13:07Z [info]Unpacking image
2023-02-15T01:13:07Z [info]Preparing kernel init
2023-02-15T01:13:07Z [info]Configuring firecracker
2023-02-15T01:13:07Z [info]Starting virtual machine
2023-02-15T01:13:07Z [info]Starting init (commit: cf3bf32)...
2023-02-15T01:13:07Z [info]Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as root
2023-02-15T01:13:07Z [info]2023/02/15 01:13:07 listening on [fdaa:1:523f:a7b:aec1:9a0d:d563:2]:22 (DNS: [fdaa::3]:53)
2023-02-15T01:13:07Z [info]/rails/bin/docker-entrypoint: line 2: syntax error near unexpected token `('
2023-02-15T01:13:07Z [info]/rails/bin/docker-entrypoint: line 2: `Dir.chdir File.expand_path("..", __dir__)'
2023-02-15T01:13:08Z [info]Starting clean up.
2023-02-15T01:13:14Z [info]Starting instance
2023-02-15T01:13:14Z [info]Configuring virtual machine
2023-02-15T01:13:14Z [info]Pulling container image
2023-02-15T01:13:14Z [info]Unpacking image
2023-02-15T01:13:14Z [info]Preparing kernel init
2023-02-15T01:13:15Z [info]Configuring firecracker
2023-02-15T01:13:15Z [info]Starting virtual machine
2023-02-15T01:13:15Z [info]Starting init (commit: cf3bf32)...
2023-02-15T01:13:15Z [info]Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as root
2023-02-15T01:13:15Z [info]2023/02/15 01:13:15 listening on [fdaa:1:523f:a7b:aec1:9a0d:d563:2]:22 (DNS: [fdaa::3]:53)
2023-02-15T01:13:16Z [info]/rails/bin/docker-entrypoint: line 2: syntax error near unexpected token `('
2023-02-15T01:13:16Z [info]/rails/bin/docker-entrypoint: line 2: `Dir.chdir File.expand_path("..", __dir__)'
2023-02-15T01:13:16Z [info]Starting clean up.
--> v10 failed - Failed due to unhealthy allocations - rolling back to job version 9 and deploying as v11
--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort
Note: if you are running Rails 6 or above, you shouldn’t need to run db:seed, as bin/docker-entrypoint will run db:prepare which does this for you. See: Rails 6 adds db:prepare rake task | Saeloun Blog
edit: … and there was a bug in dockerfile-generate. Please run bundle update before running the command listed above.
So now the deploy workes but my app is broken and i have an other error running the fly ssh console -C '/rails/bin/rails db:seed' comandline
➜ Academint git:(master) fly ssh console -C '/rails/bin/rails db:seed'
Connecting to fdaa:1:523f:a7b:ae02:9e9c:c42e:2... complete
rails aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied for schema public
LINE 1: CREATE TABLE "schema_migrations" ("version" character varyin...
^
/rails/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `exec'
/rails/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `block (2 levels) in execute'
i get the same error running fly ssh console -C '/rails/bin/rails db:migrate'
Also i seams that it does not run migrations and seed when I deploy in production (i’m on rails 7), i also have to manualy do it whent is start a local server (localhost)
Ty for your help rubys !!
I found the way to fix my problem, I changed the DATABASE_URL in the secrets of my app with the right postgres credentials givent when i started the app
I dont know why it was rong because it is suposed to be set up whant I run fly launch