Module: Deployment::Methods::Helper

Defined in:
lib/depengine/dsl/helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validates_not_empty(attribute, message = nil) ⇒ Object



164
165
166
# File 'lib/depengine/dsl/helper.rb', line 164

def validates_not_empty(attribute, message = nil)
  fail ArgumentError, message || 'Parameter is empty', caller if attribute.nil?
end

.validates_presence_of(attribute, message = nil) ⇒ Object



159
160
161
# File 'lib/depengine/dsl/helper.rb', line 159

def validates_presence_of(attribute, message = nil)
  fail ArgumentError, message || 'Missing parameter', caller if attribute.nil?
end

Instance Method Details

#assert_url_response_of(options = {}) ⇒ Object

Checks if a given url returns 200 and a body that matches a given regexp.

Parameters:

  • options - a hash with needed configuration options

    • :check_protocol - “http” or “https” or maybe something else…

    • :check_host - the host to contact

    • :check_port - the port to connect to

    • :check_uri - the recipiants address

    • :check_response_string - the string or regexp to check



44
45
46
47
48
49
50
51
52
53
# File 'lib/depengine/dsl/helper.rb', line 44

def assert_url_response_of(options = {})
  asserter = ::Asserter::Url.new
  asserter.check_protocol  = options[:check_protocol] ||  @cdb['check_protocol'] || 'http'
  asserter.check_host  = options[:check_host] || @cdb['check_host']
  asserter.check_port  = options[:check_port] || @cdb['check_port'] || '80'
  asserter.check_uri  = options[:check_uri] || @cdb['check_uri'] || '/'
  asserter.check_response_string  = options[:check_response_string] || @cdb['check_response_string'] || 'html'

  asserter.assert_url_response_of(options)
end

#date_unique(format = '%Y-%m-%d_%s') ⇒ Object

Returns an time-dependant string that can be used in pseudo-unique release versions and the such.

The object will be cached for later reference, so multiple uses of this method in a recipe will result in the same string.

Parameters:

  • format - the strftime format that is to be used to generate the unique string. Defaults to “%Y-%m-%d_%s”.



12
13
14
# File 'lib/depengine/dsl/helper.rb', line 12

def date_unique(format = '%Y-%m-%d_%s')
  @date_unique ||= Time.now.strftime(format)
end

#report_by_mail(options = {}) ⇒ Object

Sends an email to report a deployment to a given recepiant.

Parameters:

  • options - a hash with needed configuration options for the email. All parameters are optional.

    • :application_name - which application has been deployed

    • :module_name - which module of the application has been deployed

    • :status - the resulting status of the deployment

    • :message - a additional message to send in the mail, commonly used to specify any non positive status.

    • :deploy_email_from - the senders address

    • :deploy_email_to - the recipiants address



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/depengine/dsl/helper.rb', line 73

def report_by_mail(options = {})
  options = @cdb.merge($recipe_config).merge(options)
  options[:status] ||= 'success'
  options[:message] ||= ''

  mail_options = {
    from: options[:deploy_email_from] || @cdb['deploy_email_from'],
    to: options[:deploy_email_to] || @cdb['deploy_email_to'],
    subject: "#{options[:env]} #{options[:job_name]} #{options[:module_name]} #{options[:application_name]} #{options[:version]} #{options[:status]}",
    body: "Env: #{options[:env]}\nJob: #{options[:job_name]}\nModule: #{options[:module_name]}\nApplication: #{options[:application_name]}\nVersion: #{options[:version].to_json}\n#{options[:status]}.\n\n#{options[:message]}"
  }
  sendmail(mail_options)
end

#report_by_mail_with_git_history(r1 = '', r2 = '', options = {}) ⇒ Object

Sends an email with git commit history to report a deployment to a given recepiant.

Parameters:

  • :r2 - Include commits that are reachable from r2

  • :r1 - but exclude those that are reachable from r1.

  • options - a hash with needed configuration options for the email. All parameters are optional.

    • :git_dir - Directory from which the git repo can be reached (the one containing .git or any of its children).

    • :application_name - which application has been deployed

    • :module_name - which module of the application has been deployed

    • :status - the resulting status of the deployment

    • :message - a additional message to send in the mail, commonly used to specify any non positive status.

    • :deploy_email_from - the senders address

    • :deploy_email_to - the recipiants address

