-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.coffee
88 lines (77 loc) · 2.24 KB
/
app.coffee
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Net = require 'net'
Util = require "util"
Fs = require 'fs'
Express = require 'express'
Sys = require 'sys'
Exec = require('child_process').exec
HipChat = require 'node-hipchat'
hipchat = new HipChat(process.env.HIPCHAT_TOKEN)
channel_name = process.env.DEBOT_CHANNEL or 'default'
debot_name = process.env.DEBOT_NAME or 'Debot'
app = Express()
app.use Express.bodyParser()
deploying = []
hipchat.postMessage
room: channel_name
from: debot_name
message: 'Bootup ok... waiting cmds'
color: 'purple'
app.get '/deploy', (req,res) ->
console.log(req.query)
if (req.query.what)
what = req.query.what
params = req.query.params
if deploying[ what ] == true
hipchat.postMessage
room: channel_name
from: debot_name
message: 'Cannot deploy, already deploying ' + req.query.what
color: 'red'
res.json
error: true
return
deploying[ what ] = true
hipchat.postMessage
room: channel_name
from: debot_name
message: 'Deploying ' + what
color: 'yellow'
deploy_script = null
try
deploy_script = new (require "./scripts/" + req.query.what + ".coffee")()
catch error
setTimeout( ->
hipchat.postMessage
room: channel_name
from: debot_name
message: 'No deployment script for ' + req.query.what
color: 'red'
deploying[ what ] = false
res.json
error: true
, 500)
if deploy_script
res.json
success: true
setTimeout( ->
deploy_script.execute params, (error,execution_log) ->
if error
hipchat.postMessage
room: channel_name
from: debot_name
message: 'Error deploying ' + req.query.what + '. ' + error
color: 'red'
else
hipchat.postMessage
room: channel_name
from: debot_name
message: 'Deployment of ' + req.query.what + ' finished. ' + "\r\n\r\n" + execution_log
color: 'green'
deploying[ what ] = false
, 500)
delete require.cache[require.resolve("./scripts/" + req.query.what + ".coffee")]
else
deploying[ what ] = false
res.json
error: true
app.listen(5600)