mtncd 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +40 -26
  3. data/bin/mtncd +99 -9
  4. data/lib/mtncd/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmE3Zjk5ZTM2N2NlMmYzODg2NjQzMDJlYmQ0YzQyNzNiNjhkZTQ4MQ==
4
+ NTdlM2MyNjlmODkxYjdlZDk4YjZmNzc5NWIxOWVkZGFhMTA3Njg2Nw==
5
5
  data.tar.gz: !binary |-
6
- NzA1Y2I5Yzc2M2YxN2QzODM5NzBiMTFhMGRkYThhM2JlZDJjODgyNQ==
6
+ M2FlZWM0OGJjY2Y3MWJlYzA2ODAyNWFhZmZjNzU5OGVlNzg4OGI3Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Nzc0Njg0ZWNkNGQ5ZDNmZjkxZjE3OTQyYTA5NDI1ODhmMWNkODg0YzI5ZDA0
10
- N2ZmM2JhM2ZjYjI0YjE4ODYxNjNmMWY3MjA1ODg1ZmZiYjM0ODMwNGY1ZmJi
11
- NjE3NDY1N2MyNGMxYTA3N2ZiNDg0MTdhNjI3ZTRlYjI1ZGNmYjE=
9
+ YTlkNGQ1ZmEyZDI1ZDgzMWM5NTllMTA4Y2E0MWY0YmJhYTgxOTAzMjIwYTE3
10
+ ZGVmMzlmOTY4M2Q0MGQyZmU1OWMwOTQwNGIyMzMyYjI3NzZiYzk5YWZiNWFh
11
+ YWJjOTcxNmZhMDk3YWEyOTNhMTE2NDlkY2Q4OTVhMDU1ODBiNmE=
12
12
  data.tar.gz: !binary |-
13
- M2I3YjFhNWVhNDUzYjcwYTIxYWYzNmY4NzZkZGI4YWZjMjljYTI1MmFjNThl
14
- MGVlZDg3ZTMyNDUyYzFjYWI2MTI2NDg3ZTIzYjM0ZGVjMzYyZDU5YjNkYzZl
15
- NDU5Yzg5OTU3YjVjZjVlYzM3YWVhMmMwNjdlNjVkMDI0YjE5NWE=
13
+ ZjM4ZTBkZWIzMzlhOTFlODJlYjg1NGZlNTJlYmU5OWZlMmNmNWY4NzAyNGJh
14
+ NTY4MDdkYmYwYzcwYTIxY2M1MDI5Y2FjZjMyODM4NjZmOTA1ODgxYTVmZDU1
15
+ MzU5NzI1NTNjMmVmNmVkNDVhNzQ0YWQ4NTQxMmU3ZmYyMDdmZWY=
data/README.md CHANGED
@@ -1,27 +1,41 @@
1
- # Example yaml config file (.mtncdconf)
1
+ # Example json config file (.cicdconfig)
2
2
  ---