Please see ‘GITREVISIONS(7)` for more info on how to specify a revision range.



101
102
103
104
105
106
107
# File 'lib/depengine/dsl/helper.rb', line 101

def report_by_mail_with_git_history(r1 = '', r2 = '', options = {})
  git = Provider::Git.new
  git.repository_local_dir = options[:git_dir] || '.'
  options[:message] = (options[:message] || '') + git.history(r1, r2).to_s

  report_by_mail(options)
end

#report_to_cdbObject

Reports a deployment to its cdb.



56
57
58
59
60
61
# File 'lib/depengine/dsl/helper.rb', line 56

def report_to_cdb
  reporter = ::Reporter::Cdb.new
  reporter.version  = @version.to_json
  reporter.worker  = self
  reporter.set_version
end

#samba_mount(remote_path, local_path) ⇒ Object

Mounts a SMB share.

Parameters:

  • remote_path - the path to the remote share (e.g.“smb://somehost/someshare”)

  • :local_path - the local path in which the share will be mounted



142
143
144
145
146
147
# File 'lib/depengine/dsl/helper.rb', line 142

def samba_mount(remote_path, local_path)
  smb                   = ::Helper::Smb.new
  smb.remote_path       = remote_path
  smb.local_path        = local_path
  smb.samba_mount
end

#samba_umount(local_path) ⇒ Object

Unmounts a previously mounted SMB share.

Parameters:

  • :local_path - the local path in which the share is mounted



153
154
155
156
157
# File 'lib/depengine/dsl/helper.rb', line 153

def samba_umount(local_path)
  smb                   = ::Helper::Smb.new
  smb.local_path        = local_path
  smb.samba_umount
end

#sendmail(options) ⇒ Object

Sends an email.

Parameters:

  • options - a hash with needed configuration options for the email.

    • :body - the actual text to send

    • :subject - the subject line of the email

    • :from - the senders address

    • :to - the recipiants address



24
25
26
27
28
29
30
31
32
33
# File 'lib/depengine/dsl/helper.rb', line 24

def sendmail(options)
  Helper.validates_presence_of options[:from],    'Mail-FROM not set'
  Helper.validates_presence_of options[:to],      'Mail-TO not set'
  Helper.validates_presence_of options[:subject], 'No mail subject set'
  Helper.validates_presence_of options[:body],    'No mail body set'

  helper = ::Helper::Mail.new
  helper.smtp_host = @cdb['smtp_host'] if @cdb && @cdb['smtp_host']
  helper.sendmail(options)
end

#tomcat_deploy(options = {}) ⇒ Object

Deploys a tomcat based application to a set of app servers.
The tomcats are restarted in this process.

Parameters:

  • options - a hash with needed configuration options.

    • :servers - an enumerable list of the app servers

    • :runners - a subset of :servers which are currently active. Is equal to :servers if not set

    • :initd_script - the path to the init script of the appserver. Used to stop/start.

    • :application_name - the name of the current application

    • :catalina_home - the path in which the app servers webapps/ directory is

    • :tomcat_context - the tomcat context to deploy in

    • :logfilename - the name of the logfile. Will be automatically prefixed with #catalina_home/logs/

    • :check_host - an options hash to pass to #assert_url_response_of to check the status of the app

All parameters can also be spcified via CDB.



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/depengine/dsl/helper.rb', line 123

def tomcat_deploy(options = {})
  publisher = ::Publisher::Tomcat.new
  publisher.servers  = options[:servers] || @cdb['servers']
  publisher.runners = options[:runners] || @cdb['runners'] || publisher.servers
  publisher.initd_script  = options[:initd_script] || @cdb['initd_script']
  publisher.application_name  = options[:application_name] ||  $recipe_config[:application_name] || @cdb['application_name']
  publisher.catalina_home  = options[:catalina_home] || @cdb['catalina_home']
  publisher.tomcat_context  = options[:tomcat_context] || @cdb['tomcat_context']
  publisher.logfilename  = options[:logfilename] || @cdb['logfilename']
  publisher.check_host  = options[:check_host] || @cdb['check_host']
  publisher.worker  = self
  publisher.deploy(options)
end