Nov
07
2008

I have a number of rails applications that allow the user to create and edit dynamic content i.e. a shop/store front. I am using bazzar and Capistrano for source control and deployment which works fine except that out of the box this was overwriting the end user uploads etc on the site each time the code was updated.

The first and obvious thing I did was remove these directories and files from bazaar:

bzr -rm ./public/uploads –keep

and then add an entry to the bzr ignore file

bzr ignore ./public/uploads

commit the changes and deploy the app

bzr push …

cap deploy

Hmm everything in the uploads directory has gone, not really the desired result. This content needs to be moved to the shared directory (or other convenient place) and linking with the current live site. So after creating the directory within the webroot/shared directory and moving the content into it, I need to create a symbolic link from the live site to the content. This link will need to be recreated each time I update the application so I need to add it to my Capistrano recipe:

task :after_deploy do
# recreate the link to the upload dir
run “ln -s /var/www/example.com/shared/uploads /var/www/example.com/current/public/uploads”
#put someother tasks we need to do here
passenger:restart
end

This looks fine but when I run it the site deploys ok but no link is created because :after_deploy isn’t being called. On close inspection of the Capistrano output:

*** [err :: dev-01.local] sudo: /var/www/example.com/current/script/process/reaper: command not found

although the file is actually present. The file permissions are wrong and it won’t execute (solution to this towards the end of this article) and then :after_deploy is not called. So I had to add an additional task to the recipe:

task :after_update_codeĀ  do
run “chmod +x #{release_path}/script/process/reaper”
run “chmod +x #{release_path}/script/process/spawner”
end

retest it and finally it all works!

0 Comments

You must be logged in to post a comment.