Foreman: Use different Procfile in development and production
You could use two Procfiles
(e.g. Procfile
and Procfile.dev
) and use foreman
s -f
option to select a different one to use in dev:
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).
For those still looking for this, according to the docs foreman
is not needed anymore. You can simply use:
heroku local -f Procfile.dev
@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
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.