RailsPlayground
How To Use Capistrano with your svnrepository repository
The following is a simple example of using Capistrano with RailsPlayground using the svn repository on yourdomain.svnrepository.com.
- We assume the SVN repository is created using the svn control panel on domain.svnrepository.com.
- On Windows you will need SVN installed.
- You can download it here for your OS.
- First you will need to create the initial directory structure in your SVN repository. This can be done using svn from your local machine:
svn mkdir http://domainname.svnrepository.com/svn/application/trunk
svn mkdir http://domainname.svnrepository.com/svn/application/branches
svn mkdir http://domainname.svnrepository.com/svn/application/tags
- Import a Rails application from your local application into the repository.
svn import local_application_path http://domainname.svnrepository.com/svn/application/trunk
- Install capistrano on your local machine
gem install capistrano
capify /full/path/to/railsapp
- Create a subdirectory applicationdir in the homedir on the server for the application releases.
- Create a file called deploy.rb in the /config directory of your local rails application.
- The contents of the file should look like this.
set :user, 'username'
set :scm_username, "svnusername"
set :scm_password, "your_password"
set :svnserver, "base_url_for_svn_server"
set :server, 'domainname.com'
set :application, 'application'
set :applicationdir, 'yourapplicationdir'
set :repository, "http://#{svnserver}/svn/#{application}/trunk"
role :web, server
role :app, server
role :db, server, :primary => true
set :deploy_to, "/home/#{user}/#{applicationdir}"
task :restart, :roles => :app do
end
task :after_update_code, :roles => [:web, :db, :app] do
run "chmod 755 #{release_path}/public -R"
end
- Run the following command locally to setup capistrano on the railsplayground server.
cap deploy:setup
- Now you can deploy your app by using the following command
The first time you should run a cold deploy which will also run any database migrations.
cap deploy:cold
After then you should use
cap deploy
- The final step is to let apache know where your new application is
- If you want this to work on your root domain, perform the following on your RailsPlayground server.
rm -rf public_html
ln -s ~/applicationname/current/public ~/public_html
- If you are deploying on a subdomain or add-on domain
cd ~/public_html
rm -rf subdomainname
ln -s ~/applicationname/current/public ~/public_html/subdomainname
Common Problems
- Make sure your dispatch.cgi/dispatch.fcgi file has the correct shebang line. It should look like this:
#!/usr/bin/env ruby
- Make sure you edit your database.yml and it is pointing to the correct database.
- You can make any post deployment modifications to your projectfiles using embedded OS commands in the :after_update_code block in the deploy.rb
- Don’t presume that the username you use to administrate your svnrepository.com repository has access to the actual repository you are deploying from. If you want to use the same username and password, make it a user of your repository account, and give it access to the repository you are deploying.
Tips
- RailsPlayground servers don’t have the RAILS ENV environment variable set, which means that the “development” configuration is used by default. If this isn’t what you want, this can be fixed by automatically uncommenting the existing ENV[‘RAILS_ENV’] ||= ‘production’ in the environment.rb file once deployment is complete (assuming that you haven’t removed it), e.g. by adding the following task to the deploy.rb suggested above:
task :after_deploy, :roles => [:web] do
run "sed -e \"s/^# ENV/ENV/\" -i #{release_path}/config/environment.rb""
end
Revised on January 29, 2009 17:37:14
by
samy?
(88.173.113.249)
(3960 characters / 1.0 pages)