ecs_helper 0.0.28 → 0.0.32

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: d7d7e1d62103b4759b19005b1bc248f562749be0bc5f7c5b1b351d2e5a7874f8
4
- data.tar.gz: 8d2d35ef50190a45ed9ea689485d43776026eef91c496a3353c200a42c50389f
3
+ metadata.gz: 961fe1a06c1f8f0db5b128e0e06b4c531298cf9e4361b931108501044ff94f0e
4
+ data.tar.gz: 5a52f1efc1f95ee616d9e6728ebe04f8d128abe61ec8221ef1655a128d550641
5
5
  SHA512:
6
- metadata.gz: 4440e1cc6a9cec9f38e8ea485c86131ebdf15635464bf577b02cb6557b908f43a1769b5289b826815d9ad8282c14446677f6b478a1771ce82706beeb2ea4d04d
7
- data.tar.gz: c4cf0985abb1934130d7ad7266554d4c30643de641e2f3e3bb3d7b625fe1eb0b9c5c88d70ff935f2e9663d1ddb65e8c3782069782c8b4dd8aafb06ffa6644901
6
+ metadata.gz: aaae93742329f95d0abdde33a6df3b2d57645ae37920a94983cef2c77b9aa414ca186735e8cbd1b50155e2c06021058d8ac4c87d42fb5dc5497c3eab351950e3
7
+ data.tar.gz: d67641f9d8a1d4f97b95c6c5cca89ce1ac171eeda031388520613500482aee6b7df213d6b2473a91f3a9aea72911fb34113cd8e8ed7bdae8d6102d2a97c4f6e1
data/Gemfile.lock CHANGED
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecs_helper (0.0.28)
4
+ ecs_helper (0.0.32)
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
@@ -18,19 +17,19 @@ GEM
18
17
  ast (2.4.2)
19
18
  awesome_print (1.9.2)
20
19
  aws-eventstream (1.2.0)
21
- aws-partitions (1.503.0)
22
- aws-sdk-core (3.121.0)
20
+ aws-partitions (1.515.0)
21
+ aws-sdk-core (3.121.1)
23
22
  aws-eventstream (~> 1, >= 1.0.2)
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)
31
30
  aws-sdk-core (~> 3, >= 3.120.0)
32
31
  aws-sigv4 (~> 1.1)
33
- aws-sdk-ecs (1.85.0)
32
+ aws-sdk-ecs (1.86.0)
34
33
  aws-sdk-core (~> 3, >= 3.120.0)
35
34
  aws-sigv4 (~> 1.1)
36
35
  aws-sdk-ssm (1.0.0)
@@ -47,7 +46,6 @@ GEM
47
46
  rexml
48
47
  hashdiff (1.0.1)
49
48
  jmespath (1.4.0)
50
- json (2.5.1)
51
49
  method_source (1.0.0)
52
50
  minitest (5.14.4)
53
51
  minitest-power_assert (0.3.1)
@@ -96,6 +94,7 @@ GEM
96
94
  hashdiff (>= 0.4.0, < 2.0.0)
97
95
 
98
96
  PLATFORMS
97
+ aarch64-linux
99
98
  x86_64-darwin-18
100
99
  x86_64-linux
101
100
 
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
@@ -39,7 +39,5 @@ Gem::Specification.new do |s|
39
39
  s.add_runtime_dependency 'aws-sdk-ecs', '~> 1.80', '>= 1.80'
40
40
  s.add_runtime_dependency 'aws-sdk-ssm', '~> 1.0.0.rc7'
41
41
  s.add_runtime_dependency 'colorize', '~> 0.8', '>= 0.8'
42
- s.add_runtime_dependency 'json', '~> 2.5', '>= 2.5'
43
42
  s.add_runtime_dependency 'terrapin', '~> 0.6', '>= 0.6'
44
-
45
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
@@ -24,6 +24,7 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
24
24
  end
25
25
  opts.on('-c', '--cache', 'Cache image before build, default false') { options[:cache] = true }
