Class: Strobe::Resources::Application

Inherits:
Object
  • Object
show all
Includes:
Strobe::Resource::Collection
Defined in:
lib/strobe/resources/application.rb

Defined Under Namespace

Classes: PackFile

Instance Attribute Summary

Attributes included from Strobe::Resource::Base

#response

Instance Method Summary collapse

Methods included from Strobe::Resource::Collection

#key, #reload, #reload!

Methods included from Strobe::Resource::Base

#[], #[]=, #destroy, #initialize, #key?, #merge!, #params, #params=, #persisted?, #save, #save!

Methods included from Validations

#read_attribute_for_validation, #valid_attribute?, #valid_for_given_attributes?

Instance Method Details

#deploy!(opts = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/strobe/resources/application.rb', line 77

def deploy!(opts = {})
  self['path'] = opts[:path] if opts[:path]

  if opts[:pre_deploy]
    unless Kernel.system(opts[:pre_deploy])
      raise Strobe::DeployInterrupted, "pre deploy hook returned non-zero status, deploy was stopped"
    end
  end

  # TODO: trappist and/or monastery freaks out when we pass production environment
  #       explicitly, we should fix this as it's not intuitive
  environment  = (opts[:environment] == "production" ? nil : opts[:environment])
  callback     = opts[:callback]
  message      = opts[:message]
  github_url   = opts[:github_url]
  scm_version  = opts[:scm_version]

  validate_for_deploy or return

  request do
    qs = []
    qs << "environment=#{environment}"           if environment
    qs << "message=#{message}"                   if message
    qs << "github_url=#{URI.escape(github_url)}" if github_url
    qs << "scm_version=#{scm_version}"           if scm_version

    uri = "#{http_uri}/deploy"
    uri = "#{uri}?#{qs.join('&')}" unless qs.blank?
    uri = URI.escape(uri)

    packfile = build_packfile(opts)
    response = connection.put(uri, packfile, packfile.headers)
    callback.deploy_complete if callback
    Kernel.system(opts[:post_deploy]) if opts[:post_deploy]
    response
  end

  environment_url(environment)
end

#environment_url(environment) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/strobe/resources/application.rb', line 39

def environment_url(environment)
  if environment.blank? || environment == "production"
    web_url
  else
    uri = web_install['environment_uri']
    "#{environment}.#{uri}"
  end
end

#idObject



23
24
25
# File 'lib/strobe/resources/application.rb', line 23

def id
  self[:id]
end

#rollback!(sha, opts = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/strobe/resources/application.rb', line 55

def rollback!(sha, opts = {})
  environment = opts[:environment]
  message     = opts[:message]

  id = self[:id]

  request do
    qs = []
    qs << "environment=#{environment}"  if environment
    qs << "message=#{message}"          if message
    qs << "deploy=#{sha}"
    qs << "application_id=#{id}"

    uri = URI.escape("/deploys?#{qs.join('&')}")

    response = connection.post(uri)
    response
  end

  environment_url(environment)
end

#set_web_url!(url) ⇒ Object



48
49
50
51
52
53
# File 'lib/strobe/resources/application.rb', line 48

def set_web_url!(url)
  return if url.blank?
  install = web_install
  install['url'] = install['install_uri'] = url
  install.save!
end

#web_installObject



27
28
29
30
31
32
33
# File 'lib/strobe/resources/application.rb', line 27

def web_install
  @web_install ||= begin
    install = self.platform_installs.detect { |p| p.web? }
    raise "Application does not have web platform" unless install
    install
  end
end

#web_urlObject



35
36
37
# File 'lib/strobe/resources/application.rb', line 35

def web_url
  web_install['install_uri']
end