ecs_helper 0.0.26 → 0.0.30

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16ad520e81a6ee88b6cb3b67c8e68ee1cf0e724ea20d1fdd8595ffda8023be65
4
- data.tar.gz: 6d1398b798ae584fbb163d6234f01b209abb00bdd33489ee75e5ec2aae1f9bcd
3
+ metadata.gz: 3d7135d95e971a93420416be037655008bcbdb414d1ff278a5d6f054f7cae45e
4
+ data.tar.gz: 315b1bc56e9ec94be1d4ab05aa2ae969d3d6a5acacebcd899dad2a4a5664b7d7
5
5
  SHA512:
6
- metadata.gz: 44029c3fab73d9878376b1590bcba8a0f1ab39324a0aadac136f9736021514390fffec0c221d20769602c14934558221b1685eca8e1867a4f199e7790b5865b5
7
- data.tar.gz: abda0b0495455d13034a82345d2ff5dc09349a08b80c4b641b41ad3117f37fe3a28e25469f4857275babcad65673587dbb76f6398602e8b7447095a6a5f99e8d
6
+ metadata.gz: 607ed56e8ec010436a4b7bacac2a87c1135718e4c77530111056e8d3e6076598074d366924220eab781c30226adfaeda0b2d0073e0e3d89f652e7770dcdebf07
7
+ data.tar.gz: e591908c48d43ad96a0045e342a55849f31203dedc6046162b0afef791fd30f9d9934b5afc6dce02d8407d8c07091eb9843d4311d7eeaf3c38c38b1f72ffd76c
data/Gemfile.lock CHANGED
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecs_helper (0.0.25)
4
+ ecs_helper (0.0.30)
5
5
  aws-sdk-ecr (~> 1.42, >= 1.42)
6
6
  aws-sdk-ecrpublic (~> 1.3, >= 1.3)
7
7
  aws-sdk-ecs (~> 1.80, >= 1.80)
8
8
  aws-sdk-ssm (~> 1.0.0.rc7)
9
9
  colorize (~> 0.8, >= 0.8)
10
- json (~> 2.5, >= 2.5)
11
10
  terrapin (~> 0.6, >= 0.6)
12
11
 
13
12
  GEM
@@ -24,7 +23,7 @@ GEM
24
23
  aws-partitions (~> 1, >= 1.239.0)
25
24
  aws-sigv4 (~> 1.1)
26
25
  jmespath (~> 1.0)
27
- aws-sdk-ecr (1.46.0)
26
+ aws-sdk-ecr (1.47.0)
28
27
  aws-sdk-core (~> 3, >= 3.120.0)
29
28
  aws-sigv4 (~> 1.1)
30
29
  aws-sdk-ecrpublic (1.6.0)
@@ -38,6 +37,7 @@ GEM
38
37
  aws-sigv4 (~> 1.0)
39
38
  aws-sigv4 (1.4.0)
40
39
  aws-eventstream (~> 1, >= 1.0.2)
40
+ bump (0.10.0)
41
41
  byebug (11.1.3)
42
42
  climate_control (0.2.0)
43
43
  coderay (1.1.3)
@@ -46,7 +46,6 @@ GEM
46
46
  rexml
47
47
  hashdiff (1.0.1)
48
48
  jmespath (1.4.0)
49
- json (2.5.1)
50
49
  method_source (1.0.0)
51
50
  minitest (5.14.4)
52
51
  minitest-power_assert (0.3.1)
@@ -95,10 +94,12 @@ GEM
95
94
  hashdiff (>= 0.4.0, < 2.0.0)
96
95
 
97
96
  PLATFORMS
98
- x86_64-linux-musl
97
+ x86_64-darwin-18
98
+ x86_64-linux
99
99
 
100
100
  DEPENDENCIES
101
101
  awesome_print
102
+ bump
102
103
  bundler (~> 2.2)
103
104
  ecs_helper!
104
105
  minitest
@@ -113,4 +114,4 @@ DEPENDENCIES
113
114
  webmock
114
115
 
115
116
  BUNDLED WITH
