Our development process makes us deploy very often. As the number of releases grows, junk clogs up the hard drive of our application servers:
tmp
folders with compiled view templates etc.public/assets
directory to shared/assets
. This is cool since we can still serve previous assets after a new release, in the window where browser caches might still have references to old assets. But it also means that our public/assets
folder contains every asset we ever compiled.Eventually your hard drive will run out of disk space because of all that junk. You should frequently remove old releases and assets from your application servers.
As you are lazy (as every developer) you should make Capistrano do this for you.
For Capistrano 3 deploy:cleanup
is invoked by default (see
official Documentation
Show archive.org snapshot
). However, it only cleans up releases, not assets.
In order to clean up assets, you can use
capistrano-rails
Show archive.org snapshot
. Just require 'capistrano/rails'
in Capfile and add the following config:
# config/deploy.rb
set :keep_assets, 10
This will keep 10 versions of each asset and remove any older versions.
:keep_assets
invokes rake assets:clean[n]
, which
in Rails 3 is an alias to assets:clean:all
, which will remove the assets directory altogether
Show archive.org snapshot
. Either let assets accumulate (which should not be too bad), or implement a custom solution. You may use
the original Capistrano 2 implementation of asset expiry
Show archive.org snapshot
, which was more sophisticated, for inspiration.Open config/deploy.rb
and add this line to the block at the end of the file:
after "deploy:restart", "deploy:cleanup"
Next time you deploy, you will see outlook like this:
** keeping 5 of 27 deployed releases
* executing "rm -rf /path/to/your/releases/directory/..."
** Removing unneeded asset: redmond/images/ui-icons_2e83ff_256x240.png
** Removing unneeded asset: redmond/images/ui-icons_469bdd_256x240-71745de572282e54f00e292afcac7c61.png
** Removing unneeded asset: redmond/images/ui-icons_469bdd_256x240.png
** Removing unneeded asset: redmond/images/ui-icons_6da8d5_256x240-b36f41d94dfba34ce462968f952ec333.png
By default, Capistrano keeps the 5 most recent releases and all assets that have been deployed in the last week.
You can manually trigger the cleanup and also change the default value of 5 releases to keep. Details are described here: Capistrano: Delete old releases