
Setting up A Rails App with git & Capistrano on Dreamhost
Howto's for Getting an Initial Rails app setup on dreamhost with both Git and Capistrano for easy deployment and easy version control
This list is not exhuastive, but will work.
Create the domain (or subdomain) on dreamhost, and select passenger for rails setup. Also change the web directory from /public to /current/public.
Also setup the databases, and note the hostname
Create the rails app
rails myapp cd myapp
Create a git repo
git init touch temp/.gitignore log/.gitignore vendor/.gitignore
Setup a gitignore for the entire repo
vim .gitignore
.DS_Store log/*.log tmp/**/* config/database.yml db/*.sqlite3
Add files to repo
rm public/index.html git add . git commit -m "Initial Setup"
Make a clone of the repo to push to dreamhost
cd .. git clone --bare myapp/.git myapp.git scp -r myapp.git user@dreamhost:/home/user/repos cd myapp git remote add web user@dreamhost:/home/user/repos/myapp.git git fetch web
Configure your database.yml file
vim config/database.yml
# SQLite version 3.x # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: mysql encoding: utf8 database: myapp_production username: yourdbuser password: yourdbpassword host: mysql.myhost port: 3306
Dreamhost shell setup
Setup a Shared directory for database config that shouldn't be in the git repo
ssh user@dreamhost mkdir myapp/shared exit
scp config/database.yml user@dreamhost:/home/user/myapp/
Capistrano
capify . vim config/deploy.rb
set :application, "myapp"
set :repository, "user@dreamhost:/home/user/repos/myapp.git"
set :user, "user"
set :domain, "dreamhost"
set :scm, :git
set :scm_command, "~/packages/bin/git" #updated version of git on server in user directory
set :local_scm_command, "/opt/local/bin/git" #correct path to local git
set :applicationdir, "/home/jnanney/mls.hugewaste.com"
# deploy config
set :deploy_to, applicationdir
set :deploy_via, :remote_cache
# additional settings
set :chmod755, "app config db lib public vendor script script/* public/disp*"
set :use_sudo, false
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
# role :db, "your slave db-server here"
namespace :deploy do
desc "Tell Passenger to restart the app."
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
desc "Symlink shared configs and folders on each release."
task :symlink_shared do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/assets #{release_path}/assets"
end
desc "Sync the public/assets directory."
task :assets do
system "rsync -vr --exclude='.DS_Store' public/assets #{user}@#{application}:#{shared_path}/"
end
end
after 'deploy:update_code', 'deploy:symlink_shared'
Commit Capistrano files to the repos
git add Capfile config/deploy.rb git commit -a -m "Capified for dreamhost" git push web
Deployment
cap deploy:setup cap deploy:check cap deploy:cold

