Jan 22, 2011

Automated deployment setup (Capistrano)

It is really tricky in order to automate the deployment. First, install Capistrano on your local machine:

gem install capitrano

then,

capify /project_dir

It will create a file deploy.rb under config folder. Now make it look like this:

set :application, "CollegeSwap"
set :domain, "72.26.225.10"
set :repository, "git@github.com:tanin47/CollegeSwap.git"

set :use_sudo, false
set :deploy_to, "/#{application}"
set :scm, "git"

set :user, "deploy"

set :branch, "master"

role :app, domain
role :web, domain
role :db, domain, :primary => true

# If you are using Passenger mod_rails uncomment this:
# if you're still using the script/reapear helper you will need
# these http://github.com/rails/irs_process_scripts

namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end

Now go to your server and clone the project. On the local computer, you can type 'cap deploy' to re-deploy the project.

There will be some issue about permission. You can try setting the deploy user and nignx user to be the same user. That's probably the simplest way.

Or you can set them to be in the same group. Give the access to the group instead by 'chown -R :nginxgroup /CollegeSwap'.

Then, you need to type 'chmod g+s /CollegeSwap'; every file created under this dir will inherit permission from its parent.

And that's it. you're good to go.

One last thing, do not forget to 'chmod -R 777 /CollegeSwap'