ecs_helper 0.0.27 → 0.0.31

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
2
  SHA256:
3
- metadata.gz: f55caddc893a35d05fbf7778dcbc4c290b5384f3e6e085681fe2957a137deeb0
4
- data.tar.gz: aa48800b2c966ce376134df397a1c2fcebf9ba22ad678f058433a6c07876b87b
3
+ metadata.gz: 0fe6af3688b7c991c26eaf94f7b72461d3b643dbde163f945069bb72895a241c
4
+ data.tar.gz: 3af17336aedf1b2649fdc3bbd2d9a7d56bf596ac01ed64ecafc863a429c30bd0
5
5
  SHA512:
6
- metadata.gz: 0ac816e7907aa1e37b14392dd8d3cc0dbf5127e1a9f3bd6cec76ca4474d9a83e876eafbb003da8b6a48b11b67a9c163c8db4713c9ba1adee30efe1d4a399c9c8
7
- data.tar.gz: 45d514d5bfe25c083f98d44e561655a1feba0d44727fea02b1f1146dd63311eaf2e173e41d103d8238d1aa9eb0357c5171403b0726523d62eceaab6b5670827b
6
+ metadata.gz: ef01bdd22a9f0dfac372f623d75439c5e73782cc19769714b17d0e4c347cf7eff26e549804ca63dab23668d22d993d024f3a844ff30c335efd7190de486ec1eb
7
+ data.tar.gz: ab6db06d690ed72b3a72dc1f1c81e044eacf3253add69c7f90897db71e4b1f61f337898459be32fb3c1f96cefd139d96e86b2d828e10dce2c94840e3a66fa06f
data/Gemfile.lock CHANGED
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecs_helper (0.0.26)
4
+ ecs_helper (0.0.31)
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,10 +38,12 @@ 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
@@ -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,81 @@
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
+ end
49
+
50
+ def printable?
51
+ true
52
+ end
53
+
54
+ def run
55
+ check_session_manager_plugin
56
+ check_aws_cli
57
+ exec_command
58
+ end
59
+
60
+ def exec_command
61
+ "aws ecs execute-command --cluster #{cluster_arn} --task #{task_arn} --container #{helper.options[:container]} --command #{helper.options[:command]} --interactive"
62
+ end
63
+
64
+ private
65
+
66
+ def parse_version(string)
67
+ string.split('/')[1][0]
68
+ end
69
+
70
+ def cluster_arn
71
+ helper.current_cluster
72
+ end
73
+
74
+ def service_arn
75
+ helper.current_service
76
+ end
77
+
78
+ def task_arn
79
+ @task_arn ||= helper.client.list_tasks({cluster: cluster_arn, service_name: service_arn, desired_status: "RUNNING"})[0]
80
+ end
81
+ 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
 
@@ -44,7 +48,6 @@ class ECSHelper::Command
44
48
  def run
45
49
  command.validate
46
50
  result = command.run
47
- puts command if command.printable?
48
51
  puts result if command.printable?
49
52
  result
50
53
  end
@@ -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.27'
4
+ VERSION = '0.0.31'
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.27
4
+ version: 0.0.31
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