Init commit. Express server listening to github webhooks on port 5005

This commit is contained in:
2019-08-01 13:29:56 +02:00
parent 30b87be773
commit 6a8b4273ac
2 changed files with 55 additions and 0 deletions

39
index.js Normal file
View File

@@ -0,0 +1,39 @@
var express = require("express");
const bodyParser = require('body-parser');
const { execFile } = require('child_process');
var app = express();
app.use(bodyParser.json());
app.post("/webhooks/github", function (req, res) {
console.log('req', req.body)
var branch = req.body.ref;
console.log(`Detected updates to branch: '${branch}'`)
if(branch.indexOf('master') > -1){
console.log('Downloading master branch');
deploy(res);
}
else {
console.log('Non-deployable branch found. Not initiating build, but responding to the webhook')
res.sendStatus(200);
}
})
function deploy(res){
const child = execFile('/home/ubuntu/deployment/deploy.sh', [], { shell: true }, (error, stdout, stderr) => {
if (error)
console.error(error);
console.log(stdout);
});
res.sendStatus(200);
}
const port = process.env.PORT || 5005;
console.log('Starting deployment server on port:', port);
app.listen(port);

16
package.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "CD",
"version": "1.0.0",
"description": "Modular deployment server",
"main": "index.js",
"author": "Kevin Midboe",
"license": "MIT",
"private": true,
"scripts": {
"start": "node index.js"
},
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1"
}
}