class EY::Serverside::RailsAssets::Strategy::Cleaning

Precompiled assets are shared across all deploys like Shared. Before compiling the active deploying assets, all assets that are not referenced by the manifest.yml from the previous deploy are removed. After cleaning, the new assets are compiled over the top. The result is an assets dir that contains the last assets and the current assets.

When no assets changes are detected, shared directory is only symlinked and cleaning and precompile tasks are not run.

Public Instance Methods

prepare() { || ... } click to toggle source
# File lib/engineyard-serverside/rails_assets/strategy.rb, line 125
def prepare
  reuse
  remove_old_assets
  yield
rescue
  # how do you restore back to the old assets if some have been overwritten?
  # probably just deploy again I suppose.
  raise
end

Protected Instance Methods

manifest_path() click to toggle source
# File lib/engineyard-serverside/rails_assets/strategy.rb, line 157
def manifest_path
  shared_assets_path.join('manifest.yml')
end
remove_old_assets() click to toggle source
# File lib/engineyard-serverside/rails_assets/strategy.rb, line 137
def remove_old_assets
  return unless manifest_path.readable?

  Dir.chdir(shared_assets_path)

  all_assets_on_disk = Dir.glob(shared_assets_path.join('**','*.*').to_s) - [manifest_path.to_s]
  $stderr.puts "all_assets_on_disk #{all_assets_on_disk.inspect}"
  assets_on_disk     = all_assets_on_disk.reject {|a| a =~ /\.gz$/}
  $stderr.puts "assets_on_disk #{assets_on_disk.inspect}"
  assets_in_manifest = YAML.load_file(manifest_path.to_s).values
  $stderr.puts "assets_in_manifest #{assets_in_manifest.inspect}"

  remove_assets = []
  (assets_on_disk - assets_in_manifest).each do |asset|
    remove_assets << "'#{asset}'"
    remove_assets << "'#{asset}.gz'" if all_assets_on_disk.include?("#{asset}.gz")
  end
  run("rm -rf #{remove_assets.join(' ')}")
end