-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
66 lines (55 loc) · 1.44 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var express = require('express')
var bodyParser = require('body-parser')
var exec = require('child_process').exec
var app = new express()
var cluster = process.env.CLUSTER
app.use(bodyParser.json())
var router = new express.Router()
router.get('/', function (req, res) {
res.send(
'Usage: curl -X POST /{namespace}/{deployment} -H "Content-Type: application/json" -d \'{"image":}\'"<image:tag>" '
)
})
router.post('/:ns/:deploy', function (req, res) {
var ns = req.params.ns
var deploy = req.params.deploy
var image = req.body.image
if (!ns || !deploy || !image) {
return res
.status(500)
.json({ status: 500, message: 'You must pass all params' })
}
var deploymentSpec = {
spec: {
template: {
spec: {
containers: [
{
name: deploy,
image: image,
env: [{ name: 'DEPLOY_DATE', value: Date().toString() }]
}
]
}
}
}
}
exec(
`kubectl --kubeconfig=${cluster} --namespace ${ns} patch deploy ${deploy} -p '${JSON.stringify(deploymentSpec)}' --record`,
function (err) {
if (err) {
console.log(err)
res.status(500).json(err)
} else {
res.status(200).json({ status: 200, ns, deploy, image })
}
}
)
})
app.use(router)
var server = app.listen(3000, function () {
console.log('App listening on port 3000')
})
process.on('SIGINT', function(){
server.close()
})