This post originated from an RSS feed registered with Ruby Buzz
by Jamis Buck.
Original Post: Using SwitchTower with multiple deployment stages
Feed Title: the buckblogs here
Feed URL: http://weblog.jamisbuck.org/blog.cgi/programming/index.rss
Feed Description: Jamis Buck's corner of the blogging universe. Mostly about ruby, but includes ramblings on a variety of topics.
Back in August I blogged briefly about having a conditional SwitchTower configuration, which would allow you to specify a different configuration for various stages of deployment. Recently, people have been asking for “deploy_stage” and “deploy_production” in SwitchTower itself, but I’m pushing back. It seems to me that it is easy enough to do in SwitchTower that there doesn’t really need to be a specific feature set in ST for it (but you tell me).
Revisiting that entry, I wouldn’t do it much differently today. The deploy.rb would still look more or less like this:
It is as simple as an if statement, and it lets you configure multiple deployment stages (if you need them). If using environment variables is less than tasteful to you, you can also use ST variables:
...ifstage=="stage"...else...end...
You would then invoke the task like:
switchtower -vvvv -S stage=production -r config/deploy -a deploy
(Note the use of a capital -S—this causes the variable to be set before the recipe file is loaded, which is necessary since the variable is referenced as the file is being read.)
Note that using a variable complicates things a little bit if you are using rake, because you can’t pass the variable to the ST task from the rake command-line. Instead, you’ll need to create a new rake task for each value you want to pass to the variable (i.e., deploy_stage and deploy_production). For this reason, I prefer to use environment variables, but your mileage may vary.
So, from those of you who need multiple deployment stages, is this sufficient for you? If not, why?