Skip to content

Instantly share code, notes, and snippets.

@synth synth/assets.rb
Last active Dec 17, 2015

What would you like to do?
Local Asset Precompilation with Capistrano and AssetSync
# = Capistrano Assets recipe
# Provides a couple of tasks for precompiling assets locally
# Assumes usage of AssetSync to deploy to CloudProvider or CDN
# Inspired by
namespace :deploy do
namespace :assets do
desc <<-DESC
Precompiles assets locally. If you are using AssetSync, it should send them
to the cloud automatically.
task :precompile, roles: :web do
# i keep this in so that it triggers login at the beginning of the process
from = source.next_revision(current_revision)
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
desc <<-DESC
Sync assets to the cloud via Asset Sync. Must be run remotely(so it pulls remote aws credentials)
and after code is deployed so it gets proper asset manifest to sync
task :sync, roles: :web do
run("cd #{latest_release} && /usr/bin/env rake assets:sync RAILS_ENV=production")
desc <<-DESC
[internal] Updates the symlink for assets
task :symlink, roles: :web do
run ("rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.