From e34ba965e17127315bbf7881cd81eb3a2dac1ace Mon Sep 17 00:00:00 2001 From: John Maya Date: Tue, 23 Aug 2011 13:17:48 -0400 Subject: [PATCH] Added HOST filter --- README.markdown | 1 + lib/cap_ext_webistrano/host.rb | 12 ++++++++++++ lib/cap_ext_webistrano/task.rb | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 lib/cap_ext_webistrano/host.rb diff --git a/README.markdown b/README.markdown index 8f30209..c882898 100644 --- a/README.markdown +++ b/README.markdown @@ -26,6 +26,7 @@ configure for your application with Capistrano. set :password, "admin" set :stage, "test" # specify the stage you want to deploy set :webistrano_home, "http://webistrano.mydomain.com" + set :host_to_deploy, "server-name-here" #if you wish to override the host If you only have one stage in your project this should do, however with several stages it'd be better to ask for the stage to be deployed: diff --git a/lib/cap_ext_webistrano/host.rb b/lib/cap_ext_webistrano/host.rb new file mode 100644 index 0000000..0129792 --- /dev/null +++ b/lib/cap_ext_webistrano/host.rb @@ -0,0 +1,12 @@ +class Host < ActiveResource::Base + def self.configure(config) + Host.site = config[:webistrano_home] + Host.user = config[:user] + Host.password = config[:password] + end + + def self.find_by_name(name) + host = find(:all).find {|host| host.name == name} + end + +end diff --git a/lib/cap_ext_webistrano/task.rb b/lib/cap_ext_webistrano/task.rb index d252ace..2ab68a2 100644 --- a/lib/cap_ext_webistrano/task.rb +++ b/lib/cap_ext_webistrano/task.rb @@ -1,6 +1,7 @@ require 'cap_ext_webistrano/project' require 'cap_ext_webistrano/stage' require 'cap_ext_webistrano/deployment' +require 'cap_ext_webistrano/host' module CapExtWebistrano class Task @@ -13,7 +14,7 @@ def initialize(task, config) end def set_access_data - [Project, Stage, Deployment].each do |klazz| + [Project, Stage, Deployment, Host].each do |klazz| klazz.configure(@config) end end @@ -43,7 +44,18 @@ def run set_access_data @project = Project.find_by_name(@config[:application]) @stage = @project.find_stage(@config[:stage]) - params = { :task => task, :stage_id => @stage.id, :project_id => @project.id, :description => @config[:description] } + params = {} + + if @config[:host_to_deploy] + hosts_all = Host.all + host_to_deploy = Host.find_by_name(@config[:host_to_deploy]) + do_not_deploy_hosts = hosts_all - [host_to_deploy] + hosts_ids = do_not_deploy_hosts.collect {|h| h.id} + params = { :task => task, :stage_id => @stage.id, :project_id => @project.id, :description => @config[:description], :excluded_host_ids => hosts_ids } + else + params = { :task => task, :stage_id => @stage.id, :project_id => @project.id, :description => @config[:description]} + end + params.merge!(:prompt_config => @config[:prompt_config]) if @config.exists?(:prompt_config) @deployment = Deployment.create(params) loop_latest_deployment