1

I've a environment to deploy with git and I don't know how do this. Our team works with several developers hosts (local repositories for each one) which should push for one server with the central repository. So we have other two servers with "bare" repositories for each one, but this two repositories are mirrors of the central repository and exists just for to update the project in the directories /var/www.

These two final servers are our web servers. The central server are our repository server, it should to update the webserver at moment who a developer push from your the developer machine for the central server.

I've already updated (pushed) from the dev machine directly to one web server with this post-receive hook.

#!/bin/sh
GIT_WORK_TREE=/var/www/project_name git checkout -f

But now, with this new scenario how I will make the central server to update the web servers? With post-receive? Or what?

Theoretically I want do something like this:

$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=ssh://user@webserver/var/www/project_name git checkout -f
$ chmod +x hooks/post-receive

Where GIT_WORK_TREE="ssh" is the webserver adress with ssh.

mayconfsbrito
  • 2,085
  • 4
  • 26
  • 45

1 Answers1

1

You could do a post-receive hook on your main central server in order to push to the bare repos of the web server.

That way, each post-receive hoook already in place on those bare web server repos would still run as they do right now.
But they would be trigger by an automatic push from the central server, instead of a direct push from a dev.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So I have to do a push from the dev machine to the central server, and after a automatic push from the central server to the Web Servers, and this do automatic checkout? – mayconfsbrito Dec 06 '13 at 09:42
  • 1
    @mayconfsbrito yes, push from the central server to the Web Servers would trigger the same automatic checkout as a push from dev machine to Web Servers currently does. – VonC Dec 06 '13 at 09:53
  • How to push automatically from the central server to the Web Servers with post-receive automatically? Do you know a tutorial or have an example? – mayconfsbrito Dec 06 '13 at 10:23
  • 1
    @mayconfsbrito it is still a post-receive hook, with a simple `git push` in it, provided your central repo has the web servers repos as remote (`git remote add webserver1 /url/web/server1`). Then it would be `git push webserver1 `. – VonC Dec 06 '13 at 10:26
  • Do you know how to set a ssh password on the post-receive file? Here in our workspace we are using differents users for ssh. – mayconfsbrito Dec 06 '13 at 11:07
  • 1
    @mayconfsbrito you do it with a `~/.ssh/config` file and scp-like url: http://stackoverflow.com/a/10042145/6309 and http://stackoverflow.com/a/14423667/6309 – VonC Dec 06 '13 at 11:24