.

SwitchTower - Production & Staging |

Ok so I’ve switched over to SwitchTower for my deployment.

Now I’ve run into a small problem. Basically I develop on a workstation (dev), and I can push to production. That’s all well and good - except I’m missing a step.

Anyone see Staging?

It’s a not uncommon practice to have a staging server. This is the mid point between your dev environment and your production server. Some people use it for testing (since often times the dev environment is so different from production - you can get staging to more closely model production making a good place to do any final checks before you roll into production). It’s also nice to have as a place that can be accessible to users to see a version of the software before it goes “live”.

SwitchTower doesn’t seem to have this concept. (If I missed it let me know what I’m doing wrong). It’s not a big deal really - since I can just modify my /lib/tasks/switchtower.rake

A couple things about this file.

1. Nothing in here is really project specific - so if you want to use it on your project it should work for you.
2. You’ll need to create a deploy_staging.rb in your /config
3. I added in a little detector to determine if you are on Windows or not - since if you are the command is different
4. All the old commands now exist with two version (c.f. deploy becomes deploy_production deploy_staging)

I just got this to work tonight so there may still be some bugs in it. I’ll post and I get it all worked out - but I figured feedback would be a good thing.


# =============================================================================
# A set of rake tasks for invoking the SwitchTower automation utility.
# =============================================================================
desc "Figure out the correct switchtower to call based on platform"
task :switchtower_command do
if File::ALT_SEPARATOR
ENV["SWITCHTOWER_APP"] = “switchtower.cmd”
else
ENV["SWITCHTOWER_APP"] = “switchtower”
end
end

desc “Set the config_file to deploy_staging”
task :switchtower_staging do
ENV["SWITCHTOWER_CONFIG"] = “config/deploy_staging”
end
desc “Set the config_file to deploy”
task :switchtower_production do
ENV["SWITCHTOWER_CONFIG"] = “config/deploy”
end

desc “Push the latest revision into production using the release manager”
task :deploy_production => [:switchtower_command, :switchtower_production, :deploy] do
end

desc “Rollback to the release before the current release in production”
task :rollback_production => [:switchtower_command, :switchtower_production, :rollback] do
end

desc “Describe the differences between HEAD and the last production release”
task :diff_from_last_deploy_production => [:switchtower_command, :switchtower_production, :diff_from_last_deploy ] do
end

desc “Enumerate all available deployment tasks on production”
task :show_deploy_tasks_production => [:switchtower_command,:switchtower_production, :show_deploy_tasks] do
end

desc “Execute a specific action using the release manager on production”
task :remote_exec_production => [:switchtower_command, :switchtower_production,:remote_exec_production ] do
end

desc “Push the latest revision into staging using the release manager”
task :deploy_staging => [:switchtower_command, :switchtower_staging, :deploy] do
end

desc “Rollback to the release before the current release in staging”
task :rollback_staging => [:switchtower_command, :switchtower_staging, :rollback] do
end

desc “Describe the differences between HEAD and the last staging release”
task :diff_from_last_deploy_staging => [:switchtower_command, :switchtower_staging, :diff_from_last_deploy ] do
end

desc “Enumerate all available deployment tasks on staging”
task :show_deploy_tasks_staging => [:switchtower_command,:switchtower_staging, :show_deploy_tasks] do
end

desc “Execute a specific action using the release manager on staging”
task :remote_exec_staging => [:switchtower_command, :switchtower_staging,:remote_exec_staging ] do
end

desc “Push the latest revision into production using the release manager”
task :deploy => [:switchtower_command] do
system “#{ENV["SWITCHTOWER_APP"]} -vvvv -r #{ENV["SWITCHTOWER_CONFIG"]} -a deploy”
end

desc “Rollback to the release before the current release in production”
task :rollback => [:switchtower_command] do
system “#{ENV["SWITCHTOWER_APP"]} -vvvv -r #{ENV["SWITCHTOWER_CONFIG"]} -a rollback”
end

desc “Describe the differences between HEAD and the last production release”
task :diff_from_last_deploy => [:switchtower_command] do
system “#{ENV["SWITCHTOWER_APP"]} -vvvv -r #{ENV["SWITCHTOWER_CONFIG"]} -a diff_from_last_deploy”
end

desc “Enumerate all available deployment tasks”
task :show_deploy_tasks => [:switchtower_command] do
system “#{ENV["SWITCHTOWER_APP"]} -r #{ENV["SWITCHTOWER_CONFIG"]} -a show_tasks”
end

desc “Execute a specific action using the release manager”
task :remote_exec => [:switchtower_command] do
unless ENV['ACTION']
raise “Please specify an action (or comma separated list of actions) via the ACTION environment variable”
end

actions = ENV['ACTION'].split(”,”).map { |a| “-a #{a}” }.join(” “)
system “#{ENV["SWITCHTOWER_APP"]} -vvvv -r #{ENV["SWITCHTOWER_CONFIG"]} #{actions}”
end

One Response to 'SwitchTower - Production & Staging'

Leave a Reply

Moderation Active: Old stuff here... Therefore your comment on this post will be moderated (i.e. don't submit twice !)

    Categories
    Archives

    .