-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const _ = require('lodash');
const fs = require('fs');
const moment = require('moment');
const express = require('express');
const exec = require('child_process').execSync;
const app = express();
const port = 3000;
// const config = JSON.parse(fs.readFileSync("./config.json"));
const config = {
"scripts": {
"start": "start.sh",
"stop": "stop.sh",
},
"credentials": {
},
"jobs": {
"user-front-end": {
"branch": "master",
"repo": "git@gitlab.com:buy-in-kannur/bik-user-app.git",
"location": "user-front-end"
}
}
};
app.use(express.json());
app.get('/build', (req, res) => {
res.send('OK');
let ref = req.body.ref.replace(/(.*)\/(.*)/,"$2");
let checkoutSha = req.body.checkout_sha;
let url = req.body.repository.git_ssh_url;
let job = _(config.jobs).find(o => o.repo === url);
if(ref !== job.branch)
return;
exec(`/bin/bash ./scripts/deploy.sh ${url} ${checkoutSha} ${job.location}`)
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));