116
- 2.2.22
117
+ 2.2.27
data/Makefile ADDED
@@ -0,0 +1,30 @@
1
+ .PHONY: test build bump-major bump-minor bump-patch help
2
+ .DEFAULT_GOAL := test
3
+ CURRENT_VERSION=$(shell bump current)
4
+ NEXT_PATCH=$(shell bump show-next patch)
5
+ NEXT_MINOR=$(shell bump show-next minor)
6
+ NEXT_MAJOR=$(shell bump show-next major)
7
+ GEM_VERSION=ecs_helper-${CURRENT_VERSION}.gem
8
+
9
+ test: ## Run the unit tests
10
+ bundle exec rake --trace
11
+
12
+ build: ## Build the ruby gem
13
+ gem build ecs_helper.gemspec
14
+
15
+ push:
16
+ gem push ${GEM_VERSION}
17
+
18
+ release:
19
+ bump set ${NEXT_PATCH}
20
+ make build
21
+ make push
22
+
23
+ bump-major: ## Bump the major version (1.0.0 -> 2.0.0)
24
+ bump major
25
+
26
+ bump-minor: ## Bump the minor version (0.1.0 -> 0.2.0)
27
+ bump minor
28
+
29
+ bump-patch: ## Bump the patch version (0.0.1 -> 0.0.2)
30
+ bump patch
data/ecs_helper.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency 'rubocop'
30
30
  s.add_development_dependency 'rubocop-minitest'
31
31
  s.add_development_dependency 'webmock'
32
+ s.add_development_dependency 'bump'
32
33
 
33
34
  s.add_development_dependency "bundler", "~> 2.2"
34
35
  s.add_development_dependency "rake"
@@ -38,7 +39,5 @@ Gem::Specification.new do |s|
38
39
  s.add_runtime_dependency 'aws-sdk-ecs', '~> 1.80', '>= 1.80'
39
40
  s.add_runtime_dependency 'aws-sdk-ssm', '~> 1.0.0.rc7'
40
41
  s.add_runtime_dependency 'colorize', '~> 0.8', '>= 0.8'
41
- s.add_runtime_dependency 'json', '~> 2.5', '>= 2.5'
42
42
  s.add_runtime_dependency 'terrapin', '~> 0.6', '>= 0.6'
43
-
44
43
  end
@@ -56,6 +56,14 @@ class ECSHelper::Client
56
56
  ecs.describe_tasks(params).tasks
57
57
  end
58
58
 
59
+ def list_tasks(params = {})
60
+ ecs.list_tasks(params).task_arns
61
+ end
62
+
63
+ def execute_command(params = {})
64
+ ecs.execute_command(params)
65
+ end
66
+
59
67
  # ECR
60
68
  def private_repositories(params = {})
61
69
  ecr.describe_repositories(params).repositories
@@ -22,6 +22,15 @@ class ECSHelper::Command::Base
22
22
  helper.project
23
23
  end
24
24
 
25
+ def check_bin(bin)
26
+ check_cmd = Terrapin::CommandLine.new("which #{bin}")
27
+ result = check_cmd.run
28
+ "success"
29
+ rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError => e
30
+ messages = ["#{bin} not found"]
31
+ raise ECSHelper::Error::BinNotFound.new(messages)
32
+ end
33
+
25
34
  def application
26
35
  helper.application
27
36
  end
@@ -29,20 +38,26 @@ class ECSHelper::Command::Base
29
38
  def validate
30
39
  required.each do |r|
31
40
  value = options[r]
32
- unless value
33
- puts "'#{r}' required for command '#{type}'".light_white
34
- puts option_parser.help
35
- exit
41
+ if value.nil?
42
+ messages = [
43
+ "'#{r}' required for command '#{type}'".light_white,
44
+ option_parser.help
45
+ ]
46
+ raise ECSHelper::Error::CommandValidationError.new(messages)
36
47
  end
37
48
  end
38
49
  end
39
50
 
40
- private
41
-
42
51
  def required
43
52
  []
44
53
  end
45
54
 
