Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep unversioned files when deploying with Capistrano

Everytime I run cap deploy in the remote server I lost some unversioned files because capistrano creates a new directory and checkouts the head revision in it. But there are some files that are not versioned like users avatars (paperclip) and uploaded images which don't get copied to the new current release.

How can I workaround this?

Thanks!

like image 901
empz Avatar asked Jan 10 '11 15:01

empz


2 Answers

Personally, I think the best way to deal with those kind of things is to store them in the shared folder and create a task in capistrano to create symlinks to the shared assets.

Here's an example from one of my projects:

set :shared_assets, %w{public/images/products public/images/barcodes}

namespace :assets  do
  namespace :symlinks do
    desc "Setup application symlinks for shared assets"
    task :setup, :roles => [:app, :web] do
      shared_assets.each { |link| run "mkdir -p #{shared_path}/#{link}" }
    end

    desc "Link assets for current deploy to the shared location"
    task :update, :roles => [:app, :web] do
      shared_assets.each { |link| run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}" }
    end
  end
end

before "deploy:setup" do
  assets.symlinks.setup
end

before "deploy:symlink" do
  assets.symlinks.update
end
like image 191
idlefingers Avatar answered Nov 18 '22 20:11

idlefingers


Adding your paths to shared_children also works and is actually just a one-liner in your deploy.rb:

set :shared_children, shared_children + %w{public/uploads}

found it here: astonj

like image 44
urandom Avatar answered Nov 18 '22 22:11

urandom