This post originated from an RSS feed registered with Ruby Buzz
by Guy Naor.
Original Post: Deploying to Staging and Production with Capistrano
Feed Title: Famundo - The Dev Blog
Feed URL: http://devblog.famundo.com/xml/rss/feed.xml
Feed Description: A blog describing the development and related technologies involved in creating famundo.com - a family management sytem written using Ruby On Rails and postgres
After an application is released, deployment should be in stages. To a test server, a staging server and a production one. I hope you have a staging server...
But capistrano has no knowledge of the difference between a staging and a production server. To make it easy to deploy using capistrano, a small change is needed to deploy.rb.
We add an if statement based off of an environment variable, and with it select the servers to deploy to. I also use this same variable to protect my production servers from accidental data changes, by adding an if to all data altering recipies I use only in staging (like reloading the DB and such). This way there's no way to run those commands on the production server.
Now, to deploy on staging:
env DEPLOY='STAGING' cap deploy
And on production:
env DEPLOY='PRODUCTION' cap deploy
Here's a small snippet of code with the change:
ifENV['DEPLOY']=='PRODUCTION'puts"*** Deploying to the \033[1;41m PRODUCTION \033[0m servers!"role:web,"www.your.domain.com"role:app,"app.your.domain.com
role :db, "db.your.domain.com", :primary => true
else
puts "***Deployingtothe \033[1;42mSTAGING \033[0mserver!"
role :web, "www.staging.domain.com"
role :app, "app.staging.domain.comrole:db,"db.staging.domain.com",:primary=>trueend