26
26
  opts.on('--build-arg=VALUE', 'Pass --build-arg to the build command') { |o| options[:build_args] << o }
27
+ opts.on('-e', '--env-prefix', 'Add environment name as a prefix to the version tag, default false') { options[:env_prefix] = true }
27
28
  end
28
29
  [parser, options]
29
30
  end
@@ -90,7 +91,11 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
90
91
  end
91
92
 
92
93
  def version_tag
93
- "#{repository}:#{helper.version}"
94
+ if options[:env_prefix]
95
+ "#{repository}:#{helper.environment}-#{helper.version}"
96
+ else
97
+ "#{repository}:#{helper.version}"
98
+ end
94
99
  end
95
100
 
96
101
  def project
@@ -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
 
@@ -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.28'
4
+ VERSION = '0.0.32'
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.28
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Petrov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-20 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -196,60 +196,60 @@ dependencies:
196
196
  name: aws-sdk-ecr
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ">="
199
+ - - "~>"
200
200
  - !ruby/object:Gem::Version
201
201
  version: '1.42'
202
- - - "~>"
202
+ - - ">="
203
203
  - !ruby/object:Gem::Version
204
204
  version: '1.42'
205
205
  type: :runtime
206
206
  prerelease: false
207
207
  version_requirements: !ruby/object:Gem::Requirement
208
208
  requirements:
209
- - - ">="
209
+ - - "~>"
210
210
  - !ruby/object:Gem::Version
211
211
  version: '1.42'
212
- - - "~>"
212
+ - - ">="
213
213
  - !ruby/object:Gem::Version
214
214
  version: '1.42'
215
215
  - !ruby/object:Gem::Dependency
216
216
  name: aws-sdk-ecrpublic
217
217
  requirement: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - ">="
219
+ - - "~>"
220
220
  - !ruby/object:Gem::Version
221
221
  version: '1.3'
222
- - - "~>"
222
+ - - ">="
223
223
  - !ruby/object:Gem::Version
224
224
  version: '1.3'
225
225
  type: :runtime
226
226
  prerelease: false
227
227
  version_requirements: !ruby/object:Gem::Requirement
228
228
  requirements:
229
- - - ">="
229
+ - - "~>"
230
230
  - !ruby/object:Gem::Version
231
231
  version: '1.3'
232
- - - "~>"
232
+ - - ">="
233
233
  - !ruby/object:Gem::Version
234
234
  version: '1.3'
235
235
  - !ruby/object:Gem::Dependency
236
236
  name: aws-sdk-ecs
237
237
  requirement: !ruby/object:Gem::Requirement
238
238
  requirements:
239
- - - ">="
239
+ - - "~>"
240
240
  - !ruby/object:Gem::Version
241
241
  version: '1.80'
242
- - - "~>"
242
+ - - ">="
243
243
  - !ruby/object:Gem::Version
244
244
  version: '1.80'
245
245
  type: :runtime
246
246
  prerelease: false
247
247
  version_requirements: !ruby/object:Gem::Requirement
248
248
  requirements:
249
- - - ">="
249
+ - - "~>"
250
250
  - !ruby/object:Gem::Version
251
251
  version: '1.80'
252
- - - "~>"
252
+ - - ">="
253
253
  - !ruby/object:Gem::Version
254
254
  version: '1.80'
255
255
  - !ruby/object:Gem::Dependency
@@ -270,60 +270,40 @@ dependencies:
270
270
  name: colorize
271
271
  requirement: !ruby/object:Gem::Requirement
272
272
  requirements:
273
- - - ">="
273
+ - - "~>"
274
274
  - !ruby/object:Gem::Version
275
275
  version: '0.8'
276
- - - "~>"
276
+ - - ">="
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0.8'
279
279
  type: :runtime
280
280
  prerelease: false
281
281
  version_requirements: !ruby/object:Gem::Requirement
282
282
  requirements:
283
- - - ">="
284
- - !ruby/object:Gem::Version
285
- version: '0.8'
286
283
  - - "~>"
