Skip to content

Instantly share code, notes, and snippets.

@karmi
Created June 17, 2010 13:21
Show Gist options
  • Save karmi/442106 to your computer and use it in GitHub Desktop.
Save karmi/442106 to your computer and use it in GitHub Desktop.
Example script to deploy a Rails application via Git post-receive hook
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment