Module: ProjectlockerErrataTasks

Defined in:
lib/projectlocker_errata_tasks.rb

Overview

Capistrano tasks for notifying ProjectlockerErrata of deploys

Class Method Summary collapse

Class Method Details

.deploy(opts = {}) ⇒ Object

Alerts ProjectlockerErrata of a deploy.

Parameters:

  • opts (Hash) (defaults to: {})

    Data about the deploy that is set to ProjectlockerErrata

Options Hash (opts):

  • :api_key (String)

    Api key of you ProjectlockerErrata application

  • :rails_env (String)

    Environment of the deploy (production, staging)

  • :scm_revision (String)

    The given revision/sha that is being deployed

  • :scm_repository (String)

    Address of your repository to help with code lookups

  • :local_username (String)

    Who is deploying



16
17
18
19
20
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
# File 'lib/projectlocker_errata_tasks.rb', line 16

def self.deploy(opts = {})
  api_key = opts.delete(:api_key) || ProjectlockerErrata.configuration.api_key
  if api_key.blank?
    puts "I don't seem to be configured with an API key.  Please check your configuration."
    return false
  end

  if opts[:rails_env].blank?
    puts "I don't know to which Rails environment you are deploying (use the TO=production option)."
    return false
  end

  dry_run = opts.delete(:dry_run)
  params = {'api_key' => api_key}
  opts.each {|k,v| params["deploy[#{k}]"] = v }

  host = ProjectlockerErrata.configuration.host || 'errors.projectlocker.com'
  port = ProjectlockerErrata.configuration.port

  proxy = Net::HTTP.Proxy(ProjectlockerErrata.configuration.proxy_host,
                          ProjectlockerErrata.configuration.proxy_port,
                          ProjectlockerErrata.configuration.proxy_user,
                          ProjectlockerErrata.configuration.proxy_pass)
  http = proxy.new(host, port)



  # Handle Security
  if ProjectlockerErrata.configuration.secure?
    http.use_ssl      = true
    http.ca_file      = ProjectlockerErrata.configuration.ca_bundle_path
    http.verify_mode  = OpenSSL::SSL::VERIFY_PEER
  end

  post = Net::HTTP::Post.new("/deploys.txt")
  post.set_form_data(params)

  if dry_run
    puts http.inspect, params.inspect
    return true
  else
    response = http.request(post)

    puts response.body
    return Net::HTTPSuccess === response
  end
end