We have a rails app that was fly launch a year or so ago, and it seems things have changed a bit since then. We are currently experiencing fly deploy not running migrations.
This made me think, how can I update my fly setup / dockerfile, etc. to the most modern way that the fly launch script would set things up today.
For instance: bin/rails generate dockerfile wont even run.
╰─ bin/rails generate dockerfile
Could not find generator 'dockerfile'.
Run `bin/rails generate --help` for more options.
How can we simply update our fly setups with fly launch without creating a new fly app?
As for the lib/tasks/fly.rake - I noticed a newer fly app no longer has this file, is that needed?
I am just confused to how we can get an existing fly app to the latest fly deploy setup, is there a way that the flyctl will automatically perform this? I would like to basically run the fly launch command as it would run today in the latest release of the flyctl to know that my fly setup is matched to the latest standards.
Unfortunately, no. It defaults to trying to preserve the [possibly hand crafted] configuration. An in your case, I assume you wanted to keep the application, ip address, databases, etc; you just wanted to modernize your dockerfile and associated files. dockerfile-rails will do all of this for nearly everything, but it will only add to your fly.toml. Pruning is something you still have to do manually.
I am confused, I was under the impression that the docker-entrypoint file is what runs the rails db:prepare command, but this is saying we should also have this added to the fly.toml file.
I’ll give a longer explanation here, and then work to get a shorter version into the docs.
The Dockerfile that dockerfile-rails produces closely matches the one that Rails 7.1 and later produce (I contributed heavily to both and try to keep them in sync). The Dockerfile Rails produces does the db:prepare in docker-entrypoint. This is suboptimal if you are using a database like Postgres (which runs in a separate machine or set of machines) and your app has multiple machines (highly recommended for availability reasons, and it is fine if you have them set to auto stop).
The reason this is suboptimal is that it will run each time one of your machine starts, and delay that machine’s processing of requests. If you have two or more machines, it will run on each machine even though it only needs to run once. Even if you have only one machine, if that machine is set to auto stop it will run every time that machine is restarted, even though nothing has changed in the schema.
Rails’s choice is arguably the right one for Rails. Even if suboptimal, providing something that will work for everybody as a starting point is a good strategy. Optimize later.
For many cloud platforms (including fly.io) and a database like Postgres, there is a better choice. With two lines in your fly.toml you can have the migration run exactly once per deployment: Fly Launch configuration (fly.toml) · Fly Docs .