Creating and Managing Shared Areas
Capistrano has an in built mechanism for sharing areas and files between different releases of a Rails application on the same machine. The Brightbox gem takes that facility, makes it generally available and extends it so that assets can be shared effortlessly across machines. Any file or directory can be shared between releases simply by including it in the appropriate list.
Setting up the shared area
Shared area management is handled with two Capistrano variables:
:global_shared_files. Within the
config/deploy.rb file, locate the Global Shared Area section and uncomment the relevant lines.
If you want to create a shared directory area (such as an upload area for assets), add the directory name to the list, e,g:
set :global_shared_dirs, %w(public/assets public/images/uploads)
Similarly to create a shared file, add the name of the file to the list.
set :global_shared_files, %w(config/database.yml config/activemerchant.yml)
Note that all the directories and filenames are expressed relative to the root of the Rails application
You can create the shared directory structure by re-running setup, e.g.
Changing the location of the shared area
By default the system creates the directories and files in the
shared area within your application. If you are using shared files, you will need to copy the files into the shared area manually.
However if you have multiple application machines you may want to store the shared assets on a network drive linked on every machine. You can change the directory where assets are stored using the
global_shared_path variable: e.g.
set :global_shared_path, "/srv/share/myapp"
Using the shared directories and files
Now when you deploy your application, the gem recipes will automatically create symbolic links to your shared directories and files.
Using the Local shared area
If you setup the
global_shared_path, you can still create files and directories that are only shared between releases on a particular machine by using the
Note that local shared files and directories will override the global ones if they have the same name and path.