Services Spotlight:

How To Add A New Folder To The Shared Directory In Capistrano 2.15.5

Written By Corlew Solutions
Updated February 1, 2014
Published January 17, 2014
Why Corlew Solutions?

We write great software and provide amazing technical support. Contact us today if you need help with a software project:

  • Website: Send an inquiry
  • Email:
  • Phone: (703) 688-3058

Article Technology Info

This article discusses the following technologies:

If you are using Capistrano to manage the deployments of your web application, at some point, you may have some new files for Capistrano to preserve between releases. Out of the box, Capistrano does this for our log folder/files and assets (among other things) in a Ruby on Rails application, but what if we need to make Capistrano aware of a new folder?

We recently ran into this problem when we started using the CarrierWave gem to process user uploads. Having created a new public/uploads folder to store the user uploads, we needed someway for those uploads to persist between releases. Fortunately, we found a simple solution over at astonj.com that worked flawlessly on Capistrano 2.15.5. We have represented the solution and added some minor details.

Update deploy.rb

Open up deploy.rb and add the following line:

config/deploy.rb
1
set :shared_children, shared_children + %w{public/uploads}

This single line does all the magic. It tells Capistrano to store public/uploads in the shared folder and create a symlink to it.

Apply Changes

Now that we have changed Capistrano’s configuration, apply the change by running:

1
cap deploy:setup

According to the docs on Capistrano’s GitHub page, this command is safe to run on existing servers:

[cap deploy:setup] prepares one or more servers for deployment. … It is safe to run this task on servers that have already been set up; it will not destroy any deployed revisions or data.

Update .gitignore

Open up the .gitignore file and add the following line so Git does not try and track files in the new folder. 

.gitignore
1
/public/uploads

Note: CarrierWave uses a tmp folder to do some image manipulation. You may need to add that folder to the .gitignore file as well if it exists outside of /public/uploads.

If the directory has already been added to Git, it will need to be removed. This can be accomplished via:

1
git rm -r --cached public/uploads

This will not affect your working directory due to the –cached option.

Deploy

When ready, commit your code to Git, push to your repository and then run cap deploy or cap deploy:migrations. Your new shared directory should be properly managed by Capistrano.

We hope you found this article useful. If you see any mistakes, missing features or ways to improve it, please let us know in the comments below so we can update its contents. If you're willing to link to us, we would sincerely appreciate it!

References

Further Reading

Corlew Solutions is a Web Design and Web Application Development company based in Fairfax Virginia, minutes away Washington D.C. If you're looking for great web design from the Northern Virginia area or web design from the Washington D.C. area we can help. Contact Us today!

comments powered by Disqus