vagrant@testing:~$ mkdir push-to-deploy
vagrant@testing:~$ cd push-to-deploy/
vagrant@testing:~/push-to-deploy$ mkdir {dev,remote,deploy}
vagrant@testing:~/push-to-deploy$ ls
deploy dev remote
vagrant@testing:~/push-to-deploy$ cd remote/
vagrant@testing:~/push-to-deploy/remote$ git init --bare
Initialized empty Git repository in /home/vagrant/push-to-deploy/remote/
vagrant@testing:~/push-to-deploy/remote$ cd ..
vagrant@testing:~/push-to-deploy$ cd dev/
vagrant@testing:~/push-to-deploy/dev$ git init
Initialized empty Git repository in /home/vagrant/push-to-deploy/dev/.git/
vagrant@testing:~/push-to-deploy/dev$ echo "holi mundo" >> prueba.txt
vagrant@testing:~/push-to-deploy/dev$ git add prueba.txt
vagrant@testing:~/push-to-deploy/dev$ git commit -m 'first commit'
[master (root-commit) 3d581c7] first commit
1 file changed, 1 insertion(+)
create mode 100644 prueba.txt
vagrant@testing:~/push-to-deploy/dev$ git remote add production ../remote/
vagrant@testing:~/push-to-deploy/dev$ git push production master
Counting objects: 3, done.
Writing objects: 100% (3/3), 227 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ../remote/
* [new branch] master -> master
vagrant@testing:~/push-to-deploy/dev$ cd ../remote/
vagrant@testing:~/push-to-deploy/remote$ ls
branches config description HEAD hooks info objects refs
vagrant@testing:~/push-to-deploy/remote$ cd hooks/
vagrant@testing:~/push-to-deploy/remote/hooks$ ls
applypatch-msg.sample post-update.sample pre-commit.sample pre-rebase.sample
commit-msg.sample pre-applypatch.sample prepare-commit-msg.sample update.sample
vagrant@testing:~/push-to-deploy/remote/hooks$ vim post-receive
#!/usr/bin/env ruby
from, to, branch = ARGF.read.split " "
if (branch =~ /master$/) == nil
puts "Branch enviada #{branch}, no habrá deploy"
exit
end
deploy_to_dir = File.expand_path('../deploy')
`GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master`
puts "DEPLOY: master(#{to}) deployed to '#{deploy_to_dir}'"
Toques finales al hoook:
vagrant@testing:~/push-to-deploy/remote/hooks$ chmod +x post-receive
vagrant@testing:~/push-to-deploy/remote/hooks$ cd ../../dev/
vagrant@testing:~/push-to-deploy/dev$ echo "Prueba del deploy" >> prueba.txt
vagrant@testing:~/push-to-deploy/dev$ git add prueba.txt
vagrant@testing:~/push-to-deploy/dev$ git commit -m 'primera prueba del deploy'
[master 8e97c9a] primera prueba del deploy
1 file changed, 1 insertion(+)
vagrant@testing:~/push-to-deploy/dev$ git push production master
Counting objects: 5, done.
Writing objects: 100% (3/3), 284 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
remote: Already on 'master'
remote: DEPLOY: master(8e97c9ae0dd2bb382253cae1fcd4e05b4366349a) deployed to '/home/vagrant/push-to-deploy/deploy'
To ../remote/
3d581c7..8e97c9a master -> master
Listo el deploy. Verificamos:
vagrant@testing:~/push-to-deploy/dev$ ls ../deploy/
prueba.txt
vagrant@testing:~/push-to-deploy/dev$