aggkit 0.3.1.8768 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: da7e110db65fee090004aa89ebe7b9e51d61b29d
4
- data.tar.gz: a23634dedbc61ead7fdf2fd82db903d54a9db349
2
+ SHA256:
3
+ metadata.gz: 6791e59023a468170166128cafab8d1f55f699a842c5ddfc95c11db3643120a7
4
+ data.tar.gz: dcda7014d58af1a2c9efcb2cee00fd9d0512c0dcd41b0ec3356bf5f2c8d5ccaa
5
5
  SHA512:
6
- metadata.gz: fc6a2f04341e21addd3188c4902802edf68c25740c55e6986f4c2fd8005e54b2c8bf1bd34aa6404d6c3a5d458810f0e6a4e1c87f040c001d9fcd572a12ee4ff7
7
- data.tar.gz: 5cd039ed3153e03b5f1c8eec26d3058df0d28128a6709155334424215bdc5508f2fc290737bf698309fed4c0b509eb4142b63e21d4f5cf1329d97b3b6a718f64
6
+ metadata.gz: cd8d1d90dbb6d6d76589b4aa238e00e661dae5402fd2c8f791273b7f1ae0542a82d23ca97409b7aa9c05e914dd8dbe9e3b35fc6ef7e76e2a6d5649e5c3f2bff8
7
+ data.tar.gz: 1bce235ef0eecfc515224ebc201cb063b51a442df7abffbc81e542a4d638e3abd887f74c6fd8d28751764dced313333e4cd0795a72756e823640c1d6aa6bd29f
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ AllCops:
4
4
  - 'storage/**/*'
5
5
  - 'docker/**/*'
6
6
  - 'lib/aggkit/childprocess/**/*'
7
- - 'lib/aggkit/childprocess,rb'
7
+ - 'lib/aggkit/childprocess.rb'
8
8
 
9
9
 
10
10
  Security/YAMLLoad:
@@ -36,7 +36,9 @@ Style/Documentation:
36
36
  Style/Lambda:
37
37
  Enabled: false
38
38
 
39
-
39
+ Style/RedundantSelf:
40
+ Enabled: false
41
+
40
42
  Style/RaiseArgs:
41
43
  EnforcedStyle: compact
42
44
 
@@ -45,6 +47,12 @@ Style/SpecialGlobalVars:
45
47
 
46
48
  Metrics/LineLength:
47
49
  Max: 100
50
+ IgnoredPatterns: ['(\A|\s)#']
51
+
52
+ Layout/TrailingBlankLines:
53
+ Enabled: true
54
+ AutoCorrect: true
55
+ EnforcedStyle: final_blank_line
48
56
 
49
57
  #Layout/IndentationWidth:
50
58
  # Enabled: true
@@ -55,9 +63,24 @@ Metrics/LineLength:
55
63
 
56
64
  #Layout/ElseAlignment:
57
65
  # Enabled: false
66
+
67
+ Layout/MultilineOperationIndentation:
68
+ EnforcedStyle: indented
69
+
70
+ Layout/RescueEnsureAlignment:
71
+ Enabled: false
58
72
 
59
- #Layout/EndAlignment:
60
- # Enabled: false
73
+ Layout/EndAlignment:
74
+ Enabled: true
75
+ EnforcedStyleAlignWith: variable
76
+ AutoCorrect: true
77
+
78
+ Layout/AlignHash:
79
+ EnforcedColonStyle: table
80
+ EnforcedHashRocketStyle: table
81
+
82
+ Style/BracesAroundHashParameters:
83
+ EnforcedStyle: context_dependent
61
84
 
62
85
  #Lint/AssignmentInCondition:
63
86
  # Enabled: false
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in aggredator.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'diplomat', git: 'https://github.com/RnD-Soft/diplomat.git', branch: 'master'
7
+
6
8
 
7
9
  group :test do
8
10
  gem 'awesome_print'
@@ -10,3 +12,4 @@ group :test do
10
12
  gem 'rspec-retry'
11
13
  gem 'rspec-set'
12
14
  end
15
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,15 @@
1
+ GIT
2
+ remote: https://github.com/RnD-Soft/diplomat.git
3
+ revision: 9e90b9317b0572c881342599024b18aec67e5c29
4
+ branch: master
5
+ specs:
6
+ diplomat (2.0.4)
7
+ faraday (~> 0.9)
8
+
1
9
  PATH
2
10
  remote: .
3
11
  specs:
4
- aggkit (0.3.1.8768)
12
+ aggkit (0.3.4)
5
13
  diplomat
6
14
  dotenv
7
15
  json
