phil swenson
phil swenson

Reputation: 8894

foreman development vs production (rails)

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.

Upvotes: 19

Views: 9542

Answers (4)

vanboom
vanboom

Reputation: 1332

Our solution was to use a separate job type in our Procfile for dev vs. production. It is not the most DRY method, but it works...

sidekiq: bundle exec sidekiq
sidekiq-prod: bundle exec sidekiq -e production

Then we run foreman specifying the prod job on the production system:

foreman start -c sidekiq-prod=4

Upvotes: 0

conarro
conarro

Reputation: 86

I've used environment-specific Procfiles before, which is pretty simple and works fine.

Basically you have Procfile.development, Procfile.production, etc. In each you can customize the procs you want to start, then run them via foreman like so:

foreman start -f Procfile.development

Another approach is to reference scripts in your Procfile, and within each script start up the appropriate process based on the environment. The creator of Foreman does this and has an example from his Anvil project your reference.

Upvotes: 1

Matthew Rudy
Matthew Rudy

Reputation: 16834

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

Upvotes: 22

Jim Deville
Jim Deville

Reputation: 10662

Foreman takes arguments to use a different file (-d) and arguments to specify what to run. It also supports a .foreman file that allows those args to become default. See http://ddollar.github.com/foreman/ for more info

Upvotes: 3

Related Questions