How can I automatically deploy my app after a git push ( GitHub and node.js)?

Advanced picture Advanced · Feb 3, 2012 · Viewed 63.6k times · Source

I have my application (node.js) deployed on a VPS (linux). I'm using git hub as a repository. How can I deploy the application automatically, on git push ?

Answer

Pawel Dubiel picture Pawel Dubiel · Feb 5, 2012

Example in PHP:

Navigate to github into your github repository add click "Admin"

click tab 'Service Hooks' => 'WebHook URLs'

and add

http://your-domain-name/git_test.php

then create git_test.php

<?php 
try
{
  $payload = json_decode($_REQUEST['payload']);
}
catch(Exception $e)
{
  exit(0);
}

//log the request
file_put_contents('logs/github.txt', print_r($payload, TRUE), FILE_APPEND);


if ($payload->ref === 'refs/heads/master')
{
  // path to your site deployment script
  exec('./build.sh');
}

In the build.sh you will need to put usual commands to retrieve your site from github