ecs_helper 0.0.28 → 0.0.29
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.lock +1 -1
- data/Makefile +30 -0
- data/lib/ecs_helper/client.rb +8 -0
- data/lib/ecs_helper/command/base.rb +15 -4
- data/lib/ecs_helper/command/exec.rb +99 -0
- data/lib/ecs_helper/command.rb +2 -0
- data/lib/ecs_helper/error/bin_not_found.rb +2 -0
- data/lib/ecs_helper/error/command_validation_error.rb +2 -0
- data/lib/ecs_helper/error.rb +2 -0
- data/lib/ecs_helper/logging.rb +1 -1
- data/lib/ecs_helper/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d9360d89edeb8333e9caf152cb45a4a1d6042c3f614ab0d6d5d45e8d6bcd6e61
|
|
4
|
+
data.tar.gz: b3d2c66d829a1cf4b35e0d9dd476427287770fd14beb4e28729cc263d58ec878
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20bc088dc9e4f3cbd8d04d83354faa39e3e319abcfe10335e0444fda5d755c32e883854f32a072c93f96129e98ba13b7d5dd53187a0b81dfc2cdcd3bc5bb8075
|
|
7
|
+
data.tar.gz: b588b0c7003c7e08afd46ce196b04cae8756c0c7b2ba3aafabbbc20c9a9e99ef319fc952d14f23a4bd9b19291714d20843149d86bb50371f689218868d5de4f3
|
data/Gemfile.lock
CHANGED
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/lib/ecs_helper/client.rb
CHANGED
|
@@ -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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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,99 @@
|
|
|
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: 'bash -c' }
|
|
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] = c }
|
|
19
|
+
opts.on('--command VALUE', 'Command to execute') { |c| options[:command] = 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
|
+
# --region us-east-1
|
|
79
|
+
exec_cmd.run
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def parse_version(string)
|
|
85
|
+
string.split('/')[1][0]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def cluster_arn
|
|
89
|
+
helper.current_cluster
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def service_arn
|
|
93
|
+
helper.current_service
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def task_arn
|
|
97
|
+
@task_arn ||= helper.client.list_tasks({cluster: cluster_arn, service_name: service_arn, desired_status: "RUNNING"})[0]
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/ecs_helper/command.rb
CHANGED
|
@@ -5,6 +5,7 @@ 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'
|
|
8
9
|
autoload :RunCommand, 'ecs_helper/command/run_command'
|
|
9
10
|
autoload :ExportEnvSecrets, 'ecs_helper/command/export_env_secrets'
|
|
10
11
|
|
|
@@ -15,6 +16,7 @@ class ECSHelper::Command
|
|
|
15
16
|
"ecr_login" => ECRLogin,
|
|
16
17
|
"run_command" => RunCommand,
|
|
17
18
|
"export_env_secrets" => ExportEnvSecrets,
|
|
19
|
+
"exec" => Exec,
|
|
18
20
|
}
|
|
19
21
|
AVAILABLE_COMMANDS = CMD_MAPPING.keys
|
|
20
22
|
|
data/lib/ecs_helper/error.rb
CHANGED
|
@@ -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
|
data/lib/ecs_helper/logging.rb
CHANGED
data/lib/ecs_helper/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.0.29
|
|
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-
|
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: awesome_print
|
|
@@ -337,6 +337,7 @@ files:
|
|
|
337
337
|
- Dockerfile
|
|
338
338
|
- Gemfile
|
|
339
339
|
- Gemfile.lock
|
|
340
|
+
- Makefile
|
|
340
341
|
- Rakefile
|
|
341
342
|
- bin/console
|
|
342
343
|
- bin/ecs_helper
|
|
@@ -350,13 +351,16 @@ files:
|
|
|
350
351
|
- lib/ecs_helper/command/build_and_push.rb
|
|
351
352
|
- lib/ecs_helper/command/deploy.rb
|
|
352
353
|
- lib/ecs_helper/command/ecr_login.rb
|
|
354
|
+
- lib/ecs_helper/command/exec.rb
|
|
353
355
|
- lib/ecs_helper/command/export_env_secrets.rb
|
|
354
356
|
- lib/ecs_helper/command/export_images.rb
|
|
355
357
|
- lib/ecs_helper/command/run_command.rb
|
|
356
358
|
- lib/ecs_helper/common_helper.rb
|
|
357
359
|
- lib/ecs_helper/error.rb
|
|
358
360
|
- lib/ecs_helper/error/base.rb
|
|
361
|
+
- lib/ecs_helper/error/bin_not_found.rb
|
|
359
362
|
- lib/ecs_helper/error/command_not_found.rb
|
|
363
|
+
- lib/ecs_helper/error/command_validation_error.rb
|
|
360
364
|
- lib/ecs_helper/logging.rb
|
|
361
365
|
- lib/ecs_helper/service_helper.rb
|
|
362
366
|
- lib/ecs_helper/task_definition_helper.rb
|