gitdeploymentubuntu-14.04gitosisautomatic-updates

How to setup git automatic deployment with 3 servers [repository, dev, prod]


Recently I've read some notes and tutorials digital ocean of how to set up automatic deployment with Git. The problem is that all solutions were about 2 servers - test and live, and server for test had to have repository within itself.

In my case - I have 3 servers:

  1. server with all repositories [Debian 6.0.8] (using Gitosis)
  2. development/test server [ubuntu 14.04] where my team makes changes
  3. live/prod server [ubuntu 14.04]

Is it possible to configure auto deployment in this case?

I was wondering about mounting my production server to repository server or make another connection between them somehow.

Maybe there is some better way to do it?


Solution

  • It came out to be much easier than it looked like.

    1. First, I've mounted my development server to my repository server
    sshfs user@dev_server:/path/to/www /mnt/dev_server -o ServerAliveInterval=60 -o allow_other
    

    Without allow_other option there is permission denied error on "git push"

    1. Than in repositories/website.git/hooks folder I've created script "post-receive"

    cat post-receive

     #!/bin/sh
     git --work-tree=/mnt/dev_serv/path/to/www/website --git-dir=.../repositories/website.git checkout -f
    

    And it is working like a charm. Now I am just searching for some more secure approach. This solution was tested between local to dev_server.

    The main goal is to run autodeployment only when something is being pushed from dev server - not local - to production.