Last active
January 19, 2016 12:39
-
-
Save PLaRoche/4ec72f91cf6521ea73a3 to your computer and use it in GitHub Desktop.
git post receive hook for a laravel app
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
#!/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