foreman development vs production (rails)

phil swenson picture phil swenson · Jan 13, 2013 · Viewed 9.1k times · Source

what is the "foreman way" for behaving differently in production vs development? That is we want foreman start to start up a bunch of stuff in dev, however in heroku production we don't need it to start (for example) solr.

Answer

Matthew Rudy picture Matthew Rudy · Jan 14, 2013

I follow the convention;

  • Procfile defines all processes
  • .foreman set specific foreman variables

Development:

  • .env sets environment variables for each developer
  • .env.example sets defaults for development
  • foreman start starts all processes

Production:

  • heroku config sets environment variables
  • heroku ps:scale turns on or off whichever processes are needed for production

Here's an example from a project.

Procfile:

web:    bundle exec unicorn_rails -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
search: bundle exec rake sunspot:solr:run

.env.example:

# default S3 bucket
S3_KEY=keykeykeykeykeykey
S3_SECRET=secretsecretsecret
S3_BUCKET=myapp-development

.env

# developer's private S3 bucket
S3_KEY=mememememememememe
S3_SECRET=mysecretmysecret
S3_BUCKET=myapp-development

.foreman:

# development port is 3000
port: 3000