3
- node: test
4
- role: central
5
- default_exclude: mtn\-aws2
6
- deploy:
7
- global:
8
- stop: stop_deploy
9
- start: deploy
10
- local:
11
- stop: stop_deploy
12
- start: deploy
13
- system:
14
- resque:
15
- workers: 0
16
- redis:
17
- ip: 127.0.0.1
18
- port: 6379
19
- serf:
20
- global:
21
- ip: < some ip >
22
- port: < some port >
23
- auth: super secret token
24
- local:
25
- ip: < some ip >
26
- port: < some port >
27
- auth: super secret token
3
+ {
4
+ "role": "central",
5
+ "default_exclude": "mtn\-aws2",
6
+ "base_path": "/opt/mtn_cicd",
7
+ "chef": {
8
+ "promote_knife": "/root/.chef/tools/promote_knife.rb",
9
+ "server": "https://private-chef.mtnsatcloud.com/organizations/mtn-pipelines",
10
+ "node_name": "serf-central.mtnsatcloud.com",
11
+ "client_key": "/etc/chef/client.pem",
12
+ "environment_chain": {"integration":"staging","staging":"prod"},
13
+ "first_environment": "integration",
14
+ "sandbox": "sandbox"
15
+ },
16
+ "resque": {
17
+ "redis_ip": "127.0.0.1",
18
+ "redis_port": 6379,
19
+ "redis_db": 0,
20
+ "queue": "central",
21
+ "secondary_queue": "central",
22
+ "job_timeout": 7200,
23
+ "worker_count": 10,
24
+ "deploy_timeout": 7200
25
+ },
26
+ "hipchat": {
27
+ "room": "hipchat room",
28
+ "token": "your token"
29
+ },
30
+ "serf": {
31
+ "global" : {
32
+ "rpc_ip": "172.16.24.154",
33
+ "rpc_port": 7373,
34
+ "rpc_auth": "YOURSECRET",
35
+ "node_name": "cicd"
36
+ }
37
+ },
38
+ "ship": {
39
+ "deployment_data": "/opt/mtn_cicd/deployments"
40
+ }
41
+ }
data/bin/mtncd CHANGED
@@ -29,12 +29,7 @@ command :deploy do |deploy|
29
29
  deploy.command :start do |start|
30
30
 
31
31
  start.desc 'deploy starting with environment'
32
- start.default_value 'integration'
33
- start.flag :env, :must_match => {
34
- 'integ' => 'integration',
35
- 'stage' => 'staging',
36
- 'prod' => 'prod'
37
- }
32
+ start.flag :env
38
33
 
39
34
  start.desc 'use deployment id'
40
35
  start.default_value SecureRandom.hex(4)
@@ -58,13 +53,23 @@ command :deploy do |deploy|
58
53
  start.switch :single
59
54
 
60
55
  start.action do |global_options,options,args|
61
-
62
56
  event_options_hash = {
63
57
  'id' => "#{options[:id]}",
64
58
  'single' => options[:single],
65
59
  }
66
60
  event_options_hash['exclusion'] = options[:exclude].nil? ? $config['default_exclude'] : options[:exclude]
61
+
67
62
  event_options_hash['env'] = options[:env] unless options[:env].nil?
63
+ unless options[:env].nil?
64
+ if $config['chef']['environment_chain'][options[:env]].nil?
65
+ if $config['chef']['environment_chain'].key(options[:env]).nil?
66
+ if $config['chef']['sandbox'] != options[:env]
67
+ raise "Unknown environment #{options[:env]}!"
68
+ end
69
+ end
70
+ end
71
+ end
72
+
68
73
  event_options_hash['shipcodes'] = options[:ships].split(",") unless options[:ships].nil?
69
74
 
