#!/usr/bin/env ruby # Example script to deploy a Rails application via Git post-receive hook # # INSTALL # # $ curl http://gist.github.com/442106.txt -o post-receive # $ mv post-receive path/to/to/your/repo.git/hooks/post-receive # $ chmod +x post-receive INPUT = STDIN.read.strip # puts INPUT.inspect # DEBUG # === CONFIGURE THE SCRIPT HERE ================= deploy_branch = 'deploy' application_path = '/www/data/applications/myapp' # =============================================== old_revision, new_revision, branch = INPUT.split(' ') if branch =~ Regexp.new(deploy_branch) DEPLOY_COMMAND =<<-END ( unset GIT_DIR \ && \ cd #{application_path} \ && \ git fetch --quiet \ && \ git reset --hard -q origin/#{deploy_branch} ) END RESTART_COMMAND =<<-END ( touch #{application_path}/tmp/restart.txt ) END puts "Updating application code..." system DEPLOY_COMMAND puts "Restarting application..." system RESTART_COMMAND end