Skip to content

Commit 245a8b1

Browse files
author
Gerad Suyderhoud
committed
setup deploy key
1 parent 659e47b commit 245a8b1

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

Vagrantfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Vagrant.configure("2") do |config|
1313
# doesn't already exist on the user's system.
1414
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
1515

16-
config.vm.provision 'shell', path: './scripts/setup-publickey.sh'
17-
config.vm.provision 'shell', path: './scripts/setup-ubuntu.sh'
16+
config.vm.provision 'shell', path: './scripts/setup/setup-ubuntu.sh'
1817

1918
# config.vm.network "private_network", ip: "192.168.4.790"
2019

models/team.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ TeamSchema = module.exports = new mongoose.Schema
2121
regCode: String
2222
machine: {}
2323
ip: String
24+
deployKey:
25+
public: String
26+
private: String
2427
entry:
2528
name: String
2629
url: String

scripts/setup/setup-deploy-key.coffee

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

scripts/setup/setup-deploy-key.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set -evu
2+
3+
# Creating the deploy key...
4+
ssh-keygen -t rsa -b 2048 -P '' -f ~/.ssh/id_deploy
5+
6+
# Authorizing the deploy key for ssh access...
7+
cat ~/.ssh/id_deploy.pub >> ~/.ssh/authorized_keys

scripts/setup/setup-publickey.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)