diff --git a/README.textile b/README.textile index a022f49..b90d2d7 100644 --- a/README.textile +++ b/README.textile @@ -2,6 +2,28 @@ h1. A simple continuous deploy server for github projects h2. Author: Maksim Lin +h2. Usage + +This is a very simple continous deploy server that listens on a port for POSTs from +githubs post-receive webhook. + +The server will cwd into the project folder. This fodler is expected to be a git working copy +where it will execute "git pull origin master && npm install". + +Note that the server will only run if it gets a payload that specifies a push tp the master branch, +ie. refs/heads/master + + +h3. Configuration + +Configuration is via environment variables: + +PORT - port to listen on +RESTART_CMD - the shell command to execute +DEPLOY_PATH - the path to append the project name to that becomes the cwd prior to pulling from the gitrepo + +Please set the bin/run.sh as an example. + h2. License Copyright 2011 Maksim Lin @@ -19,4 +41,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Mydvds. If not, see . +along with node-github-deployhook. If not, see . diff --git a/bin/run.sh b/bin/run.sh index 9cc54ec..84e3bbb 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -1,6 +1,6 @@ #! //bin/sh export PORT=1974 -export DEPLY_PATH=/var/www/mydvds/app +export DEPLY_PATH=/var/www export RESTART_CMD="sudo restart mydvds" cd /var/www/node-github-deployhook diff --git a/lib/server.js b/lib/server.js index 64bf3ee..d50eed1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -8,15 +8,13 @@ var log = require('nlogger').logger(module), http = require('http'), + path = require('path'), decodeForm = require('./www-forms').decodeForm, exec = require('child_process').exec, command = 'git pull origin master && npm install', currentResponse, reqBody = [], - options = { - cwd: process.env.DEPLOY_PATH - }; - + options = {}; /** * @param {bool} processedOk @@ -35,9 +33,10 @@ function sendResponse(processedOk, messageText) { //execute a git pull within the deployPath //and then execute an npm install -function deploy() { +function deploy(projectName) { log.info('doing pull and npm'); + options.cwd = path.join(process.env.DEPLOY_PATH, projectName); exec(command, options, function(error, stdout, stderr) { if (error) { return log.error(command, { @@ -93,7 +92,7 @@ function requestHandler(request, response) { log.info('repo:'+data.repository.name); log.info('ref:'+data.ref); if (data && data.ref && (data.ref === 'refs/heads/master')) { - deploy(); + deploy(data.repository.name); } }); }