Created
April 15, 2016 22:03
-
-
Save aapis/ad8affec92991fa7f8db9875c01da6e0 to your computer and use it in GitHub Desktop.
post-receive hook for automatic git deployments
This file contains hidden or 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
| #!/home/git/.rvm/rubies/ruby-2.3.0/bin/ruby | |
| puts "Hello world!" | |
| # 1. Read STDIN (Format: "from_commit to_commit branch_name") | |
| from, to, branch = ARGF.read.split " " | |
| # 2. Only deploy if master branch was pushed | |
| if (branch =~ /master$/) == nil | |
| puts "Received branch #{branch}, not deploying." | |
| exit | |
| end | |
| # 3. Copy files to deploy directory | |
| deploy_to_dir = File.expand_path('/var/www/vhosts/api.server') | |
| `GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master` | |
| puts "DEPLOY: master(#{to}) copied to '#{deploy_to_dir}'" | |
| # 4.TODO: Deployment Tasks | |
| # i.e.: Run Puppet Apply, Restart Daemons, etc | |
| puts "You're a STAR" | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Idea: when pushing a branch that isn't master, change to this branch before deploying. Whatever you push becomes the live branch.