Search code examples
ruby-on-railsrubycapistranopassengercarrierwave

Keep uploads directory under public while deploying new revisions using capistrano


I have a Rails app and using Apache2 + Passenger + Capistrano on production server:

.
├── current -> releases/20150527234152
|   ├── app
|   ├── db
|   ├── lib
|   ├── ...
|   └── public
|       ├── assets
|       └── uploads
|           ├── 01.jpg
|           ├── 02.jpg
|           ├── 03.jpg
|           └── ...
├── releases
|   ├── 20150527212555
|   ├── 20150527230415
|   └── 20150527234152
├── repo
└── shared

I am not tracking the public/uploads directory (Where images are being uploaded by users). So whenever I do cap production deploy, the current links to the new version which won't have the uploads directory anymore. I am using carrierwave gem for image upload.

The only solution I can think of is to have capistrano run a script after deploying that moves the directory from older to latest revision.

Or

Have the uploads directory outside of the app. (If so, what's the best/safest location for it?)

I want to know which solution is better, or if there is a better option.

Cheers


Solution

  • The method you are looking for is called linked_dirs.

    It accepts an Array of directories and will create a symlink to the directories specified across each successive deployment works well for directories that should persist even when other code is updated as is your case for uploads.

    When you deploy what it does is it runs deploy:check:linked_dirs to confirm that the path exists and/or creates it. Then it runs deploy:symlink:linked_dirs which creates a symlink to this directory.

    You can find it in the Official Documentation. The Rake Tasks can be Found Here