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.



95
96
97
98
99
100
101
102
# File 'lib/engineyard-serverside/paths.rb', line 95

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



115
116
117
# File 'lib/engineyard-serverside/paths.rb', line 115

def active_release
  @active_release || latest_release
end

#all_releasesObject



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

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

#deploy_hook(hook_name) ⇒ Object



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

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

#deploy_keyObject



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

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

#deployed?Boolean

Returns:

  • (Boolean)


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

def deployed?
  !!latest_release
end

#executable_deploy_hook(hook_name) ⇒ Object



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

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

#latest_releaseObject

deploy_root/releases/<latest timestamp>



159
160
161
# File 'lib/engineyard-serverside/paths.rb', line 159

def latest_release
  all_releases.last
end

#maintenance_page_candidatesObject



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/engineyard-serverside/paths.rb', line 167

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



110
111
112
# File 'lib/engineyard-serverside/paths.rb', line 110

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>



144
145
146
147
148
149
150
151
# File 'lib/engineyard-serverside/paths.rb', line 144

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



153
154
155
156
# File 'lib/engineyard-serverside/paths.rb', line 153

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

#release_dirnameObject



104
105
106
# File 'lib/engineyard-serverside/paths.rb', line 104

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

#repository_cacheObject



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

def repository_cache
  @repository_cache ||= default_repository_cache
end

#rollbackObject



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

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

#ssh_wrapperObject



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

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