How to launch rails app with react in SSR mode,. customizing fly.rake or fly.toml

Hello, community

I have a rails application setup with react in SSR mode, and below is the Procfile which is used with foreman,

backend: bin/rails s -p 8000
frontend: bin/vite ssr # runs on port 13714

Here the rails server will run on port 8000 and a node.js app runs on port 13714.

I am a bit confused to configure these startup commands with fly, like whether I have to use fly.rake file or fly.toml file.

Could someone help me with customizing the startup commands?
Thanks in advance.

Assuming that you are following the recommendation to Don’t Bundle Foreman; add ruby-foreman to the DEPLOY_PACKAGES in your Dockerfile, then change your lib/tasks/fly.toml as follows:

  task :server => %i(swapfile) do
    Bundler.with_original_env do
      sh "foreman start"

Feel free to adjust the path to the procfile and add additional setup tasks as dependencies.

Thank you @rubys ,

It is helpful. Yes I m not bundling foreman into my Gemfile dependencies.

I wanted to get rid of foreman, so can I do the following in server task definition of fly.rake ?

  task :server => :swapfile do
    sh 'bin/rails server'
    sh 'bin/vite my-node-server-script'

Since bin/rails server normally won’t ever return, you won’t launch your node server.

There are a number of ways to launch multiple processes which are expected to run simultaneously. Foreman (and similar tools like overwind) are one way. See Running Multiple Processes Inside A App for more options. Multi process machines are another.

Finally, since the Rakefile is ruby code, the following will also work:

fork { sh 'bin/rails server' }
fork { sh 'bin/vite my-node-server-script' }
1 Like

Much clear now, Thanks a lot @rubys will give it a short :pray:

Thank you @rubys it worked :heart_eyes: