Class: DrushDeploy::Capistrano

Inherits:
Object
  • Object
show all
Defined in:
lib/drush_deploy/capistrano.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

DEFAULT_ROLES =
[:web]

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Capistrano

Returns a new instance of Capistrano.



14
15
16
17
18
# File 'lib/drush_deploy/capistrano.rb', line 14

def initialize(config)
  @cap_config = config
  @drush_config = DrushDeploy::Configuration.new @cap_config[:drush]
  @cap_config.logger.info "Using drush at \"#{@drush_config.drush}\""
end

Instance Method Details

#load_target(sitename) ⇒ Object

Take a sitename and setup it’s settings as the target host



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/drush_deploy/capistrano.rb', line 21

def load_target(sitename)
  site = @drush_config.lookup_site(sitename)
  return nil unless site

  if site["site-list"]
    # Site group
    site["site-list"].each {|member| load_target member}
  else
    this = self
    @cap_config.load do
      # Verify existence of required setting
      if this.valid_target(site)
        logger.info "Loading target #{sitename}"
        # Setup servername. Use <username>@ and :<port> syntax in servername instead of
        # :user and ssh_option[:port] to allow for different values per host.
        servername = site["remote-host"]

        servername = site["remote-user"]+'@'+servername if site["remote-user"]

        attributes = site["attributes"] || {}

        if site["ssh-options"]
          ssh_opts = site["ssh-options"].dup
          if  ssh_opts[:port]
            servername += ':'+ssh_opts[:port].to_s
            ssh_opts.delete :port
          end
          (attributes[:ssh_options] ||= {}).merge! ssh_opts
        end

        roles = site["roles"]
        unless roles
          roles = DEFAULT_ROLES
          logger.info "Using default roles #{roles.map{|r| "#{r}"}.join(", ")} for target \"#{sitename}\""
        end
        server servername, *roles, attributes

        # If global settings are already set, don't overwrite
        root = site["root"].dup
        unless root.sub! %r{/current/?$},''
          throw Error.new "root setting of site \"#{sitename}\" does not end in /current: \"#{root}\""
        end
        if root
          if !defined?(deploy_to)
            set :deploy_to, root
          elsif deploy_to != root
            logger.important "Ignoring \"root\" option for site #{sitename} because deploy_to has already been set.\n"\
                        "Note there may be only one root value for a single deploy"
          end
        end
        if site["databases"]
          dbs = DrushDeploy::Configuration.normalize_value site["databases"]
          set :databases, DrushDeploy::Database.deep_merge(dbs,databases)
        end
        if site["version_database"]
          set :version_database, (site["version_database"] == 1)
        end
      end
    end
  end
end

#targetsObject



87
88
89
90
91
92
# File 'lib/drush_deploy/capistrano.rb', line 87

def targets
  @drush_config.aliases.inject([]) do |list,(k,v)|
    list << k if valid_target(v)
    list
  end
end

#valid_target(site) ⇒ Object



83
84
85
# File 'lib/drush_deploy/capistrano.rb', line 83

def valid_target(site)
  site["site-list"] || site["remote-host"]
end