Foreman: Use different Procfile in development and production
Asked Answered
B

4

78

I have a homemade Sinatra application for which I intend to use Heroku to host it.

I use foreman and shotgun in development, with the following Procfile:

web: shotgun config.ru -s thin -o 0.0.0.0 -p $PORT -E $RACK_ENV

It works great with both development and production. But the thing is, I don't want to use shotgun in production since it's too slow.

Can we use separate Procfile configurations for both dev and prod?

Berlioz answered 21/7, 2012 at 13:56 Comment(0)
L
160

Use multiple Procfiles and specify -f or --procfile running option to select one:

In dev (Procfile.dev contains your shotgun web process):

foreman start -f Procfile.dev

In production, foreman start will pick up the normal Procfile.

Alternatively, you could create a bin directory in your app with a script to start the appropriate web server depending on $RACK_ENV (an idea I found in a comment made by the creator of Foreman, so worth considering).

Longship answered 21/7, 2012 at 20:27 Comment(5)
Would you by chance know if there is a way to tell Heroku to run a different Procfile?Patino
@Patino no, there is no way to specify a custom Procfile for Heroku to run with. It will always use the one named Procfile.Siloxane
To avoid the -f Procfile.dev parameter you can create a .foreman file with procfile: Procfile.devin itFe
@Siloxane that's terrifying, is that intentional?Keppel
For anyone happening to use node-foreman, the flag is -j instead of -f for some odd reason.Wale
H
25

@sharagoz 's comment on the selected answer, in my opinion, is the best option to allow you to still use foreman start without adding additional arguments AND keep your Procfile separate for Heroku.

To avoid the -f Procfile.dev parameter you can create a .foreman file with procfile: Procfile.dev in it – Sharagoz

In my applications root directory I created a .foreman file and as the comment states

.foreman

procfile: Procfile.dev

Procfile

web: bundle exec puma -C config/puma.rb

Procfile.dev

web: bundle exec puma -C config/puma.rb
webpacker: ./bin/webpack-dev-server
Honey answered 18/10, 2018 at 17:26 Comment(0)
S
4

Here is a way to handle it with one Procfile and environment variables. I am using this on Heroku.

Set your environment:

export WEB_START_COMMAND='node index.js'
export WORKER_START_COMMAND='node worker.js'

The Procfile:

web: eval '$WEB_START_COMMAND'
worker: eval '$WORKER_START_COMMAND'

Export different start command in your server and dev environments.

Suborder answered 9/6, 2017 at 23:6 Comment(3)
this doesn't seem to work when there's a $PORT on the commandPassus
This is somewhat limited if you want to have a different set of processes per environment. @sharagoz solution is more flexible.Transference
In my case it turned out to be a pretty good solution, simple and working.Spoondrift
L
2

For those still looking for this, according to the docs foreman is not needed anymore. You can simply use:

heroku local -f Procfile.dev

Loyola answered 4/4, 2019 at 11:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.