gaptool-server 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/routes/main.rb +22 -6
- data/lib/views/init.erb +5 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b30390596dc01948c60152b9bfcedac64c6a7a2
|
4
|
+
data.tar.gz: 1047f8c1a78239b180e0dfa82b09b32ff10553b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1348e1db97048015c9f916787891ab1411378aeab0693e5c0c1f2c5583c329b888150b56f97dd57861e1b7481e2b3f9a232e791bb84e74eec102364023add97
|
7
|
+
data.tar.gz: 1f50122385dad3fcd3d2f0dc66efddb795c3f23661bbd68a6fd44933c35254b54f938fc276bd851ef176b30eac341f7070c21265c52ed24f37e8aff3052cd5df
|
data/lib/routes/main.rb
CHANGED
@@ -18,7 +18,8 @@ class GaptoolServer < Sinatra::Application
|
|
18
18
|
data.merge!("secret" => @secret)
|
19
19
|
security_group = data['security_group'] || $redis.hget("role:#{data['role']}", "security_group")
|
20
20
|
sgid = gt_securitygroup(data['role'], data['environment'], data['zone'], security_group)
|
21
|
-
image_id = $redis.hget("amis:#{data['role']}", data['zone'].chop) || $redis.hget("amis", data['zone'].chop)
|
21
|
+
image_id = data['ami'].chop || $redis.hget("amis:#{data['role']}", data['zone'].chop) || $redis.hget("amis", data['zone'].chop)
|
22
|
+
puts data['zone']
|
22
23
|
if data['mirror']
|
23
24
|
instance = @ec2.instances.create(
|
24
25
|
:image_id => image_id,
|
@@ -52,7 +53,12 @@ class GaptoolServer < Sinatra::Application
|
|
52
53
|
instance.add_tag('Name', :value => "#{data['role']}-#{data['environment']}-#{instance.id}")
|
53
54
|
instance.add_tag('gaptool', :value => "yes")
|
54
55
|
# Create temporary redis entry for /register to pull the instance id
|
55
|
-
|
56
|
+
# with an expire of 24h
|
57
|
+
host_key = "instance:#{data['role']}:#{data['environment']}:#{@secret}"
|
58
|
+
$redis.hmset(host_key, 'instance_id', instance.id,
|
59
|
+
'chef_branch', data['chef_branch'],
|
60
|
+
'chef_repo', data['chef_repo'])
|
61
|
+
$redis.expire(host_key, 86400)
|
56
62
|
"{\"instance\":\"#{instance.id}\"}"
|
57
63
|
end
|
58
64
|
|
@@ -71,9 +77,14 @@ class GaptoolServer < Sinatra::Application
|
|
71
77
|
data = JSON.parse request.body.read
|
72
78
|
AWS.config(:access_key_id => $redis.hget('config', 'aws_id'), :secret_access_key => $redis.hget('config', 'aws_secret'), :ec2_endpoint => "ec2.#{data['zone'].chop}.amazonaws.com")
|
73
79
|
@ec2 = AWS::EC2.new
|
74
|
-
|
80
|
+
host_key = "instance:#{data['role']}:#{data['environment']}:#{data['secret']}"
|
81
|
+
host_data = redis.hgetall(host_key)
|
82
|
+
unless host_data
|
83
|
+
error 403
|
84
|
+
end
|
85
|
+
@instance = @ec2.instances[host_data['instance']]
|
75
86
|
hostname = @instance.dns_name
|
76
|
-
$redis.del(
|
87
|
+
$redis.del(host_key)
|
77
88
|
@apps = []
|
78
89
|
$redis.keys("app:*").each do |app|
|
79
90
|
if $redis.hget(app, 'role') == data['role']
|
@@ -85,6 +96,10 @@ class GaptoolServer < Sinatra::Application
|
|
85
96
|
data.merge!("apps" => @apps.to_json)
|
86
97
|
data.merge!("instance" => @instance.id)
|
87
98
|
hash2redis("host:#{data['role']}:#{data['environment']}:#{@instance.id}", data)
|
99
|
+
|
100
|
+
@chef_repo = data['chef_repo'] || $redis.hget('config', 'chefrepo')
|
101
|
+
@chef_branch = data['chef_branch'] || $redis.hget('config', 'chefbranch')
|
102
|
+
@initkey = $redis.hget('config', 'initkey')
|
88
103
|
@json = {
|
89
104
|
'hostname' => hostname,
|
90
105
|
'recipe' => 'init',
|
@@ -92,12 +107,13 @@ class GaptoolServer < Sinatra::Application
|
|
92
107
|
'run_list' => ['recipe[init]'],
|
93
108
|
'role' => data['role'],
|
94
109
|
'environment' => data['environment'],
|
95
|
-
'chefrepo' =>
|
96
|
-
'chefbranch' =>
|
110
|
+
'chefrepo' => @chef_repo,
|
111
|
+
'chefbranch' => @chef_branch,
|
97
112
|
'identity' => $redis.hget('config','initkey'),
|
98
113
|
'appuser' => $redis.hget('config','appuser'),
|
99
114
|
'apps' => @apps
|
100
115
|
}.to_json
|
116
|
+
|
101
117
|
erb :init
|
102
118
|
end
|
103
119
|
|
data/lib/views/init.erb
CHANGED
@@ -2,10 +2,11 @@ apt-get update
|
|
2
2
|
apt-get install -ymq zsh git libssl-dev ruby1.9.1-full build-essential
|
3
3
|
gem install --bindir /usr/local/bin --no-ri --no-rdoc chef
|
4
4
|
cat << 'EOFKEY' > /root/.ssh/id_rsa
|
5
|
-
|
5
|
+
<%= @initkey %>
|
6
6
|
EOFKEY
|
7
7
|
chmod 600 /root/.ssh/id_rsa
|
8
8
|
echo 'StrictHostKeyChecking no' > /root/.ssh/config
|
9
|
-
git clone -b
|
10
|
-
echo '
|
11
|
-
chef-solo -c /root/ops/cookbooks/init.rb -j /root/init.json &&
|
9
|
+
git clone -b <%= @chef_branch %> <%= @chef_repo %> /root/ops
|
10
|
+
echo '<%= @json %>' > /root/init.json
|
11
|
+
chef-solo -c /root/ops/cookbooks/init.rb -j /root/init.json && \
|
12
|
+
(rm /root/.ssh/id_rsa; userdel -r ubuntu; rm -rf /root/.ssh; rm -rf /root/ops)
|