-
Notifications
You must be signed in to change notification settings - Fork 69
Shared public directories
It's pretty common to have uploaded assets in a Rails application using paperclip, attachment_fu, carrier_wave, etc. One concern with having this in a deployed environment is that files would be uploaded to a directory like:
/srv/your_app/current/public/photos
But here's a problem. You do a deploy, and they go missing. Oh no! /srv/your_app/current points to a particular release, so when you redeploy, you create a new deploy, and the files keep on living in the original release.
Fortunately, we can solve this with shared public directories that get symlinked at deploy time. In moonshine, we can create this in your app/manifests/application_manifest.rb like this:
def shared_directories
file '/srv/your_app/shared/photos', :ensure => :directory,
:owner => configuration[:user],
:group => (configuration[:group] || configuration[:user])
end
recipe :shared_directories
With this in place, we just need to make sure deploys know to symlink that shared_directory into place every deploy. We can do this by updating config/moonshine.yml:
:app_symlinks:
- photos
Now, just deploy, and the initial /srv/your_app/shared/photos will be created by moonshine, and will be symlinked into the latest release. No more missing files!
While writing this up, it occurred to me specifying :app_symlinks should automatically create the shared directories. This would make a create patch to moonshine if someone wants to beat me to it :) - JOsh