@@ -12,13 +20,10 @@ GEM
12
20
  specs:
13
21
  awesome_print (1.8.0)
14
22
  diff-lcs (1.3)
15
- diplomat (2.0.2)
16
- faraday (~> 0.9)
17
- json
18
- dotenv (2.6.0)
23
+ dotenv (2.7.1)
19
24
  faraday (0.15.4)
20
25
  multipart-post (>= 1.2, < 3)
21
- json (2.1.0)
26
+ json (2.2.0)
22
27
  multipart-post (2.0.0)
23
28
  rake (10.5.0)
24
29
  rspec (3.8.0)
@@ -46,6 +51,7 @@ DEPENDENCIES
46
51
  aggkit!
47
52
  awesome_print
48
53
  bundler (~> 1.14)
54
+ diplomat!
49
55
  rake (~> 10.0)
50
56
  rspec
51
57
  rspec-retry
data/aggkit.gemspec CHANGED
@@ -31,9 +31,10 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency 'dotenv'
32
32
  spec.add_dependency 'json'
33
33
  spec.add_dependency 'tty-tree'
34
-
35
-
34
+
35
+
36
36
 
37
37
  spec.add_development_dependency 'bundler', '~> 1.14'
38
38
  spec.add_development_dependency 'rake', '~> 10.0'
39
39
  end
40
+
data/bin/agg CHANGED
@@ -29,10 +29,10 @@ exmaple_usage = "
29
29
 
30
30
  env_cmd_parser = OptionParser.new do |o|
31
31
  o.banner = "Usage: #{UTIL} env [options]"
32
- o.on("-l", "--list", "list environments") do
32
+ o.on('-l', '--list', 'list environments') do
33
33
  @opts[:list] = true
34
34
  end
35
- o.on("-t", "--tree", "print as tree") do
35
+ o.on('-t', '--tree', 'print as tree') do
36
36
  @opts[:tree] = true
37
37
  end
38
38
  end
@@ -42,48 +42,51 @@ exec_cmd_parser = OptionParser.new do |o|
42
42
  o.on('-p', '--pristine', "not include the parent processes' environment when exec child process") do
43
43
  @opts[:pristine] = true
44
44
  end
45
- o.on('--cd', "cd to envroot") do
45
+ o.on('--cd', 'cd to envroot') do
46
46
  @opts[:cd] = true
47
47
  end
48
+ o.on('--wrap', 'wrap in docker-compose down -v and logs') do
49
+ @opts[:wrap] = true
50
+ end
48
51
  end
49
52
 
