@@ -5,6 +5,46 @@ module.exports = setupDeployKey = (options, next) ->
55 team = options .team
66 githubAuth = options .githubAuth
77
8- # TODO setup deploy key
8+ github = require (' ../../config/github' )(githubAuth)
9+ exec = require (' child_process' ).exec
10+ async = require ' async'
911
10- next ()
12+ execssh = (cmd , next ) ->
13+ exec " ssh root@#{ team .ip } #{ cmd} " , cwd : __dirname , next
14+
15+ createDeployKey = (next ) ->
16+ console .log team .slug , ' create deploy key'
17+ execssh " bash -s < ./setup-deploy-key.sh" , (err , stdout , stderr ) ->
18+ next (err) if err?
19+ next ()
20+
21+ getDeployPublicKey = (next ) ->
22+ console .log team .slug , ' get deploy public key'
23+
24+ execssh " 'cat ~/.ssh/id_deploy.pub'" , (err , publicKey , stderr ) ->
25+ return next (err) if err?
26+ team .deployKey .public = publicKey
27+ next ()
28+
29+ getDeployPrivateKey = (next ) ->
30+ console .log team .slug , ' get deploy private key'
31+
32+ execssh " 'cat ~/.ssh/id_deploy'" , (err , privateKey , stderr ) ->
33+ return next (err) if err?
34+ team .deployKey .private = privateKey
35+ next ()
36+
37+ saveDeployKeypair = (next ) ->
38+ console .log team .slug , ' save deploy keypair'
39+ team .save (err) ->
40+ return next (err) if err?
41+ next ()
42+
43+ addDeployKeyToGithub = (next ) ->
44+ console .log team .slug , ' add deploy key to github'
45+ github .post " repos/nko4/#{ team .slug } /keys" ,
46+ title : " deploy@#{ team .slug } .2013.nodeknockout.com"
47+ key : team .deployKey .public
48+ , next
49+
50+ async .waterfall [ createDeployKey, getDeployPublicKey, getDeployPrivateKey, saveDeployKeypair, addDeployKeyToGithub ], next
0 commit comments