287
284
  - !ruby/object:Gem::Version
288
285
  version: '0.8'
289
- - !ruby/object:Gem::Dependency
290
- name: json
291
- requirement: !ruby/object:Gem::Requirement
292
- requirements:
293
- - - ">="
294
- - !ruby/object:Gem::Version
295
- version: '2.5'
296
- - - "~>"
297
- - !ruby/object:Gem::Version
298
- version: '2.5'
299
- type: :runtime
300
- prerelease: false
301
- version_requirements: !ruby/object:Gem::Requirement
302
- requirements:
303
286
  - - ">="
304
287
  - !ruby/object:Gem::Version
305
- version: '2.5'
306
- - - "~>"
307
- - !ruby/object:Gem::Version
308
- version: '2.5'
288
+ version: '0.8'
309
289
  - !ruby/object:Gem::Dependency
310
290
  name: terrapin
311
291
  requirement: !ruby/object:Gem::Requirement
312
292
  requirements:
313
- - - ">="
293
+ - - "~>"
314
294
  - !ruby/object:Gem::Version
315
295
  version: '0.6'
316
- - - "~>"
296
+ - - ">="
317
297
  - !ruby/object:Gem::Version
318
298
  version: '0.6'
319
299
  type: :runtime
320
300
  prerelease: false
321
301
  version_requirements: !ruby/object:Gem::Requirement
322
302
  requirements:
323
- - - ">="
303
+ - - "~>"
324
304
  - !ruby/object:Gem::Version
325
305
  version: '0.6'
326
- - - "~>"
306
+ - - ">="
327
307
  - !ruby/object:Gem::Version
328
308
  version: '0.6'
329
309
  description: A simple gem which make CI CD process easier for AWS ECS service
@@ -337,6 +317,7 @@ files:
337
317
  - Dockerfile
338
318
  - Gemfile
339
319
  - Gemfile.lock
320
+ - Makefile
340
321
  - Rakefile
341
322
  - bin/console
342
323
  - bin/ecs_helper
@@ -348,15 +329,19 @@ files:
348
329
  - lib/ecs_helper/command.rb
349
330
  - lib/ecs_helper/command/base.rb
350
331
  - lib/ecs_helper/command/build_and_push.rb
332
+ - lib/ecs_helper/command/check_exec.rb
351
333
  - lib/ecs_helper/command/deploy.rb
352
334
  - lib/ecs_helper/command/ecr_login.rb
335
+ - lib/ecs_helper/command/exec.rb
353
336
  - lib/ecs_helper/command/export_env_secrets.rb
354
337
  - lib/ecs_helper/command/export_images.rb
355
338
  - lib/ecs_helper/command/run_command.rb
356
339
  - lib/ecs_helper/common_helper.rb
357
340
  - lib/ecs_helper/error.rb
358
341
  - lib/ecs_helper/error/base.rb
342
+ - lib/ecs_helper/error/bin_not_found.rb
359
343
  - lib/ecs_helper/error/command_not_found.rb
344
+ - lib/ecs_helper/error/command_validation_error.rb
360
345
  - lib/ecs_helper/logging.rb
361
346
  - lib/ecs_helper/service_helper.rb
362
347
  - lib/ecs_helper/task_definition_helper.rb
@@ -365,7 +350,7 @@ homepage: https://github.com/artempartos/ecs_helper
365
350
  licenses:
366
351
  - MIT
367
352
  metadata: {}
368
- post_install_message:
353
+ post_install_message:
369
354
  rdoc_options: []
370
355
  require_paths:
371
356
  - lib
@@ -380,8 +365,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
380
365
  - !ruby/object:Gem::Version
381
366
  version: '0'
382
367
  requirements: []
383
- rubygems_version: 3.0.3
384
- signing_key:
368
+ rubyforge_project:
369
+ rubygems_version: 2.7.6
370
+ signing_key:
385
371
  specification_version: 4
386
372
  summary: ECSHelper
387
373
  test_files: []