70
75
  serf_options_hash = {
@@ -224,6 +229,76 @@ command :system do |system|
224
229
  end
225
230
  end
226
231
 
232
+ desc 'Reachability times'
233
+ command :ping do |ping|
234
+ ping.desc 'json output'
235
+ ping.default_value false
236
+ ping.switch :json
237
+
238
+ ping.desc 'local or global cluster command'
239
+ ping.default_value 'global'
240
+ ping.flag :cluster, :must_match => {
241
+ 'global' => 'global',
242
+ 'local' => 'local'
243
+ }
244
+
245
+ ping.desc 'timeout in seconds'
246
+ ping.default_value 60
247
+ ping.flag :timeout
248
+
249
+ ping.action do |global_options,options,args|
250
+ begin
251
+ puts "This might take up to #{options[:timeout]} seconds" unless options[:json]
252
+
253
+ members = nil
254
+ Serfx.connect(host: $config['serf'][options[:cluster]]['rpc_ip'], port: $config['serf'][options[:cluster]]['rpc_port'], authkey:$config['serf'][options[:cluster]]['rpc_auth']) do |conn|
255
+ members = conn.members.body['Members']
256
+ end
257
+
258
+ # build serf command string
259
+ command_string = "serf query --format=json -timeout=\"#{options[:timeout]}s\" "
260
+ members.each do |member|
261
+ if member['Status'] != 'left'
262
+ command_string += " -node=#{member['Name']}"
263
+ end
264
+ end
265
+ command_string += " -rpc-addr=#{$config['serf'][options[:cluster]]['rpc_ip']}:#{$config['serf'][options[:cluster]]['rpc_port']}"
266
+ command_string += " -rpc-auth=#{$config['serf'][options[:cluster]]['rpc_auth']}" unless $config['serf'][options[:cluster]]['rpc_auth'].nil?
267
+
268
+ start_time = Time.now.to_i
269
+ command_string += " ping #{start_time}"
270
+
271
+ serf_output = nil
272
+ Open3.popen3(command_string) do |stdin, stdout, stderr, wait_thr|
273
+ exitstatus = wait_thr.value
274
+ raise "Failed to send the ping query" unless exitstatus == 0
275
+ serf_output = JSON.parse(stdout.read)
276
+ end
277
+
278
+ if serf_output['Responses'].length < members.length
279
+ serf_output['Error'] = "expecting #{members.length} responses, got #{serf_output['Responses'].length} responses"
280
+ end
281
+
282
+ serf_output['Responses'].each do |node,time|
283
+ serf_output['Responses'][node] = serf_output['Responses'][node].to_i - start_time
284
+ end
285
+
286
+ if options[:json]
287
+ puts JSON.pretty_generate(serf_output)
288
+ else
289
+ puts "\033[31mFailure: #{serf_output['Error']}\033[0m" unless serf_output['Error'].nil?
290
+
291
+ serf_output['Responses'].each do |node,time|
292
+ puts "Node #{node} ack in #{time} seconds"
293
+ end
294
+ end
295
+
296
+ rescue Serfx::RPCError => e
297
+ raise "Could not connect to #{options[:cluster]} cluster"
298
+ end
299
+ end
300
+ end
301
+
227
302
  desc 'resque information'
228
303
  command :resque do |resque|
229
304
  resque.desc 'resque information'
@@ -254,6 +329,19 @@ command :resque do |resque|
254
329
  puts "Worker #{worker.to_s} processing job #{worker.job}"
255
330
  }
256
331
  end
332
+ end
333
+
334
+ resque.desc 'resque errors'
335
+ resque.command :errors do |errors|
336
+ errors.action do |global_options,options,args|
337
+ Resque.redis = "#{$config['resque']['redis_ip']}:#{$config['resque']['redis_port']}/#{$config['resque']['redis_db']}"
338
+
339
+ puts "All failures:"
340
+ Resque::Failure.all(0, Resque::Failure.count - 1).each { |failure|
341
+ puts "#{failure["exception"]}:\n #{failure["backtrace"]}"
342
+ puts '--------------------'
343
+ }
344
+ end
257
345
  end
258
346
 
259
347
  resque.desc 'flush redis (destructive)'
@@ -276,11 +364,13 @@ pre do |global,command,options,args|
276
364
  $config = JSON.parse(File.read(File.join(Dir.home, '.cicdconfig')))
277
365
 
278
366
  if $config['role'] == 'sled' && options[:cluster] == 'global'
279
- raise 'global commands are not available on sled nodes'
367
+ puts 'global commands are not available on sled nodes. forcing \'--cluster=local\''
368
+ options[:cluster] = 'local'
280
369
  end
281
370
 
282
371
  if $config['role'] == 'central' && options[:cluster] == 'local'
283
- raise 'local commands are not available on central nodes'
372
+ puts 'local commands are not available on central nodes. forcing \'--cluster=global\''
373
+ options[:cluster] = 'global'
284
374
  end
285
375
 
286
376
  true
@@ -1,3 +1,3 @@
1
1
  module Mtncd
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtncd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - MTN Satellite Communications
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque