Question

Here I received a solution to my problem that every time when I deploy my Spree Commerce app with Capistrano my images are removed (they are still there, but the folder names are wrong) and I have to add them again via admin.

Both on this Google group and in the answer to the question it is said that symlinking is solution.

You need to make sure that your RAILS_ROOT/public/spree directory is being symlinked in from the Capistrano shared directory and not recreated every time you deploy. If this symlink isn't happening, your images will be lost on every deploy.

I've tried a few things but I do not manage to symlink my images.

On the server they are in the folder /public/spree/products. What I tried is this:

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :symlink_shared do
     run "ln -nfs #{shared_path}/shared/spree/ #{release_path}/public/spree/""
  end
end

but this does not work. I do not know which shared path I have to enter. I hope someone can help me out or provide a link with explanation.

Was it helpful?

Solution

If you are using Capistrano 3 you can use the same method I explained in the answer to my own question here.

In essence, :shared_children was how you'd do it in Capistrano 2, but it was removed in favor of :linked_files and :linked_dirs.

Just create your public/spree/ directory in your repository, add it to .gitignore if you need to (it doesn't matter if they're tracked or not by Git), then edit your deploy.rb to use :linked_dirs:

set :linked_dirs, %w(public/spree)

This way, when Capistrano deploys it'll automatically create the directory in shared/ and link it into your current release. Please keep in mind that if you need files to be present in that directory you have to copy them to shared/ manually, using a tool like rsync. The same goes for files like database.yml (for which you'd use :linked_files).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top