Skip to content

Instantly share code, notes, and snippets.

@nickwhitt
Created November 2, 2012 13:22
Show Gist options
  • Save nickwhitt/4001342 to your computer and use it in GitHub Desktop.
Save nickwhitt/4001342 to your computer and use it in GitHub Desktop.
Capistrano

Development Machine

Install Capistrano with Railsless Deploy

$> sudo gem install capistrano railsless-deploy

Copy ssh keys to production

$> scp ~/.ssh/id_rsa.pub production:/tmp/id_rsa.developer.pub

Production Server

Create deployment user and ssh public key

$> sudo adduser deploy
$> su deploy
$> ssh-keygen

Copy each developer's public key to deployment's authorized_keys file

$> cat /tmp/id_rsa.developer_1.pub >> ~/.ssh/authorized_keys
$> cat /tmp/id_rsa.developer_2.pub >> ~/.ssh/authorized_keys
...

Test with ssh deploy@production for each developer

Copy public key to version control server

$> scp ~/.ssh/id_rsa.pub git-server:/tmp/id_rsa.deploy.pub

Version Control Server

Create git (or svn) user

$> sudo adduser git
$> su git
$> cd
$> mkdir .ssh

Copy deployment user's public key

$> cat /tmp/id_rsa.deploy.pub >> ~/.ssh/authorized_keys

Extra security? Replace git user's shell tool with /usr/bin/git-shell in /etc/passwd

$> ssh git@git-server
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to git-server closed.

Capify Project

$> cd project/directory
$> capify .

Replace the newly created Capfile contents with the code below, and update the deploy script with your custom values.

Setup and Check Dependencies

$> cap deploy:setup
$> cap deploy:check

To Deploy

$> cap deploy
require "rubygems"
require "railsless-deploy"
load "config/deploy"
set :application, "project"
# Version Control
set :scm, :git
set :repository, "git@git-server:/git/repository/#{application}.git"
set :branch, "master"
set :deploy_via, :remote_cache
set :git_enable_submodules, 1
set :copy_exclude, ["Capfile", "config/deploy.rb", ".git", ".gitignore", ".gitmodules"]
# -Or- Subversion?
#set :repository, "svn+ssh://svn@server/svn/repo/#{application}/trunk"
#set :deploy_via, :remote_cache
#set :copy_exclude, ["Capfile", "config/deploy.rb", ".svn"]
# Production Server
server "www.production.com", :web
set :user, "deploy"
set :deploy_to, "/var/www/#{application}"
set :use_sudo, false
# Assume we have a shared settings file
after "deploy:symlink" do
run "ln -fs #{shared_path}/settings.php #{release_path}/config/settings.php"
end
# Cleanup
set :keep_releases, 5
after "deploy:update", "deploy:cleanup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment