lakki
November 6, 2022, 2:33pm
1
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.
rubys
November 6, 2022, 2:56pm
2
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 --procfile=Procfile.fly"
end
end
Feel free to adjust the path to the procfile and add additional setup tasks as dependencies.
lakki
November 6, 2022, 3:05pm
3
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'
end
rubys
November 6, 2022, 3:16pm
4
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 Fly.io 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' }
Process.wait
1 Like
lakki
November 6, 2022, 3:23pm
5
Much clear now, Thanks a lot @rubys will give it a short
lakki
November 6, 2022, 6:25pm
6
Thank you @rubys it worked
system
Closed
May 4, 2024, 12:16am
8
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.