55
+ def printable?
56
+ false
57
+ end
58
+
59
+ private
60
+
46
61
  def processEqual(value)
47
62
  value.start_with?('=') ? value[1..-1] : value
48
63
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'terrapin'
4
+
5
+ class ECSHelper::Command::CheckExec < ECSHelper::Command::Base
6
+ def cmd_option_parser
7
+ options = { command: 'bash -c' }
8
+ parser = ::OptionParser.new do |opts|
9
+ opts.banner = 'Usage: ecs_helper check_exec'
10
+ opts.on('-p VALUE', '--project VALUE', "Set project name, if not specified will look at ENV['PROJECT'], will be used to detect cluster") do |p| options[:project] = processEqual(p) end
11
+ opts.on('-a VALUE', '--application VALUE', "Set application name, if not specified will look at ENV['APPLICATION'], will be used to detect service and task definition") do |a| options[:application] = processEqual(a) end
12
+ end
13
+ [parser, options]
14
+ end
15
+
16
+ def check_exec_bin
17
+ check_bin('check-ecs-exec')
18
+ end
19
+
20
+ def check_exec
21
+ exec_cmd = Terrapin::CommandLine.new("check-ecs-exec #{cluster_arn} #{task_arn}")
22
+ exec_cmd.run
23
+ end
24
+
25
+ def printable?
26
+ true
27
+ end
28
+
29
+ def run
30
+ log("Command", type)
31
+ log("Cluster", cluster_arn)
32
+ log("Service", service_arn)
33
+ log("Task", task_arn)
34
+ log("Options", options)
35
+ log("Check bin", check_exec_bin)
36
+ check_exec
37
+ end
38
+
39
+ private
40
+
41
+ def cluster_arn
42
+ helper.current_cluster
43
+ end
44
+
45
+ def service_arn
46
+ helper.current_service
47
+ end
48
+
49
+ def task_arn
50
+ @task_arn ||= helper.client.list_tasks({cluster: cluster_arn, service_name: service_arn, desired_status: "RUNNING"})[0]
51
+ end
52
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'terrapin'
4
+
5
+ class ECSHelper::Command::Exec < ECSHelper::Command::Base
6
+ def cmd_option_parser
7
+ options = { command: '/bin/bash' }
8
+ parser = ::OptionParser.new do |opts|
9
+ opts.banner = 'Usage: ecs_helper exec [options]. require session-manager-plugin and aws cli v2'
10
+ opts.on('-p VALUE', '--project VALUE',
11
+ "Set project name, if not specified will look at ENV['PROJECT'], will be used to detect cluster") do |p|
12
+ options[:project] = processEqual(p)
13
+ end
14
+ opts.on('-a VALUE', '--application VALUE',
15
+ "Set application name, if not specified will look at ENV['APPLICATION'], will be used to detect service and task definition") do |a|
16
+ options[:application] = processEqual(a)
17
+ end
18
+ opts.on('-c', '--container VALUE', 'Cache image before build, default false') { |c| options[:container] = processEqual(c) }
19
+ opts.on('--command VALUE', 'Command to execute') { |c| options[:command] = processEqual(c) }
20
+ end
21
+ [parser, options]
22
+ end
23
+
24
+ def required
25
+ [:container]
26
+ end
27
+
28
+ def check_session_manager_plugin
29
+ check_bin('session-manager-plugin')
30
+ end
31
+
32
+ def check_aws_cli_version
33
+ check_cmd = Terrapin::CommandLine.new("aws --version")
34
+ result = check_cmd.run
35
+ version = parse_version(result)
36
+ if version === "1"
37
+ messages = [
38
+ "Exec command requires aws cli v2".light_white,
39
+ cmd_option_parser[0].help
40
+ ]
41
+ raise ECSHelper::Error::CommandValidationError.new(messages)
42
+ end
43
+ end
44
+
45
+ def check_aws_cli
46
+ check_bin('aws')
47
+ check_aws_cli_version
48
+ "success"
49
+ end
50
+
51
+
52
+ def check_aws_cli_version
53
+ check_cmd = Terrapin::CommandLine.new("aws --version")
54
+ result = check_cmd.run
55
+ version = parse_version(result)
56
+ if version === "1"
57
+ messages = [
58
+ "Exec command requires aws cli v2".light_white,
59
+ cmd_option_parser[0].help
60
+ ]
61
+ raise ECSHelper::Error::CommandValidationError.new(messages)
62
+ end
63
+ end
64
+
65
+ def run
66
+ log("Command", type)
67
+ log("Cluster", cluster_arn)
68
+ log("Service", service_arn)
69
+ log("Task", task_arn)
70
+ log("Options", options)
71
+ log("Check session-manager-plugin ", check_session_manager_plugin)
72
+ log("Check aws cli version", check_aws_cli)
73
+ exec
74
+ end
75
+
76
+ def exec
77
+ exec_cmd = Terrapin::CommandLine.new("aws ecs execute-command --cluster #{cluster_arn} --task #{task_arn} --container #{helper.options[:container]} --command #{helper.options[:command]} --interactive")
78
+ exec_cmd.run
79
+ end
80
+
81
+ private
82
+
83
+ def parse_version(string)
84
+ string.split('/')[1][0]
85
+ end
86
+
87
+ def cluster_arn
88
+ helper.current_cluster
89
+ end
90
+
91
+ def service_arn
92
+ helper.current_service
93
+ end
94
+
95
+ def task_arn
96
+ @task_arn ||= helper.client.list_tasks({cluster: cluster_arn, service_name: service_arn, desired_status: "RUNNING"})[0]
97
+ end
98
+ end
@@ -18,6 +18,10 @@ class ECSHelper::Command::ExportEnvSecrets < ECSHelper::Command::Base
18
18
  []
