aggkit 0.2.9.8725 → 0.3.0
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 +5 -5
- data/Gemfile.lock +1 -1
- data/bin/aggstart +34 -30
- data/lib/aggkit/option_parser.rb +52 -0
- data/lib/aggkit/runner.rb +4 -1
- data/lib/aggkit/version.rb +1 -1
- data/lib/aggkit.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1cb8844a3333ce60ca5918aaf4d13ac75dcbf22dc82387de89417435632f7f76
|
4
|
+
data.tar.gz: d7f1f771d64acd6d1bf34dd28374d023a2430c6769d92f84c74d1b0163458b62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7115a18b786af71eac551e93ebeae47fa474c3e7650979cb3d6cbf377c310bfd7101354f7f2fed1088372cf13eeba23a716df4b9fb2750173e6fe9424e68c0a
|
7
|
+
data.tar.gz: f281d3f5ec9594197680290536b2aec4cc149b0d3b02cba3dcb2a550749655922c08935a643ca79f07f4bf0cf6c2ca647af352816df4986d0027e59af68b5aa2
|
data/Gemfile.lock
CHANGED
data/bin/aggstart
CHANGED
@@ -1,42 +1,40 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'optparse'
|
4
3
|
require 'aggkit'
|
5
4
|
|
6
5
|
UTIL = File.basename(__FILE__)
|
7
6
|
|
8
7
|
@opts = {
|
9
8
|
service: ENV['AGGREDATOR_SERVICE'],
|
10
|
-
consul: ENV['CONSUL_HOST'],
|
9
|
+
consul: ENV['CONSUL_HOST'] || 'localhost',
|
10
|
+
consulconf: [],
|
11
11
|
depends: [],
|
12
|
-
consulconf: []
|
13
12
|
}
|
14
13
|
|
15
|
-
|
16
|
-
parser = OptionParser.new do |o|
|
14
|
+
parser = Aggkit::OptionParser.new do |o|
|
17
15
|
o.banner = "Usage: #{UTIL} [options]"
|
18
16
|
|
19
|
-
o.on("--service
|
17
|
+
o.on("--service <NAME>", 'Set service NAME. AGGREDATOR_SERVICE env can be used instead') do |service|
|
20
18
|
@opts[:service] = service.to_s
|
21
19
|
end
|
22
20
|
|
23
|
-
o.on("--consul=#{@opts[:consul]}", '
|
24
|
-
|
25
|
-
@opts[:consul] = nil
|
26
|
-
else
|
27
|
-
@opts[:consul] = consul.to_s
|
28
|
-
end
|
21
|
+
o.on("--consul=#{@opts[:consul]}", 'Set consul host. CONSUL_HOST env can be used instead') do |consul|
|
22
|
+
@opts[:consul] = consul.to_s
|
29
23
|
end
|
30
24
|
|
31
|
-
o.on("--consulconf=
|
32
|
-
@opts[:consulconf] = list.to_s
|
25
|
+
o.on("--consulconf=consul,consul/smev3...", 'Set list of folders with consul configs. Special: none - disable local consul') do |list|
|
26
|
+
@opts[:consulconf] = if list.to_s == 'none'
|
27
|
+
nil
|
28
|
+
else
|
29
|
+
list.to_s.split(/[ ;,|]/).map(&:to_s).reject(&:empty?)
|
30
|
+
end
|
33
31
|
end
|
34
32
|
|
35
|
-
o.on("--depends=
|
33
|
+
o.on("--depends=mq,db,router...", 'Set list of services to wait for ready before start') do |list|
|
36
34
|
@opts[:depends] = list.to_s.split(/[ ;,|]/).map(&:to_s).reject(&:empty?)
|
37
35
|
end
|
38
36
|
|
39
|
-
o.on("--exec
|
37
|
+
o.on("--exec <FILE>", 'Set FILE to execute.') do |file|
|
40
38
|
@opts[:exec] = file.to_s
|
41
39
|
end
|
42
40
|
|
@@ -44,41 +42,47 @@ parser = OptionParser.new do |o|
|
|
44
42
|
end
|
45
43
|
parser.parse!
|
46
44
|
|
45
|
+
|
47
46
|
include Aggkit::Runner
|
48
47
|
|
49
|
-
|
48
|
+
if @opts[:service].to_s.empty?
|
49
|
+
die "service name must be provided"
|
50
|
+
end
|
51
|
+
|
52
|
+
if @opts[:exec].to_s.empty?
|
53
|
+
die "exec script must be provided"
|
54
|
+
end
|
55
|
+
|
56
|
+
@opts[:node_name] = "#{@opts[:service]}_#{`hostname`.strip}".strip
|
57
|
+
|
58
|
+
ENV['AGGREDATOR_SERVICE'] = @opts[:service]
|
59
|
+
ENV['CONSUL_HOST'] = @opts[:consul]
|
60
|
+
ENV['NODE_NAME'] = @opts[:node_name]
|
50
61
|
|
51
|
-
|
52
|
-
$CONSUL_HOST = @opts[:consul]
|
53
|
-
$NODE_NAME = ENV['NODE_NAME'] ||= "#{$AGGREDATOR_SERVICE}_#{`hostname`.strip}".strip
|
62
|
+
init_service @opts[:service], @opts
|
54
63
|
|
55
64
|
envsubst '/home/app/consul'
|
56
65
|
|
57
66
|
Aggkit::Watcher.new.exec do |watcher|
|
58
67
|
|
59
|
-
if @opts[:
|
60
|
-
#watcher.add %W{consul agent -config-dir consul -config-dir consul/smev3 -node #{$NODE_NAME}}
|
68
|
+
if @opts[:consulconf]
|
61
69
|
configs = @opts[:consulconf].map do |folder|
|
62
70
|
"-config-dir #{folder}"
|
63
71
|
end.join(' ').strip
|
64
72
|
|
65
|
-
watcher.add "consul agent #{configs} -node #{
|
73
|
+
watcher.add "consul agent #{configs} -node #{@opts[:node_name]}".split
|
66
74
|
end
|
67
75
|
|
68
|
-
execute!("aggwait -t 20 --consul-addr=http://#{
|
76
|
+
execute!("aggwait -t 20 --consul-addr=http://#{@opts[:consul]}:8500 --consul", "Timeout for consul service")
|
69
77
|
|
70
|
-
load_envs_from_consul(
|
78
|
+
load_envs_from_consul(@opts[:consul], @opts[:service])
|
71
79
|
|
72
80
|
@opts[:depends].each do |service|
|
73
|
-
execute!("aggwait -t 60 --consul-addr=http
|
81
|
+
execute!("aggwait -t 60 --consul-addr=http://#{@opts[:consul]}:8500 --consul-service #{service}", "Timeout for #{service} service")
|
74
82
|
end
|
75
83
|
|
76
84
|
sleep 2
|
77
85
|
|
78
|
-
|
79
|
-
# execute("rake db:create")
|
80
|
-
# execute!("rake db:migrate", "migrate failed")
|
81
|
-
# execute!("rake db:seed", "seed failed")
|
82
86
|
watcher.add %W{#{@opts[:exec]}}
|
83
87
|
end
|
84
88
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'English'
|
5
|
+
|
6
|
+
# Add the ability to specify switches as required to OptionParser
|
7
|
+
class OptionParser
|
8
|
+
|
9
|
+
# An array of messages describing any missing required switches
|
10
|
+
attr_reader :missing_switches
|
11
|
+
|
12
|
+
# Convenience method to test if we're missing any required switches
|
13
|
+
def missing_switches?
|
14
|
+
!@missing_switches.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
# Alias the OptionParser::make_switch function
|
18
|
+
# (instead of directly modifying it like I did in 0.1.0)
|
19
|
+
alias :pickled_make_switch :make_switch
|
20
|
+
|
21
|
+
# Wrapper for OptionParser::make_switch to allow for required switches
|
22
|
+
def make_switch(opts, block = nil)
|
23
|
+
|
24
|
+
# Test if a switch is required
|
25
|
+
required = opts.delete(:required)
|
26
|
+
|
27
|
+
return_values = pickled_make_switch(opts, block)
|
28
|
+
|
29
|
+
# Make sure required switches are given
|
30
|
+
if required
|
31
|
+
short = return_values[1][0].nil? ? nil : "-#{return_values[1][0]}"
|
32
|
+
long = return_values[2][0].nil? ? nil : "--#{return_values[2][0]}"
|
33
|
+
|
34
|
+
if !(default_argv.include?(short) || default_argv.include?(long))
|
35
|
+
@missing_switches ||= [] # Should be placed in initialize if incorporated into Ruby proper
|
36
|
+
|
37
|
+
# Not much prettier, but a bit more readable than the previous iteration
|
38
|
+
message = "Missing switch: "
|
39
|
+
message << short unless short.nil?
|
40
|
+
message << " or " unless (short.nil? || long.nil?)
|
41
|
+
message << long unless long.nil?
|
42
|
+
@missing_switches << message
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
return return_values
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Aggkit
|
51
|
+
OptionParser = ::OptionParser
|
52
|
+
end
|
data/lib/aggkit/runner.rb
CHANGED
@@ -6,11 +6,14 @@ module Aggkit
|
|
6
6
|
|
7
7
|
module Runner
|
8
8
|
|
9
|
-
def init_service(service)
|
9
|
+
def init_service(service, options = nil)
|
10
10
|
STDOUT.sync = true
|
11
11
|
STDERR.sync = true
|
12
12
|
|
13
13
|
puts "Starting #{service}..."
|
14
|
+
if options
|
15
|
+
puts "Options: #{options.inspect}"
|
16
|
+
end
|
14
17
|
|
15
18
|
trap('EXIT') do
|
16
19
|
puts "Stopping #{service}..."
|
data/lib/aggkit/version.rb
CHANGED
data/lib/aggkit.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aggkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Godko Ivan
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/aggkit/childprocess/windows/structs.rb
|
166
166
|
- lib/aggkit/ci.rb
|
167
167
|
- lib/aggkit/env.rb
|
168
|
+
- lib/aggkit/option_parser.rb
|
168
169
|
- lib/aggkit/runner.rb
|
169
170
|
- lib/aggkit/version.rb
|
170
171
|
- lib/aggkit/watcher.rb
|
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
version: '0'
|
189
190
|
requirements: []
|
190
191
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
192
|
+
rubygems_version: 2.7.3
|
192
193
|
signing_key:
|
193
194
|
specification_version: 4
|
194
195
|
summary: Helper scripts for work with docker and consul in Aggredator
|