12
2008
Just put up a new website for a friend of mine who has just started a new classic car business Gasoline Alley. He already has a nice collection of mercs like this excellent 450 slc.
This is a ruby on rails based site which uses attachment_fu and rmagick to manage and re-size the images uploaded onto the site. The site design is basic but the underlying code allows the end user to manage most is the content themselves and the rails framework made it possible to develop a flexible dynamic site within an extremely limited budget, more design and content will be added as time and money allow.
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!
02
2008
I was trying to install the rmagick gem and got the following error:
dev-01:~$ sudo gem install rmagick
Building native extensions. This could take a while…
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension./usr/bin/ruby1.8 extconf.rb install rmagick
checking for Ruby version >= 1.8.2… yes
checking for cc… yes
checking for …
etc.
This happens when the necessary libries are missing, I had installed the imagemagick package but this doesn’t include the dev libraries so I need to do :
dev-01:~$ sudo apt-get install libmagick++9-dev
after it completes, try again:
dev-01:~$ sudo gem install rmagick
Building native extensions. This could take a while…
Successfully installed rmagick-2.7.1
1 gem installed
Which is what I wanted.
30
2008
When you try and install the native mysql gem you get:
>sudo gem install mysql
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
checking for mysql_query() in -lmysqlclient… no
/usr/bin/ruby1.8 extconf.rb install mysql
blah..blah…and it fails.
Most likely you installed the mysql server package but you also need to install the mysql client development libraries (check the name of the latest package):
sudo apt-get install libmysqlclient15-dev
Now try again:
>sudo gem install mysql
Successfully installed mysql-2.7
1 gem installedBuilding native extensions. This could take a while…
That’s better.
30
2008
Assumptions:
Capistrano is installed
You are using a Capistrano supported version control system
You are using Ruby on Rails as the application framework and it is all installed and working
- First you need to create the Capistrano configuration files by moving to the root of you rails application and typing ‘capify .‘ (include the space and dot) this created the Capfile in the root and deploy.rb in the config directory
- Edit deploy.rb to set up Capistrano for your application: you will need to change or set the following values:
- set :application, “myNewApplication” #put your application name here – this is the directory your app will end up in
- set :repository, “pathToYourRepository” #this can be a local full file path eg ‘/home/me/repository/myNewApplication’ or a path to an external repo ‘bzr+ssh://me@example.com/repo/myNewApplication’
- set :scm, :bzr #set this to :bzr, :git etc as appropriate if you are not using subversion
- set :deploy_to, “/var/www” #set this to the directory you want your apps to land in, the application name listed above will be created as a sub directory of this one
- role :app “myserver.example.com” #set this to the domain name of your server, it is used to connect to your server so it must resolve to the ip of the server
- role :web “myserver.example.com”
- role :db “myserver.example.com” , :primary =>true
- ssh_options[:port] = 20000 #if you are not using the standard ssh port (22) you must specify the correct value here
- set :user, “me” #if you use a different username to log into the remote machine you need to specify it here
- set :use_sodu, false #you will probably want to use this else everything will be owned by root and the application probably won’t run, I found this did not for cap deploy:setup
- Set up the directory structure by running ‘cap deploy:setup‘
- Check the app skeleton by running ‘cap deploy:check‘ you may need to change the owner for the directories created above
- Deploy your app with ‘cap deploy:update‘ if everything went OK the app will be deployed from the repository to the application directory structure
You still need to create and deploy the database and start the application itself, you can use Capistrano and rake tasks do these things.