19
19
  end
20
20
 
21
+ def printable?
22
+ true
23
+ end
24
+
21
25
  def run
22
26
  return log("No ENV secrets to export. Please pass ENV variables names using -n") if options[:env_vars].empty?
23
27
  export_values
@@ -42,5 +46,6 @@ class ECSHelper::Command::ExportEnvSecrets < ECSHelper::Command::Base
42
46
  rescue Aws::SSM::Errors::ParameterNotFound
43
47
  next
44
48
  end).join(' ')
49
+ variables
45
50
  end
46
51
  end
@@ -14,6 +14,10 @@ class ECSHelper::Command::ExportImages < ECSHelper::Command::Base
14
14
  []
15
15
  end
16
16
 
17
+ def printable?
18
+ true
19
+ end
20
+
17
21
  def run
18
22
  export_images
19
23
  end
@@ -5,6 +5,8 @@ class ECSHelper::Command
5
5
  autoload :Deploy, 'ecs_helper/command/deploy'
6
6
  autoload :ExportImages, 'ecs_helper/command/export_images'
7
7
  autoload :ECRLogin, 'ecs_helper/command/ecr_login'
8
+ autoload :Exec, 'ecs_helper/command/exec'
9
+ autoload :CheckExec, 'ecs_helper/command/check_exec'
8
10
  autoload :RunCommand, 'ecs_helper/command/run_command'
9
11
  autoload :ExportEnvSecrets, 'ecs_helper/command/export_env_secrets'
10
12
 
@@ -15,6 +17,8 @@ class ECSHelper::Command
15
17
  "ecr_login" => ECRLogin,
16
18
  "run_command" => RunCommand,
17
19
  "export_env_secrets" => ExportEnvSecrets,
20
+ "exec" => Exec,
21
+ "check_exec" => CheckExec,
18
22
  }
19
23
  AVAILABLE_COMMANDS = CMD_MAPPING.keys
20
24
 
@@ -43,7 +47,9 @@ class ECSHelper::Command
43
47
 
44
48
  def run
45
49
  command.validate
46
- command.run
50
+ result = command.run
51
+ puts result if command.printable?
52
+ result
47
53
  end
48
54
  end
49
55
 
