aggkit 0.4.4.11050 → 0.4.4.12292
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/Gemfile +2 -1
- data/Gemfile.lock +9 -0
- data/bin/aggexec +71 -0
- data/lib/aggkit/childprocess/abstract_io.rb +1 -0
- data/lib/aggkit/childprocess/abstract_process.rb +1 -0
- data/lib/aggkit/childprocess/errors.rb +1 -0
- data/lib/aggkit/childprocess/jruby.rb +1 -0
- data/lib/aggkit/childprocess/tools/generator.rb +1 -0
- data/lib/aggkit/childprocess/unix/fork_exec_process.rb +1 -0
- data/lib/aggkit/childprocess/unix/io.rb +1 -0
- data/lib/aggkit/childprocess/unix/lib.rb +1 -0
- data/lib/aggkit/childprocess/unix/platform/i386-linux.rb +1 -0
- data/lib/aggkit/childprocess/unix/platform/i386-solaris.rb +1 -0
- data/lib/aggkit/childprocess/unix/platform/x86_64-linux.rb +1 -0
- data/lib/aggkit/childprocess/unix/platform/x86_64-macosx.rb +1 -0
- data/lib/aggkit/childprocess/unix/posix_spawn_process.rb +1 -0
- data/lib/aggkit/childprocess/unix/process.rb +1 -0
- data/lib/aggkit/childprocess/unix.rb +1 -0
- data/lib/aggkit/childprocess/version.rb +1 -0
- data/lib/aggkit/childprocess/windows.rb +1 -0
- data/lib/aggkit/childprocess.rb +1 -0
- data/lib/aggkit/consul.rb +62 -0
- data/lib/aggkit/exec.rb +44 -0
- data/lib/aggkit.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7e60deba3fa62e58fca16ad17c510ad79184ac9
|
|
4
|
+
data.tar.gz: 52b36d4af259d772575b8b1f869b3ddc02ef7178
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 543131a585b51005c7d40c31825f0bbfed6ae5e17903510bcc1afdd85f907f51cf84f3a9fa81be9a77f0035da019ff545119f17e3fe269ae86b3f29ba9fe3a74
|
|
7
|
+
data.tar.gz: 7404283ebc889e58b061dcf0179d6a9cfec1da120cf00214f59e4c8d817737cdbe78ae6e1e47e4588f7df20845d0a59362b0379b057314bd3109faffbb905b3e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -10,6 +10,7 @@ PATH
|
|
|
10
10
|
GEM
|
|
11
11
|
remote: https://rubygems.org/
|
|
12
12
|
specs:
|
|
13
|
+
ansi (1.5.0)
|
|
13
14
|
awesome_print (1.8.0)
|
|
14
15
|
diff-lcs (1.3)
|
|
15
16
|
diplomat (2.0.5)
|
|
@@ -43,8 +44,15 @@ GEM
|
|
|
43
44
|
docile (~> 1.1)
|
|
44
45
|
json (>= 1.8, < 3)
|
|
45
46
|
simplecov-html (~> 0.10.0)
|
|
47
|
+
simplecov-console (0.5.0)
|
|
48
|
+
ansi
|
|
49
|
+
simplecov
|
|
50
|
+
terminal-table
|
|
46
51
|
simplecov-html (0.10.2)
|
|
52
|
+
terminal-table (1.8.0)
|
|
53
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
47
54
|
tty-tree (0.2.0)
|
|
55
|
+
unicode-display_width (1.6.0)
|
|
48
56
|
|
|
49
57
|
PLATFORMS
|
|
50
58
|
ruby
|
|
@@ -59,6 +67,7 @@ DEPENDENCIES
|
|
|
59
67
|
rspec-set
|
|
60
68
|
rspec_junit_formatter
|
|
61
69
|
simplecov
|
|
70
|
+
simplecov-console
|
|
62
71
|
|
|
63
72
|
BUNDLED WITH
|
|
64
73
|
1.16.2
|
data/bin/aggexec
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'aggkit'
|
|
4
|
+
|
|
5
|
+
UTIL = File.basename(__FILE__)
|
|
6
|
+
|
|
7
|
+
if ENV['CONSUL_HTTP_ADDR'].to_s.empty?
|
|
8
|
+
ENV['CONSUL_HTTP_ADDR'] = "http://#{ENV['CONSUL_HOST'] || 'localhost'}:8500"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
@opts = {
|
|
12
|
+
consul: ENV['CONSUL_HTTP_ADDR'],
|
|
13
|
+
depends: [],
|
|
14
|
+
prefixes: [],
|
|
15
|
+
templates: []
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@opts[:exec] = (begin
|
|
19
|
+
idx = ARGV.index {|a| a.strip == '--' } + 1
|
|
20
|
+
ARGV[idx..-1]
|
|
21
|
+
rescue StandardError
|
|
22
|
+
[]
|
|
23
|
+
end)
|
|
24
|
+
|
|
25
|
+
parser = Aggkit::OptionParser.new do |o|
|
|
26
|
+
o.banner = "Usage: #{UTIL} [options]"
|
|
27
|
+
|
|
28
|
+
o.on("--consul=#{@opts[:consul]}", 'Set consul http address. CONSUL_HTTP_ADDR env can be used instead') do |consul|
|
|
29
|
+
ENV['CONSUL_HTTP_ADDR'] = Aggkit::Consul.consul_addr(consul)
|
|
30
|
+
@opts[:consul] = ENV['CONSUL_HTTP_ADDR']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
o.on('--depends=mq,db,router...', 'Set list of services to wait for ready before start') do |list|
|
|
34
|
+
@opts[:depends] += list.to_s.split(/[ ;,|]/).map(&:to_s).reject(&:empty?)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
o.on('--prefix=kv/folder/path', 'Consul KV prefix to load envs from. Multiple prefixes are merged from left to right.') do |prefix|
|
|
38
|
+
@opts[:prefixes] << prefix.strip
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
o.on('--service=<SERVICE>', 'Showrtcut for --prefix=services/env/<SERVICE>. Multiple prefixes are merged from left to right.') do |service|
|
|
42
|
+
@opts[:prefixes] << "services/env/#{service}".strip
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
o.on('--templates=<FOLDER>', 'Folder for recursive ensubst *.in templates. Multiple prefixes are merged from left to right.') do |folder|
|
|
46
|
+
@opts[:templates] << folder.strip
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
parser.parse!
|
|
51
|
+
|
|
52
|
+
@opts[:depends] = @opts[:depends].select(:present?)
|
|
53
|
+
@opts[:prefixes] = @opts[:prefixes].select(:present?)
|
|
54
|
+
@opts[:templates] = @opts[:templates].select(:present?)
|
|
55
|
+
|
|
56
|
+
die 'exec script must be provided' if @opts[:exec].empty?
|
|
57
|
+
|
|
58
|
+
# Wait for consul
|
|
59
|
+
Aggkit::Consul.wait_for_consul(@opts[:consul])
|
|
60
|
+
|
|
61
|
+
# Wait for dependencies
|
|
62
|
+
@opts[:depends].each(&Aggkit::Consul.method(:wait_for_service).curry.call(@opts[:consul]))
|
|
63
|
+
|
|
64
|
+
# Load env from consul
|
|
65
|
+
@opts[:prefixes].each(&Aggkit::Consul.method(:load_envs_from_consul).curry.call(@opts[:consul]))
|
|
66
|
+
|
|
67
|
+
# Preprocess template files
|
|
68
|
+
Aggkit::Consul.envsubst(*@opts[:templates])
|
|
69
|
+
|
|
70
|
+
exec(*@opts[:exec])
|
|
71
|
+
|
data/lib/aggkit/childprocess.rb
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'English'
|
|
4
|
+
|
|
5
|
+
module Aggkit
|
|
6
|
+
|
|
7
|
+
module Consul
|
|
8
|
+
|
|
9
|
+
def load_envs(string, env = ENV)
|
|
10
|
+
envs = Dotenv::Parser.new(string).call
|
|
11
|
+
envs.each_pair do |k, v|
|
|
12
|
+
env[k] = v
|
|
13
|
+
end
|
|
14
|
+
envs
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def consul_addr addr_or_host
|
|
18
|
+
if addr_or_host['http']
|
|
19
|
+
addr_or_host
|
|
20
|
+
else
|
|
21
|
+
"http://#{addr_or_host}:8500"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def load_envs_from_consul(consul, prefix)
|
|
26
|
+
consul_http = consul_addr(consul)
|
|
27
|
+
envs = Aggkit::Exec.capture!("aggconsul --consul=#{consul_http} --env #{prefix} --pristine -d", "Can't load envs from #{prefix}")
|
|
28
|
+
load_envs(envs)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def wait_for_consul consul
|
|
32
|
+
consul_http = consul_addr(consul)
|
|
33
|
+
Aggkit::Exec.execute!("aggwait -t 30 -i 5 --consul-addr=#{consul_http} --consul", 'Timeout for consul service')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def wait_for_service consul, service
|
|
37
|
+
consul_http = consul_addr(consul)
|
|
38
|
+
Aggkit::Exec.execute!("aggwait -t 60 -i 5 --consul-addr=#{consul_http} --consul-service #{service}", "Timeout for #{service} service")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def envsubst(*paths)
|
|
42
|
+
paths = paths.flatten.map{|c| c.to_s.strip }.reject(&:empty?)
|
|
43
|
+
paths.each do |path|
|
|
44
|
+
Dir.glob("#{path}/**/*.in") do |templ|
|
|
45
|
+
envsubst_file(templ, templ.sub(/\.in$/, ''))
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def envsubst_file(templ, output = nil)
|
|
51
|
+
output ||= templ.sub(/\.in$/, '')
|
|
52
|
+
Aggkit::Exec.die('filename must ends with .in or output must be provided') if output.strip == templ.strip
|
|
53
|
+
cmd = "cat '#{templ}' | envsubst > '#{output}'"
|
|
54
|
+
Aggkit::Exec.execute!(cmd, "envsubst failed: #{cmd}")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
extend ::Aggkit::Consul
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
data/lib/aggkit/exec.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Aggkit
|
|
2
|
+
|
|
3
|
+
module Exec
|
|
4
|
+
|
|
5
|
+
def error(message)
|
|
6
|
+
STDERR.puts "Error: #{message}"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def die(message, code: 1)
|
|
10
|
+
error(message)
|
|
11
|
+
exit!(code)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def capture(cmd)
|
|
15
|
+
puts "Capturing: #{cmd}"
|
|
16
|
+
io = IO.popen(cmd)
|
|
17
|
+
io.read.strip
|
|
18
|
+
ensure
|
|
19
|
+
io.close rescue nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def capture!(cmd, error = nil)
|
|
23
|
+
output = capture(cmd)
|
|
24
|
+
error = error ? "#{error}: Execution failed" : 'Execution failed'
|
|
25
|
+
die(error) unless $?&.success?
|
|
26
|
+
|
|
27
|
+
output
|
|
28
|
+
rescue Exception => e
|
|
29
|
+
error = error ? "#{error}: #{e.inspect}" : "Execution failed: #{e.inspect}"
|
|
30
|
+
die(error)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def execute!(cmd, error = nil)
|
|
34
|
+
puts "Executing: #{cmd}"
|
|
35
|
+
error = error ? "#{error}: Execution failed" : 'Execution failed'
|
|
36
|
+
die(error) unless system(cmd)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
extend ::Aggkit::Exec
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
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.4.
|
|
4
|
+
version: 0.4.4.12292
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Godko Ivan
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2019-
|
|
12
|
+
date: 2019-06-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: diplomat
|
|
@@ -103,6 +103,7 @@ executables:
|
|
|
103
103
|
- agg
|
|
104
104
|
- aggci
|
|
105
105
|
- aggconsul
|
|
106
|
+
- aggexec
|
|
106
107
|
- agggen
|
|
107
108
|
- agglock
|
|
108
109
|
- aggmerge
|
|
@@ -127,6 +128,7 @@ files:
|
|
|
127
128
|
- bin/agg
|
|
128
129
|
- bin/aggci
|
|
129
130
|
- bin/aggconsul
|
|
131
|
+
- bin/aggexec
|
|
130
132
|
- bin/agggen
|
|
131
133
|
- bin/agglock
|
|
132
134
|
- bin/aggmerge
|
|
@@ -167,7 +169,9 @@ files:
|
|
|
167
169
|
- lib/aggkit/childprocess/windows/process_builder.rb
|
|
168
170
|
- lib/aggkit/childprocess/windows/structs.rb
|
|
169
171
|
- lib/aggkit/ci.rb
|
|
172
|
+
- lib/aggkit/consul.rb
|
|
170
173
|
- lib/aggkit/env.rb
|
|
174
|
+
- lib/aggkit/exec.rb
|
|
171
175
|
- lib/aggkit/option_parser.rb
|
|
172
176
|
- lib/aggkit/runner.rb
|
|
173
177
|
- lib/aggkit/version.rb
|