-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerUpdate.js
executable file
·70 lines (62 loc) · 1.82 KB
/
dockerUpdate.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
67
68
69
70
const process = require('child_process')
const Koa = require('koa')
const Router = require('koa-router')
const app = new Koa()
const router = new Router()
app.use(router.routes())
const IMAGES_NAME = 'hello-docker2'
const instruct = [
'docker-compose pull',
'docker-compose stop',
'docker-compose rm',
'docker-compose up -d'
]
// eslint-disable-next-line handle-callback-err
router.post('/wechat', async ctx => {
let data = await parsePostData(ctx)
data = JSON.parse(data)
if (data.repository.namespace === 'hodor123' && data.repository.name === IMAGES_NAME) {
process.exec(instruct.join('&'), err => {
err
? console.log(err)
: console.log('process done work', err)
})
ctx.response.status = 200
ctx.response.body = JSON.stringify({
'state': 'success',
'description': '387 tests PASSED',
'context': 'Continuous integration by Acme CI',
'target_url': 'http://ci.acme.com/results/afd339c1c3d27'
})
}
// console.log(Object.getOwnPropertyNames(ctx), Object.getOwnPropertyNames(ctx.request))
})
function parseQueryStr (queryStr) {
let queryData = {}
let queryStrList = queryStr.split('&')
console.log(queryStrList)
for (let [ index, queryStr ] of queryStrList.entries() ) {
let itemList = queryStr.split('=')
queryData[ itemList[0] ] = decodeURIComponent(itemList[1])
}
return queryData
}
function parsePostData (ctx) {
return new Promise((resolve, reject) => {
try {
let postdata = ''
ctx.req.addListener('data', data => {
postdata += data
})
ctx.req.addListener('end', () => {
// let parseData = parseQueryStr(postdata) json 暂时不需要key value
resolve(postdata)
})
} catch (err) {
reject(err)
}
})
}
// process.exec('docker-compose pull info', () => {
// })
app.listen('2333')