Using SwitchTower with multiple deployment stages
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:
1 2 3 4 5 6 7 8 9 10 11 |
set :application, "example" if ENV["STAGE"] == "stage" set :deploy_to, "/u/apps/stage/#{application}" role :app, "staging.example.com" role :web, "staging.example.com" role :db, "staging.example.com", :primary => true else role :app, "foo.example.com", "bar.example.com" role :web, "123.example.com", role :db, "tiger.example.com", :primary => true end |
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:
1 2 3 4 5 6 7 |
... if stage == "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?
Reader Comments
3 Jan 2006
3 Jan 2006
3 Jan 2006
4 Jan 2006
4 Jan 2006
6 Jan 2006
6 Jan 2006
11 Jan 2006
11 Jan 2006
2 Feb 2006