50
- @single_subcommands ||= {
53
+ @single_subcommands ||= {
51
54
  'exec' => exec_cmd_parser
52
55
  }
53
56
 
54
- @global_subcommands ||= {
57
+ @global_subcommands ||= {
55
58
  'env' => env_cmd_parser
56
59
  }
57
60
 
58
61
  single_parser = OptionParser.new do |o|
59
62
  o.banner = "Aggredator environment manager\nUsage: #{UTIL} <envname> [options] [subcommand [options]]"
60
-
61
- o.on("-s", "--show", "show envname details") do
63
+
64
+ o.on('-s', '--show', 'show envname details') do
62
65
  @opts[:show] = true
63
66
  end
64
67
 
65
- o.on("-e", "--export", "show variable for export") do
68
+ o.on('-e', '--export', 'show variable for export') do
66
69
  @opts[:export] = true
67
70
  end
68
71
 
69
- o.on("-r", "--release", "make release compose-result.yml(without build)") do
72
+ o.on('-r', '--release', 'make release compose-result.yml(without build)') do
70
73
  @opts[:release] = true
71
74
  end
72
75
 
73
- o.on("-h", "--help", "show help") do
76
+ o.on('-h', '--help', 'show help') do
74
77
  puts o.help
75
78
  exit 0
76
79
  end
77
80
 
78
- o.separator ""
81
+ o.separator ''
79
82
  o.separator "Subcommands: #{@single_subcommands.keys.join(', ')}"
80
83
  end
81
84
 
82
85
  global_parser = OptionParser.new do |o|
83
86
  o.banner = "Aggredator manager\nUsage: #{UTIL} [envname] [options] [subcommand [options]]"
84
-
85
- o.on("--resolve=address", "resolve hostname or IP to IP") do |address|
86
- resolved = `getent hosts #{address.to_s.strip}`.split.first.to_s
87
+
88
+ o.on('--resolve=address', 'resolve hostname or IP to IP') do |address|
89
+ resolved = `getent ahosts #{address.to_s.strip}`.split.first.to_s
87
90
  if resolved.empty?
88
91
  puts address.to_s.strip
89
92
  else
@@ -92,24 +95,21 @@ global_parser = OptionParser.new do |o|
92
95
  exit 0
93
96
  end
94
97
 
95
- o.on("-h", "--help", "show help") do
98
+ o.on('-h', '--help', 'show help') do
96
99
  puts o.help
97
100
  exit 0
98
101
  end
99
102
 
100
- o.separator ""
103
+ o.separator ''
101
104
  o.separator "Subcommands: #{@global_subcommands.keys.join(', ')}"
102
105
 
103
- o.separator ""
106
+ o.separator ''
104
107
  o.separator "Examples:\n#{exmaple_usage}"
105
108
  end
106
109
 
107
110
  begin
108
- if Aggkit::Env.list.include?(ARGV.first)
109
- $env = Aggkit::Env.new(ARGV.shift)
110
- end
111
- rescue => e
112
-
111
+ $env = Aggkit::Env.new(ARGV.shift) if Aggkit::Env.list.include?(ARGV.first)
112
+ rescue StandardError => e
113
113
  end
114
114
 
115
115
  if $env
@@ -127,7 +127,7 @@ end
127
127
 
128
128
 
129
129
  if command = ARGV.shift
130
- if @subcommands.has_key?(command)
130
+ if @subcommands.key?(command)
131
131
  $parser = @subcommands[command]
132
132
  @commands[command.to_sym] = true
133
133
  $parser.parse!
@@ -139,7 +139,7 @@ if command = ARGV.shift
139
139
  end
140
140
 
141
141
 
142
- def env_command opts
142
+ def env_command(opts)
143
143
  if opts[:list]
144
144
  envs = Aggkit::Env.list
145
145
  # if opts[:tree]
@@ -154,22 +154,40 @@ def env_command opts
154
154
  # puts data
155
155
  # puts TTY::Tree.new(data.first).render
156
156
  # else
157
- puts envs
157
+ puts envs
158
158
  # end
159
159
  exit 0
160
160
  end
161
161
  end
162
162
 
163
- def exec_command opts
164
- raise "envname not specified!" unless $env
165
- raise "cmd not specified!" unless @exec
163
+ def wrap_with_compose(cmd)
164
+ system('docker-compose down -v || true')
165
+
166
+ system(cmd)
167
+ result = $?
168
+ system('docker-compose logs') unless result.success?
169
+ result.exitstatus
170
+ ensure
171
+ system('docker-compose down -v || true')
172
+ end
166
173
 
167
- $env.prepare release: @opts[:release]
174
+ def exec_command(opts)
175
+ raise 'envname not specified!' unless $env
176
+ raise 'cmd not specified!' unless @exec
177
+
178
+ $env.prepare release: opts[:release]
168
179
  e = $env.environment
169
180
  e = ENV.to_h.merge(e) unless opts[:pristine]
170
181
 
171
182
  Dir.chdir $env.env_root if opts[:cd]
172
- exec(e, @exec, unsetenv_others: true)
183
+
184
+ if opts[:wrap]
185
+ Aggkit::Env.with_env(e) do
186
+ exit(wrap_with_compose(@exec))
187
+ end
188
+ else
189
+ exec(e, @exec, unsetenv_others: true)
190
+ end
173
191
  end
174
192
 
175
193
  if @commands[:global]
@@ -180,7 +198,7 @@ if @commands[:single]
180
198
  exec_command(@opts) if @commands[:exec]
181
199
 
182
200
  if @opts[:show]
183
- raise "envname not specified!" unless $env
201
+ raise 'envname not specified!' unless $env
184
202
 
185
203
  $env.prepare release: @opts[:release]
186
204
  puts JSON.pretty_generate($env.show)
@@ -188,11 +206,11 @@ if @commands[:single]
188
206
  end
189
207
 
190
208
  if @opts[:export]
191
- raise "envname not specified!" unless $env
209
+ raise 'envname not specified!' unless $env
192
210
 
193
211
  $env.prepare release: @opts[:release]
194
212
  $env.environment.each_pair do |k, v|
195
- puts "export #{k.to_s}=\"#{v.to_s}\""
213
+ puts "export #{k}=\"#{v}\""
196
214
  end
197
215
  exit 0
198
216
  end
@@ -201,3 +219,4 @@ end
201
219
 
202
220
  STDOUT.puts $parser.help
203
221
  exit 1
222
+
data/bin/aggci CHANGED
@@ -11,69 +11,70 @@ include Aggkit::Ci
11
11
  tag: ENV['CORE_TAG'] || ENV['CI_COMMIT_TAG'] || 'latest'
12
12
  }
13
13
 
14
- def parse_services services
14
+ def parse_services(services)
15
15
  [services].flatten.join(' ').split(/[,;| \n]/).map(&:strip).reject(&:empty?).uniq.sort
16
16
  end
17
17
 
18
18
  parser = OptionParser.new do |o|
19
19
  o.banner = "Usage: #{UTIL} [options]"
20
20
 
21
- o.on("--pull-cache services", 'Pull cache from docker regestry') do |services|
21
+ o.on('--pull-cache services', 'Pull cache from docker regestry') do |services|
22
22
  @opts[:pull] = parse_services(services)
23
23
  end
24
24
 
25
- o.on("--push-cache services", 'Push cache to docker regestry') do |services|
25
+ o.on('--push-cache services', 'Push cache to docker regestry') do |services|
26
26
  @opts[:push] = parse_services(services)
27
27
  end
28
28
 
29
- o.on("--promote services", 'Promote service images to --stage') do |services|
29
+ o.on('--promote services', 'Promote service images to --stage') do |services|
30
30
  @opts[:promote] = parse_services(services)
31
31
  end
32
32
 
33
- o.on("--promote-tag tag", 'Promote service images') do |tag|
33
+ o.on('--promote-tag tag', 'Promote service images') do |tag|
34
34
  @opts[:promotetag] = tag.to_s.strip
35
35
  end
36
36
 
37
- o.on("--stage stage", 'stage for image promotion Stages: dev, stge, tag') do |stage|
37
+ o.on('--stage stage', 'stage for image promotion Stages: dev, stge, tag') do |stage|
38
38
  @opts[:stage] = stage.to_s.strip
39
39
  end
40
40
 
41
- o.on("--clean services", 'remove tags and images excluding last stable') do |services|
41
+ o.on('--clean services', 'remove tags and images excluding last stable') do |services|
42
42
  @opts[:clean] = parse_services(services)
43
43
  end
44
44
 
45
- o.on("--services services", 'list or services to process') do |services|
45
+ o.on('--services services', 'list or services to process') do |services|
46
46
  @opts[:services] = parse_services(services)
47
47
  end
48
48
 
49
- o.on("--ssh-deploy env", 'ssh') do |env_and_server|
49
+ o.on('--ssh-deploy env', 'ssh') do |env_and_server|
50
50
  env, server = env_and_server.strip.split('@')
51
- @opts[:deploy] = {env: env, server: server}
51
+ @opts[:deploy] = { env: env, server: server }
52
52
  end
53
53
 
54
- o.on("--ssh-core-deploy env", 'ssh') do |env_and_server|
54
+ o.on('--ssh-core-deploy env', 'ssh') do |env_and_server|
55
55
  env, server = env_and_server.strip.split('@')
56
- @opts[:core_deploy] = {env: env, server: server}
56
+ @opts[:core_deploy] = { env: env, server: server }
57
57
  end
58
58
 
59
59
  o.on("--tag tag=#{@opts[:tag].inspect}", 'Use tag as default tag for images') do |tag|
60
60
  @opts[:tag] = tag.to_s.strip
61
61
  end
62
-
63
62
  end
64
63
  parser.parse!
65
64
 
66
65
  if services = @opts[:pull]
67
- raise "tag not defined" if @opts[:tag].to_s.empty?
66
+ raise 'tag not defined' if @opts[:tag].to_s.empty?
67
+
68
68
  pull_images_cache services, @opts[:tag]
69
69
  exit 0
70
70
  elsif services = @opts[:push]
71
- raise "tag not defined" if @opts[:tag].to_s.empty?
71
+ raise 'tag not defined' if @opts[:tag].to_s.empty?
72
+
72
73
  push_images_cache services, @opts[:tag]
73
74
  exit 0
74
75
  elsif services = @opts[:promote]
75
- raise "tag not defined" if @opts[:tag].to_s.empty?
76
- raise "stage not defined" if @opts[:stage].to_s.empty?
76
+ raise 'tag not defined' if @opts[:tag].to_s.empty?
77
+ raise 'stage not defined' if @opts[:stage].to_s.empty?
77
78
 
78
79
  case @opts[:stage]
79
80
  when 'dev'
@@ -81,32 +82,36 @@ elsif services = @opts[:promote]
81
82
  when 'stage'
82
83
  promote_services_to_stage!(services, @opts[:tag])
83
84
  when 'tag'
84
- raise "promote-tag not defined" if @opts[:promotetag].to_s.empty?
85
+ raise 'promote-tag not defined' if @opts[:promotetag].to_s.empty?
86
+
85
87
  promote_services_to_tag!(services, @opts[:tag], @opts[:promotetag])
86
- else
88
+ else
87
89
  raise "invalid stage #{@opts[:stage].inspect} for promotion"
88
90
  end
89
91
 
90
92
  exit 0
91
93
 
92
94
  elsif services = @opts[:clean]
93
- raise "tag not defined" if @opts[:tag].to_s.empty?
95
+ raise 'tag not defined' if @opts[:tag].to_s.empty?
96
+
94
97
  clean_services services, @opts[:tag]
95
98
  exit 0
96
99
 
97
100
  elsif deploy = @opts[:deploy]
98
101
  @opts[:services] ||= []
99
- raise "tag not defined" if @opts[:tag].to_s.empty?
100
- raise "stage not defined" if @opts[:stage].to_s.empty?
101
- raise "services not defined" if @opts[:services].empty?
102
+ raise 'tag not defined' if @opts[:tag].to_s.empty?
103
+ raise 'stage not defined' if @opts[:stage].to_s.empty?
104
+ raise 'services not defined' if @opts[:services].empty?
105
+
102
106
  ssh_deploy @opts[:services], deploy[:env], deploy[:server], @opts[:tag], @opts[:stage]
103
107
  exit 0
104
108
 
105
109
  elsif deploy = @opts[:core_deploy]
106
110
  @opts[:services] ||= []
107
- raise "tag not defined" if @opts[:tag].to_s.empty?
108
- raise "stage not defined" if @opts[:stage].to_s.empty?
109
- raise "services not defined" if @opts[:services].empty?
111
+ raise 'tag not defined' if @opts[:tag].to_s.empty?
112
+ raise 'stage not defined' if @opts[:stage].to_s.empty?
113
+ raise 'services not defined' if @opts[:services].empty?
114
+
110
115
  ssh_core_deploy @opts[:services], deploy[:env], deploy[:server], @opts[:tag], @opts[:stage]
111
116
  exit 0
112
117
  end
data/bin/aggconsul CHANGED
@@ -93,8 +93,8 @@ def key_to_env(key)
93
93
  end
94
94
 
95
95
  def dereferenced_value(value)
96
- if @opts[:dereference] && value && value[/^consul:\/\//]
97
- reference_path = value.gsub(/^consul:\/\//, '')
96
+ if @opts[:dereference] && value && value[%r{^consul://}]
97
+ reference_path = value.gsub(%r{^consul://}, '')
98
98
  dereferenced_value(Diplomat::Kv.get(reference_path))
99
99
  else
100
100
  value
@@ -109,11 +109,11 @@ if @opts[:init]
109
109
  raise OptionParser::MissingArgument.new('config') unless @opts[:config]
110
110
 
111
111
  services = if service = @opts[:service]
112
- {
113
- service => @opts[:config][service]
114
- }
115
- else
116
- @opts[:config]
112
+ {
113
+ service => @opts[:config][service]
114
+ }
115
+ else
116
+ @opts[:config]
117
117
  end
118
118
 
119
119
  services.each_pair do |service, config|
@@ -124,9 +124,9 @@ if @opts[:init]
124
124
  config.each_pair do |env, item|
125
125
  key = "#{path}/#{key_to_consul(env)}"
126
126
  value = if @opts[:upload] && item['file']
127
- File.read(item['file'])
128
- else
129
- item['value'] || item['default'] || item['file']
127
+ File.read(item['file'])
128
+ else
129
+ item['value'] || item['default'] || item['file']
130
130
  end
131
131
 
132
132
  empty = begin
@@ -147,10 +147,10 @@ if @opts[:show]
147
147
  config = {}
148
148
 
149
149
  path = if service = @opts[:service]
150
- "services/env/#{service}/"
151
- else
152
- 'services/env/'
153
- end
150
+ "services/env/#{service}/"
151
+ else
152
+ 'services/env/'
153
+ end
154
154
 
155
155
  answer = Diplomat::Kv.get(path, recurse: true, convert_to_hash: true) || die("Can't get #{path} from Consul")
156
156
  answer['services']['env'].each_pair do |service, env|
@@ -160,7 +160,7 @@ if @opts[:show]
160
160
  value = dereferenced_value(value)
161
161
 
162
162
  cfg[key_to_env(key)] = {
163
- env: key_to_env(key),
163
+ env: key_to_env(key),
164
164
  value: value
165
165
  }
166
166
  end
@@ -220,3 +220,4 @@ end
220
220
 
221
221
  STDOUT.puts parser.help
222
222
  exit 1
223
+