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



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
116
117
118
# File 'lib/strobe/resources/application.rb', line 80

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



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

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

    # TODO: remove next line when environment_uri stuff is released
    uri = web_url if uri.blank?

    "#{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



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

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



51
52
53
54
55
56
# File 'lib/strobe/resources/application.rb', line 51

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

#web_installObject



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

def web_install
  # TODO: eventually it will be better to us name for identifying web platform
  install = self.platform_installs.detect { |p| p.web? }
  raise "Application does not have web platform" unless install
  install.reload!
end

#web_urlObject



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

def web_url
  web_install['install_uri']
end