Skip to content

Instantly share code, notes, and snippets.

@richpeck
Created August 23, 2017 15:13
Show Gist options
  • Save richpeck/12da5be0d105029d26798b202b7c5564 to your computer and use it in GitHub Desktop.
Save richpeck/12da5be0d105029d26798b202b7c5564 to your computer and use it in GitHub Desktop.
Post Receive Hook
#!/usr/bin/env ruby
# REF => https://gist.github.com/karmi/442106#file-post-receive-deploy-rb-L21
###################################################
# === CONFIGURE THE SCRIPT HERE ================= #
deploy_branch = 'master' #=> change to production
git_path = Dir.pwd
application_path = File.dirname(git_path) + "/current"
# =============================================== #
INPUT = STDIN.read.strip
old_revision,
new_revision,
branch = INPUT.split(' ')
# =============================================== #
if branch =~ Regexp.new(deploy_branch)
DEPLOY =<<-END
(
unset GIT_DIR \
&& \
git --work-tree=#{application_path} --git-dir=#{git_path} checkout -f
)
END
# => unset GIT_DIR to fix "fatal . not a git repo" errors
# => http://stackoverflow.com/a/4100577/1143732
BUNDLE =<<-END
(
unset GIT_DIR \
&& \
cd #{application_path} \
&& \
bundle install \
&& \
rake assets:precompile
)
END
RESTART =<<-END
(
touch #{application_path}/tmp/restart.txt
)
END
puts "Updating application code..."
system DEPLOY
puts "Bundling App..."
system BUNDLE
puts "Restarting application..."
system RESTART
end
# =============================================== #
# =============================================== #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment