I have a Rails app which requires the client to upload image files to
a certain directory.
I’m using capistrano to deploy and have created a directory in shared:
shared/book_images
I want to symlink this to my_rails_app/public/images/book_images and
have this task in my deploy.rb file:
desc “Link to the book images directory where uploads go”
task :after_symlink do
run “ln -nfs #{shared_dir}/book_images
#{release_path}/public/images/book_images”
end
However, iif I ssh into the current release, I see that the symlink
above is incorrect: the symlink to the shared book_images directory is inside of public/images/book_images
that is, I end up with public/images/book_images/book_images
Any clues on how to resolve this would be appreciated.
that is, I end up with public/images/book_images/book_images
Any clues on how to resolve this would be appreciated.
Does your release_path/public already contain an images/book_images
directory before you symlink? I seem to remember having a similar
problem and it was because I already had a public/photos directory in
subversion and so when I deployed the app and then tried to link
public/photos to shared/photos, I remember something screwy happening.
My quicky hack workaround was to delete the real directory before I did
the symlink, i.e.:
task :after_update_code, :roles => :app do
run “rm -rf #{release_path}/public/photos”
run “ln -nfs #{shared_path}/photos #{release_path}/public/photos”
end
HTH,
Jamey
Confidentiality Notice: This email message, including any attachments,
is for the sole use of the intended recipient(s) and may contain
confidential and/or privileged information. If you are not the intended
recipient(s), you are hereby notified that any dissemination,
unauthorized review, use, disclosure or distribution of this email and
any materials contained in any attachments is prohibited. If you receive
this message in error, or are not the intended recipient(s), please
immediately notify the sender by email and destroy all copies of the
original message, including attachments.
Upon closer inspection, the sylink is created fine, but for some
reason I can’t access the symlinked directory. It’s permissions are
the same as other directories but if I try and cd into it, I get ‘no
such file or directory’.
I do the same thing and it looks like this in my config/deploy.rb :
desc “Create the #{shared_dir}/files/production|development|test dirs "
+
“if they don’t exists and add symlink to #{shared_dir}/files from
" +
“the current release path”
task :symlink_files_dir, :roles => :app do
[‘production’,‘development’,‘test’].each do |env|
run “mkdir -p #{shared_path}/files/#{env}” unless
File.exists?(”#{shared_path}/files/#{env}”)
end
change owner and permission of files
sudo “chown --recursive #{user}:#{apache_group} #{shared_path}/files”
sudo “chmod --recursive 774 #{shared_path}/files”
run “mv #{release_path}/files #{release_path}/files.local”
run “ln -s #{shared_path}/files #{release_path}/files”
end
desc “Do these tasks after you update the code”
task :after_update_code do
symlink_files_dir
end