mirror of
https://github.com/KevinMidboe/CD.git
synced 2025-10-29 01:20:16 +00:00
Init commit. Express server listening to github webhooks on port 5005
This commit is contained in:
39
index.js
Normal file
39
index.js
Normal 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
16
package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user