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.



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

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



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

def active_release
  @active_release || latest_release
end

#all_releasesObject



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

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

#deploy_hook(hook_name) ⇒ Object



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

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

#deploy_keyObject



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

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

#deployed?Boolean

Returns:

  • (Boolean)


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

def deployed?
  !!latest_release
end

#executable_deploy_hook(hook_name) ⇒ Object



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

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

#latest_releaseObject

deploy_root/releases/<latest timestamp>



161
162
163
# File 'lib/engineyard-serverside/paths.rb', line 161

def latest_release
  all_releases.last
end

#maintenance_page_candidatesObject



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

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



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

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>



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

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



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

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

#release_dirnameObject



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

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

#repository_cacheObject



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

def repository_cache
  @repository_cache ||= default_repository_cache
end

#rollbackObject



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

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

#ssh_wrapperObject



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

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