How do I symlink my product images in production on a Capistrano deploy?

假装没事ソ 提交于 2019-12-23 21:30:18

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/21837690/how-do-i-symlink-my-product-images-in-production-on-a-capistrano-deploy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!