ecs_helper 0.0.3 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ecs_helper/client.rb +8 -2
- data/lib/ecs_helper/command.rb +5 -1
- data/lib/ecs_helper/command/build_and_push.rb +12 -6
- data/lib/ecs_helper/command/deploy.rb +2 -3
- data/lib/ecs_helper/command/ecr_login.rb +32 -0
- data/lib/ecs_helper/command/export_images.rb +40 -0
- metadata +14 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69c2a9f0e010f46fd746986748e14f9a08ee5a0255a2779b7ea453d8dc47c685
|
4
|
+
data.tar.gz: b59a0b7bd4a045834a741dd34586dd87a8eec88c84fb11d63daeba3cfc5bbe8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65f11ad6c8120a872900dbc61b91d08ad66e9b999931f298760de9baf0639d0a691bcd5bc7c37be095d94d7ed18a5fb5c34a205b8e22dd117f43f12b6239ced3
|
7
|
+
data.tar.gz: 20126689d683994f8ade23d02de2f81a25406b86ace18890be6f013c8bc64a467de567e9ccb23f3cf1fbf31ac3bec754400913ca23faad623fe1559495f7aecf
|
data/lib/ecs_helper/client.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'aws-sdk-ecs'
|
2
2
|
require 'aws-sdk-ecr'
|
3
|
+
require 'aws-sdk-ecrpublic'
|
3
4
|
|
4
5
|
class ECSHelper::Client
|
5
|
-
attr_accessor :ecs, :ecr
|
6
|
+
attr_accessor :ecs, :ecr, :ecr_public
|
6
7
|
def initialize
|
7
8
|
@ecs = Aws::ECS::Client.new
|
8
9
|
@ecr = Aws::ECR::Client.new
|
10
|
+
@ecr_public = Aws::ECRPublic::Client.new
|
9
11
|
end
|
10
12
|
|
11
13
|
# ECS
|
@@ -47,10 +49,14 @@ class ECSHelper::Client
|
|
47
49
|
end
|
48
50
|
|
49
51
|
# ECR
|
50
|
-
def
|
52
|
+
def private_repositories(params = {})
|
51
53
|
ecr.describe_repositories(params).repositories
|
52
54
|
end
|
53
55
|
|
56
|
+
def public_repositories(params = {})
|
57
|
+
ecr_public.describe_repositories(params).repositories
|
58
|
+
end
|
59
|
+
|
54
60
|
def describe_images(params = {})
|
55
61
|
ecr.describe_images(params).image_details[0]
|
56
62
|
end
|
data/lib/ecs_helper/command.rb
CHANGED
@@ -3,10 +3,14 @@ class ECSHelper::Command
|
|
3
3
|
autoload :Base, 'ecs_helper/command/base'
|
4
4
|
autoload :BuildAndPush, 'ecs_helper/command/build_and_push'
|
5
5
|
autoload :Deploy, 'ecs_helper/command/deploy'
|
6
|
+
autoload :ExportImages, 'ecs_helper/command/export_images'
|
7
|
+
autoload :ECRLogin, 'ecs_helper/command/ecr_login'
|
6
8
|
|
7
9
|
CMD_MAPPING = {
|
8
10
|
"build_and_push" => BuildAndPush,
|
9
|
-
"deploy" => Deploy
|
11
|
+
"deploy" => Deploy,
|
12
|
+
"export_images" => ExportImages,
|
13
|
+
"ecr_login" => ECRLogin,
|
10
14
|
}
|
11
15
|
AVAILABLE_COMMANDS = CMD_MAPPING.keys
|
12
16
|
|
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'terrapin'
|
2
2
|
|
3
3
|
class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
|
4
|
-
# attr_accessor :type, :client, :project, :application, :version
|
5
4
|
|
6
5
|
def cmd_option_parser
|
7
6
|
options = {}
|
8
7
|
parser = ::OptionParser.new do |opts|
|
9
|
-
opts.banner = "Usage: ecs_helper build_and_push [options]
|
10
|
-
opts.on("-v", "--verbose", "Show debug information") { o[:verbose] = true }
|
8
|
+
opts.banner = "Usage: ecs_helper build_and_push [options]"
|
11
9
|
opts.on("-i VALUE", "--image VALUE", "Set image name, will be used to detect ecr repo where to push image, for example web/nginx/toolbox (required)") { |c| options[:image] = processEqual(c) }
|
12
10
|
opts.on("-d VALUE", "--directory VALUE", "Set directory for dockerfile and context, default = './'") { |c| options[:directory] = processEqual(c) }
|
13
11
|
opts.on("-p VALUE", "--project VALUE", "Set project name, if not specified will look at ENV['PROJECT'], will be used to detect cluster") { |p| options[:project] = processEqual(p) }
|
@@ -24,13 +22,19 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
|
|
24
22
|
log("Command", type)
|
25
23
|
log("Options", options)
|
26
24
|
log("Repository", repository)
|
27
|
-
log("Auth",
|
25
|
+
log("Auth Private", auth_private)
|
26
|
+
log("Auth Public", auth_public)
|
28
27
|
log("Pull", pull)
|
29
28
|
log("Build", build)
|
30
29
|
log("Push", push)
|
31
30
|
end
|
32
31
|
|
33
|
-
def
|
32
|
+
def auth_public
|
33
|
+
auth_cmd = Terrapin::CommandLine.new("aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws")
|
34
|
+
auth_cmd.run
|
35
|
+
end
|
36
|
+
|
37
|
+
def auth_private
|
34
38
|
auth_cmd = Terrapin::CommandLine.new("aws ecr get-login --no-include-email | sh")
|
35
39
|
auth_cmd.run
|
36
40
|
end
|
@@ -74,7 +78,9 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
|
|
74
78
|
|
75
79
|
def repository
|
76
80
|
@repository ||= begin
|
77
|
-
|
81
|
+
private_repos = client.private_repositories
|
82
|
+
public_repos = client.public_repositories
|
83
|
+
all = private_repos + public_repos
|
78
84
|
with_name = all.select { |r| r.repository_arn.include?(image_name) }
|
79
85
|
return with_name[0].repository_uri if with_name.length === 1
|
80
86
|
|
@@ -8,8 +8,7 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
|
|
8
8
|
def cmd_option_parser
|
9
9
|
options = {}
|
10
10
|
parser = ::OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage: ecs_helper deploy [options]
|
12
|
-
opts.on("-v", "--verbose", "Show debug information") { o[:verbose] = true }
|
11
|
+
opts.banner = "Usage: ecs_helper deploy [options]"
|
13
12
|
opts.on("-p VALUE", "--project VALUE", "Set project name, if not specified will look at ENV['PROJECT'], will be used to detect cluster") { |p| options[:project] = processEqual(p) }
|
14
13
|
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") { |a| options[:application] = processEqual(a) }
|
15
14
|
opts.on("-e VALUE", "--environment VALUE", "Set environment, if not specified will look at ENV['ENVIRONMENT'], it there is empty will try to detect based on the branch") { |e| options[:environment] = processEqual(e) }
|
@@ -78,7 +77,7 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
|
|
78
77
|
end
|
79
78
|
|
80
79
|
def repositories
|
81
|
-
@repositories ||= client.
|
80
|
+
@repositories ||= client.private_repositories
|
82
81
|
end
|
83
82
|
|
84
83
|
def tag_image(repo)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'terrapin'
|
2
|
+
|
3
|
+
class ECSHelper::Command::ECRLogin < ECSHelper::Command::Base
|
4
|
+
|
5
|
+
def cmd_option_parser
|
6
|
+
options = {}
|
7
|
+
parser = ::OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: ecs_helper ecr_login"
|
9
|
+
end
|
10
|
+
[parser, options]
|
11
|
+
end
|
12
|
+
|
13
|
+
def required
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
log("Command", type)
|
19
|
+
log("Auth Private", auth_private)
|
20
|
+
log("Auth Public", auth_public)
|
21
|
+
end
|
22
|
+
|
23
|
+
def auth_public
|
24
|
+
auth_cmd = Terrapin::CommandLine.new("aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws")
|
25
|
+
auth_cmd.run
|
26
|
+
end
|
27
|
+
|
28
|
+
def auth_private
|
29
|
+
auth_cmd = Terrapin::CommandLine.new("aws ecr get-login --no-include-email | sh")
|
30
|
+
auth_cmd.run
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'terrapin'
|
2
|
+
|
3
|
+
class ECSHelper::Command::ExportImages < ECSHelper::Command::Base
|
4
|
+
|
5
|
+
def cmd_option_parser
|
6
|
+
options = {}
|
7
|
+
parser = ::OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: ecs_helper export_images"
|
9
|
+
end
|
10
|
+
[parser, options]
|
11
|
+
end
|
12
|
+
|
13
|
+
def required
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
puts export_images
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def project
|
24
|
+
helper.project
|
25
|
+
end
|
26
|
+
|
27
|
+
def application
|
28
|
+
helper.application
|
29
|
+
end
|
30
|
+
|
31
|
+
def export_images
|
32
|
+
variables = (['export'] + client.private_repositories.map do |repo|
|
33
|
+
container_name = repo.repository_name.scan(/#{project}-#{application}-(.*)/).flatten.first
|
34
|
+
key = container_name.upcase.gsub("-", "_") + "_IMAGE"
|
35
|
+
value = "#{repo.repository_uri}:#{helper.version}"
|
36
|
+
"#{key}=#{value}"
|
37
|
+
end).join(' ')
|
38
|
+
variables
|
39
|
+
end
|
40
|
+
end
|
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.8
|
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-06-
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-ecs
|
@@ -51,45 +51,45 @@ dependencies:
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '1.42'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: aws-sdk-ecrpublic
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
59
|
+
version: '1.3'
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '1.3'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '1.3'
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
72
|
+
version: '1.3'
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
74
|
+
name: json
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
79
|
+
version: '2.5'
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '2.5'
|
83
83
|
type: :runtime
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2.5'
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version: '
|
92
|
+
version: '2.5'
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: colorize
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,26 +110,6 @@ dependencies:
|
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0.8'
|
113
|
-
- !ruby/object:Gem::Dependency
|
114
|
-
name: docker-api
|
115
|
-
requirement: !ruby/object:Gem::Requirement
|
116
|
-
requirements:
|
117
|
-
- - "~>"
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
version: '2.1'
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: '2.1'
|
123
|
-
type: :runtime
|
124
|
-
prerelease: false
|
125
|
-
version_requirements: !ruby/object:Gem::Requirement
|
126
|
-
requirements:
|
127
|
-
- - "~>"
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: '2.1'
|
130
|
-
- - ">="
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version: '2.1'
|
133
113
|
- !ruby/object:Gem::Dependency
|
134
114
|
name: terrapin
|
135
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,6 +145,8 @@ files:
|
|
165
145
|
- lib/ecs_helper/command/base.rb
|
166
146
|
- lib/ecs_helper/command/build_and_push.rb
|
167
147
|
- lib/ecs_helper/command/deploy.rb
|
148
|
+
- lib/ecs_helper/command/ecr_login.rb
|
149
|
+
- lib/ecs_helper/command/export_images.rb
|
168
150
|
- lib/ecs_helper/common_helper.rb
|
169
151
|
- lib/ecs_helper/logging.rb
|
170
152
|
- lib/ecs_helper/service_helper.rb
|