Skip to content

Instantly share code, notes, and snippets.

@PLaRoche PLaRoche/post-receive
Last active Jan 19, 2016

Embed
What would you like to do?
git post receive hook for a laravel app
#!/usr/bin/env ruby
# post-receive
#From: http://krisjordan.com/essays/setting-up-push-to-deploy-with-git
# NOTE: if you have a sudo requires tty you have to change the require tty line in your sudeors file
# Make sure you can write to the dir:
`sudo chown -R ec2-user:ec2-user /var/app/current`
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
from, to, branch = ARGF.read.split " "
# 2. Only deploy if master branch was pushed
# Uncomment to ensure this only happens on master branch
# if (branch =~ /master$/) == nil
# puts "Received branch #{branch}, not deploying."
# exit
# end
# 3. Copy files to deploy directory
#you can change the deploy_to_dir to whatever is needed
#deploy_to_dir = File.expand_path('../deploy')
deploy_to_dir = '/var/app/current/'
`GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f #{branch}`
puts "DEPLOY: #{branch} (#{to}) copied to '#{deploy_to_dir}'"
# 4.TODO: Deployment Tasks
# i.e.: Run Puppet Apply, Restart Daemons, etc
`cd /var/app/current; /usr/local/bin/composer install`
`sudo chown -R webapp:webapp /var/app/current`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.