A Capistrano 3 plugin to deploy Ruby on Rails apps faster.
The standard way to deploy Rails apps which make use of the Asset Pipeline is to
have Capistrano call rake assets:precompile
as part of the deploy. This has
three problems.
- The precompile task can get very slow.
- Very few deploys will actually change any assets
- Not all servers need a copy of assets (e.g. workers that don't server http requests; sometimes not all app-servers, depending on routing), but all apps probably will need a copy of the manifest.yml that is generated by assets:precompile.
The fast-assets plugin speeds up deploys in two ways.
- Assets are only compiled if a change to asset-ish locations has been made
- Assets are only compiled on nominated servers and the manifest.yml file is then copied to other servers.
Require capistrano3-fast-assets
in your Gemfile
Require capistrano/fast-assets
in your Capfile.
Attachs to deploy:after
. Any change between the currently deployed revision
and the next deployed revision should trigger a full recompile of assets. If it
doesn't, or you want to force the issue set FORCE_COMPILE=1
as part of the
deploy.
set :asset_manifest_path, "config/manifest.yml"
set :asset_locations, ["app/assets", "lib/assets", "vendor/assets", "Gemfile.lock"]
set :asset_compiler_role, :asset_compiler
set :rails_env, fetch(:rails_env) || fetch(:stage)
- Not compatible with Capistrano 2.
- Probably not compatible with the official capistrano-rails gem
- Only compatible with git as SCM.
- We don't use the default public/assets/manifest.yml location. We store the manifest in config/ so that each deploy retains a copy and never overwrites a shared manifest.yml.
- We symlink shared/public/assets to current/public/assets. This means that all previous assets remain available for future deploys. This is considered a feature, not a bug. Anyone looking at a cached page or old HTML email should still be able to fetch the original assets from that revision.
- This was build very much as an in-house tool, YMMV.