class EY::Serverside::RailsAssets::Strategy::Shifting

The default behavior and the one used since the beginning of asset support in engineyard-serverside. Assets are compiled into a fresh shared directory. Previous shared assets are shifted to a last_assets directory to prevent errors during deploy.

When no assets changes are detected, the two shared directories are symlinked into the active release without any changes.

Public Instance Methods

prepare() { || ... } click to toggle source
# File lib/engineyard-serverside/rails_assets/strategy.rb, line 175
def prepare
  shift_existing_assets
  yield
rescue
  unshift_existing_assets
  raise
end
reuse() click to toggle source

link shared/assets and shared/last_assets into public

# File lib/engineyard-serverside/rails_assets/strategy.rb, line 171
def reuse
  run "mkdir -p #{shared_assets_path} #{last_assets_path} && #{link_assets}"
end

Protected Instance Methods

last_assets_path() click to toggle source
# File lib/engineyard-serverside/rails_assets/strategy.rb, line 185
def last_assets_path
  paths.shared.join('last_assets')
end
shift_existing_assets() click to toggle source

If there are current shared assets, move them under a ‘last_assets’ directory.

To support operations like Unicorn’s hot reload, it is useful to have the prior release’s assets as well. Otherwise, while a deploy is running, clients may request stale assets that you just deleted. Making use of this requires a properly-configured front-end HTTP server.

Note: This results in the directory structure:

deploy_root/current/public/assets -> deploy_root/shared/assets
deploy_root/current/public/last_assets -> deploy_root/shared/last_assets

where last_assets has an assets dir under it.

deploy_root/shared/last_assets/assets
# File lib/engineyard-serverside/rails_assets/strategy.rb, line 201
def shift_existing_assets
  run "rm -rf #{last_assets_path} && mkdir -p #{shared_assets_path} #{last_assets_path} && mv #{shared_assets_path} #{last_assets_path.join('assets')} && mkdir -p #{shared_assets_path} && #{link_assets}"
end
unshift_existing_assets() click to toggle source

Restore shared/last_assets to shared/assets and relink them to the app public

# File lib/engineyard-serverside/rails_assets/strategy.rb, line 206
def unshift_existing_assets
  run "rm -rf #{shared_assets_path} && mv #{last_assets_path.join('assets')} #{shared_assets_path} && mkdir -p #{last_assets_path} && #{link_assets}"
end