@@ -0,0 +1,2 @@
1
+ class ECSHelper::Error::BinNotFound < ECSHelper::Error::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class ECSHelper::Error::CommandValidationError < ECSHelper::Error::Base
2
+ end
@@ -3,4 +3,6 @@
3
3
  class ECSHelper::Error
4
4
  autoload :Base, 'ecs_helper/error/base'
5
5
  autoload :CommandNotFound, 'ecs_helper/error/command_not_found'
6
+ autoload :CommandValidationError, 'ecs_helper/error/command_validation_error'
7
+ autoload :BinNotFound, 'ecs_helper/error/bin_not_found'
6
8
  end
@@ -1,6 +1,6 @@
1
1
  module ECSHelper::Logging
2
2
  def console(message)
3
- puts message if ENV["SKIP_LOGS"].nil?
3
+ puts message if ENV["SKIP_LOGS"] != 'true'
4
4
  end
5
5
 
6
6
  def log(title, message = nil, color = "light_white")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ECSHelper
4
- VERSION = '0.0.26'
4
+ VERSION = '0.0.30'
5
5
  end
data/lib/ecs_helper.rb CHANGED
@@ -6,6 +6,8 @@ class ECSHelper
6
6
  extend Forwardable
7
7
  attr_accessor :options, :client, :command, :parser, :cluster_helper, :service_helper, :common_helper
8
8
 
9
+
10
+ autoload :VERSION, 'ecs_helper/version'
9
11
  autoload :Client, 'ecs_helper/client'
10
12
  autoload :CommonHelper, 'ecs_helper/common_helper'
11
13
  autoload :ClusterHelper, 'ecs_helper/cluster_helper'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Petrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-20 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: bump
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: bundler
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -272,26 +286,6 @@ dependencies:
272
286
  - - "~>"
273
287
  - !ruby/object:Gem::Version
274
288
  version: '0.8'
275
- - !ruby/object:Gem::Dependency
276
- name: json
277
- requirement: !ruby/object:Gem::Requirement
278
- requirements:
279
- - - ">="
280
- - !ruby/object:Gem::Version
281
- version: '2.5'
282
- - - "~>"
283
- - !ruby/object:Gem::Version
284
- version: '2.5'
285
- type: :runtime
286
- prerelease: false
287
- version_requirements: !ruby/object:Gem::Requirement
288
- requirements:
289
- - - ">="
290
- - !ruby/object:Gem::Version
291
- version: '2.5'
292
- - - "~>"
293
- - !ruby/object:Gem::Version
294
- version: '2.5'
295
289
  - !ruby/object:Gem::Dependency
296
290
  name: terrapin
297
291
  requirement: !ruby/object:Gem::Requirement
@@ -323,6 +317,7 @@ files:
323
317
  - Dockerfile
324
318
  - Gemfile
325
319
  - Gemfile.lock
320
+ - Makefile
326
321
  - Rakefile
327
322
  - bin/console
328
323
  - bin/ecs_helper
@@ -334,15 +329,19 @@ files:
334
329
  - lib/ecs_helper/command.rb
335
330
  - lib/ecs_helper/command/base.rb
336
331
  - lib/ecs_helper/command/build_and_push.rb
332
+ - lib/ecs_helper/command/check_exec.rb
337
333
  - lib/ecs_helper/command/deploy.rb
338
334
  - lib/ecs_helper/command/ecr_login.rb
335
+ - lib/ecs_helper/command/exec.rb
339
336
  - lib/ecs_helper/command/export_env_secrets.rb
340
337
  - lib/ecs_helper/command/export_images.rb
341
338
  - lib/ecs_helper/command/run_command.rb
342
339
  - lib/ecs_helper/common_helper.rb
343
340
  - lib/ecs_helper/error.rb
344
341
  - lib/ecs_helper/error/base.rb
342
+ - lib/ecs_helper/error/bin_not_found.rb
345
343
  - lib/ecs_helper/error/command_not_found.rb
344
+ - lib/ecs_helper/error/command_validation_error.rb
346
345
  - lib/ecs_helper/logging.rb
347
346
  - lib/ecs_helper/service_helper.rb
348
347
  - lib/ecs_helper/task_definition_helper.rb