Jump start a Rails project with Rails Edge, Capistrano, Mongrel and Mercurial
1 # Create a Rails project 2 rails project -d sqlite3 3 cd project 4 # Delete index file 5 rm public/index.html 6 # Use Rails edge. Use rake rails:freeze:edge TAG=rel_1-2-3 to get a specific version. 7 rake rails:freeze:edge 8 # Add Capistrano configuration file 9 capify . 10 # Add Mongrel cluster configuration file 11 sudo mongrel_rails cluster::configure -e production \ 12 --user mongrel --group mongrel \ 13 -c /var/www/project-xxx/current \ 14 -a 127.0.0.1 \ 15 -p 8000 \ 16 -N 3 17 # Create a Mercurial repository 18 hg init 19 # Add project to repository 20 hg commit -A --message "Project started" 21 # Push changes to a remote repository 22 hg push ssh://user@ip:port//var/mercurial/xxx
Cloning is done with hg clone:
1 hg clone ssh://user@ip:port//var/mercurial/xxx
Capistrano 2 task for backing up your MySQL production database before each deployment
This Capistrano task connects to your production database and dumps the contents to a file. The file is compressed and put in a directory specified with set :backup_dir, ”#{deploy_to}/backups”. This is a slight modification of http://pastie.caboo.se/42574. All credit to court3nay.
1 task :backup, :roles => :db, :only => { :primary => true } do 2 filename = "#{backup_dir}/#{application}.dump.#{Time.now.to_f}.sql.bz2" 3 text = capture "cat #{deploy_to}/current/config/database.yml" 4 yaml = YAML::load(text) 5 6 on_rollback { run "rm #{filename}" } 7 run "mysqldump -u #{yaml['production']['username']} -p #{yaml['production']['database']} | bzip2 -c > #{filename}" do |ch, stream, out| 8 ch.send_data "#{yaml['production']['password']}\n" if out =~ /^Enter password:/ 9 end 10 end
To automatically backup your data before you deploy a new version add this to config/deploy.rb:
1 task :before_deploy do 2 backup 3 end
To restore the backup run the following command:
1 mysql database_name -uroot < filename.sql
Improve page load times by combining JavaScript and CSS files
Add cache => true to combine JavaScript and CSS files and improve page load times.
See changeset 6164 for more information
1 <%= stylesheet_link_tag 'all', :cache => true %> 2 <%= javascript_include_tag :defaults, :cache => true %>