Class: EY::Serverside::Paths

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard-serverside/paths.rb

Defined Under Namespace

Modules: LegacyHelpers

Constant Summary collapse

MAINTENANCE_CANDIDATES =

Maintenance page candidates in order of search preference.

[
  "public/maintenance.html.custom",
  "public/maintenance.html.tmp",
  "public/maintenance.html",
  "public/system/maintenance.html.default",
]
DEFAULT_MAINTENANCE_PAGE =

This one is guaranteed to exist.

Pathname.new("default_maintenance_page.html").expand_path(File.dirname(__FILE__))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Paths

Returns a new instance of Paths.


98
99
100
101
102
103
104
105
# File 'lib/engineyard-serverside/paths.rb', line 98

def initialize(opts)
  @opts             = opts
  @home             = Pathname.new(@opts[:home] || ENV['HOME'])
  @app_name         = @opts[:app_name]
  @active_release   = Pathname.new(@opts[:active_release])   if @opts[:active_release]
  @repository_cache = Pathname.new(@opts[:repository_cache]) if @opts[:repository_cache]
  @deploy_root      = Pathname.new(@opts[:deploy_root] || "/data/#{@app_name}")
end

Instance Attribute Details

#deploy_rootObject (readonly)

Returns the value of attribute deploy_root


60
61
62
# File 'lib/engineyard-serverside/paths.rb', line 60

def deploy_root
  @deploy_root
end

#homeObject (readonly)

Returns the value of attribute home


60
61
62
# File 'lib/engineyard-serverside/paths.rb', line 60

def home
  @home
end

Class Method Details

.def_path(name, parts) ⇒ Object

Define methods that get us paths


49
50
51
# File 'lib/engineyard-serverside/paths.rb', line 49

def self.def_path(name, parts)
  define_method(name.to_sym) { path(*parts) }
end

Instance Method Details

#active_releaseObject

If no active release is defined, use current


118
119
120
# File 'lib/engineyard-serverside/paths.rb', line 118

def active_release
  @active_release || latest_release
end

#all_releasesObject


150
151
152
# File 'lib/engineyard-serverside/paths.rb', line 150

def all_releases
  @all_releases ||= Pathname.glob(path(:releases,'*')).sort
end

#deploy_hook(hook_name) ⇒ Object


130
131
132
# File 'lib/engineyard-serverside/paths.rb', line 130

def deploy_hook(hook_name)
  path(:deploy_hooks, "#{hook_name}.rb")
end

#deploy_keyObject


122
123
124
# File 'lib/engineyard-serverside/paths.rb', line 122

def deploy_key
  path(:home, '.ssh', "#{@app_name}-deploy-key")
end

#deployed?Boolean

Returns:

  • (Boolean)

174
175
176
# File 'lib/engineyard-serverside/paths.rb', line 174

def deployed?
  !!latest_release
end

#executable_deploy_hook(hook_name) ⇒ Object


138
139
140
# File 'lib/engineyard-serverside/paths.rb', line 138

def executable_deploy_hook(hook_name)
  path(:deploy_hooks, "#{hook_name}")
end

#executable_service_hook(service_name, hook_name) ⇒ Object


142
143
144
# File 'lib/engineyard-serverside/paths.rb', line 142

def executable_service_hook(service_name, hook_name)
  path(:shared_hooks, service_name, "#{hook_name}")
end

#latest_releaseObject

deploy_root/releases/<latest timestamp>


170
171
172
# File 'lib/engineyard-serverside/paths.rb', line 170

def latest_release
  all_releases.last
end

#maintenance_page_candidatesObject


178
179
180
181
182
183
184
185
186
187
188
# File 'lib/engineyard-serverside/paths.rb', line 178

def maintenance_page_candidates
  if latest_release
    candidates = MAINTENANCE_CANDIDATES.map do |file|
      path(:latest_release, file)
    end
  else
    candidates = []
  end
  candidates << DEFAULT_MAINTENANCE_PAGE
  candidates
end

#new_release!Object

if active_release is already set, it's set because we're operating on an existing release. This happens during integrate


113
114
115
# File 'lib/engineyard-serverside/paths.rb', line 113

def new_release!
  @active_release ||= path(:releases, release_dirname)
end

#path(root, *parts) ⇒ Object

Load a path given a root and more parts Pathname#join is extremely inefficient. This implementation uses much less memory and way fewer objects.


56
57
58
# File 'lib/engineyard-serverside/paths.rb', line 56

def path(root, *parts)
  Pathname.new(File.join(send(root).to_s, *parts))
end

#previous_release(from_release = latest_release) ⇒ Object

deploy_root/releases/<release before argument release path>


155
156
157
158
159
160
161
162
# File 'lib/engineyard-serverside/paths.rb', line 155

def previous_release(from_release=latest_release)
  index = all_releases.index(from_release)
  if index && index > 0
    all_releases[index-1]
  else
    nil
  end
end

#previous_revisionObject


164
165
166
167
# File 'lib/engineyard-serverside/paths.rb', line 164

def previous_revision
  rel = previous_release(active_release)
  rel && rel.join('REVISION')
end

#release_dirnameObject


107
108
109
# File 'lib/engineyard-serverside/paths.rb', line 107

def release_dirname
  Time.now.utc.strftime("%Y%m%d%H%M%S")
end

#repository_cacheObject


146
147
148
# File 'lib/engineyard-serverside/paths.rb', line 146

def repository_cache
  @repository_cache ||= default_repository_cache
end

#rollbackObject


190
191
192
193
194
195
196
# File 'lib/engineyard-serverside/paths.rb', line 190

def rollback
  if deployed? && previous_release
    self.class.new(@opts.dup.merge(:active_release => previous_release))
  else
    nil
  end
end

#service_hook(service_name, hook_name) ⇒ Object


134
135
136
# File 'lib/engineyard-serverside/paths.rb', line 134

def service_hook(service_name, hook_name)
  path(:shared_hooks, service_name, "#{hook_name}.rb")
end

#ssh_wrapperObject


126
127
128
# File 'lib/engineyard-serverside/paths.rb', line 126

def ssh_wrapper
  path(:shared_config, "#{@app_name}-ssh-wrapper")
end