Created
March 22, 2012 22:59
-
-
Save tedsparc/2165293 to your computer and use it in GitHub Desktop.
Github post-receive hook for auto-deployment of a Web site document root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "sinatra" | |
require "json" | |
# Configure this with the directory path for the Web server's clone of the Git repo | |
git_dir = '/var/www/origin.git' | |
# Configure the mappings between Git branches and Web document roots | |
branch_to_working_directory = { | |
'www' => '/var/www/www.example.com', | |
'staging' => '/var/www/staging.example.com/', | |
'dev' => '/var/www/dev.example.com/' | |
} | |
post '/' do | |
push = JSON.parse(params[:payload]) | |
ref = push['ref'] || raise("ref required in payload") | |
branch = ref.match(/([^\/]+)$/)[0] | |
work_dir = branch_to_working_directory[branch] | |
warn "Got Github hook for ref #{ref}, branch #{branch}, work_dir #{work_dir}" | |
system "git --git-dir=#{git_dir} --work-tree=#{work_dir} add ." | |
system "git --git-dir=#{git_dir} --work-tree=#{work_dir} fetch" | |
system "git --git-dir=#{git_dir} --work-tree=#{work_dir} reset --hard -q origin/#{branch}" | |
'' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment