ecs_helper 0.0.4 → 0.0.9

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: b3a8956a9f6eda0de978eae11de21c36ff09fd45c6c0a9c1df13ccd6b2bdba95
4
- data.tar.gz: 40391c6c317e96687b9ad72ebcf03df0cdb0bb1b1a1fd381db720df7720d2801
3
+ metadata.gz: abb3dcfdd4e42b2bf86e57422c59ceda2458f359e557cd0f782385c3e673ecf1
4
+ data.tar.gz: d036e9dbfac6b04133e2667f13e897b1e43cbad438d586904e53bb26b9536eee
5
5
  SHA512:
6
- metadata.gz: 497a68f0ae2b2e8cce1701b821195dc1f07f5a7a7a6f67b442abc59a4e69005ff5de067943037b63e5e4ec1f09e318b4ec3136a6b92f5b2ec92d3911be58199c
7
- data.tar.gz: 1a01a3f9ca2b5c94fdd5a146b6cc3f41c6fa6b35620748068f9cbee3f10afc102f2dee0a32e5884007bb7f6cb7c6d02a9e72dfddcf1df1c0ddfd94fb2d831a5f
6
+ metadata.gz: 8d4df5b95e14fce83d28822904a4822bc6f8074cd7895b950a18ac68675790e8d998b0c9fa22b985430b1a5684b026b63c1caa771263025517d5272d7e54837c
7
+ data.tar.gz: 26dd182dcb2b0bc3d437acb41d3c89f2513b6ec4944c28a971244fcce3bece4efb63261591aadd31a5c4088557cc440e5ccc699cc1e014598e3424db427fa7ef
@@ -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 repositories(params = {})
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
@@ -22,13 +22,19 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
22
22
  log("Command", type)
23
23
  log("Options", options)
24
24
  log("Repository", repository)
25
- log("Auth", auth)
25
+ log("Auth Private", auth_private)
26
+ log("Auth Public", auth_public)
26
27
  log("Pull", pull)
27
28
  log("Build", build)
28
29
  log("Push", push)
29
30
  end
30
31
 
31
- def auth
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
32
38
  auth_cmd = Terrapin::CommandLine.new("aws ecr get-login --no-include-email | sh")
33
39
  auth_cmd.run
34
40
  end
@@ -72,7 +78,9 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
72
78
 
73
79
  def repository
74
80
  @repository ||= begin
75
- all = client.repositories
81
+ private_repos = client.private_repositories
82
+ public_repos = client.public_repositories
83
+ all = private_repos + public_repos
76
84
  with_name = all.select { |r| r.repository_arn.include?(image_name) }
77
85
  return with_name[0].repository_uri if with_name.length === 1
78
86
 
@@ -2,7 +2,7 @@ require 'terrapin'
2
2
 
3
3
  class ECSHelper::Command::Deploy < ECSHelper::Command::Base
4
4
  attr_accessor :repositories, :task_definition, :new_task_definition, :service
5
- TIMEOUT = 300
5
+ DEFAULT_TIMEOUT = 300
6
6
  STEP = 5
7
7
 
8
8
  def cmd_option_parser
@@ -12,20 +12,23 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
12
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) }
13
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) }
14
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) }
15
- opts.on("-t VALUE", "--tag VALUE", "Set tag which will be applied to all containers in the task if tag is present in the repo") { |t| options[:tag] = processEqual(t) }
15
+ opts.on("-v VALUE", "--version VALUE", "Set version which will be applied to all containers in the task if tag is present in the repo") { |t| options[:version] = processEqual(t) }
16
16
  opts.on("-c VALUE", "--cluster VALUE", "Set cluster name, could be autodetected if project and environment are specified") { |c| options[:cluster] = processEqual(c) }
17
17
  opts.on("-s VALUE", "--service VALUE", "Set service, could be autodetected if application and environment are specified") { |s| options[:service] = processEqual(s) }
18
+ opts.on("-t VALUE", "--timeout VALUE", "Set timeout how long to wait until deployment finished") { |t| options[:timeout] = processEqual(t) }
18
19
  end
19
20
  [parser, options]
20
21
  end
21
22
 
23
+ def timeout
24
+
22
25
  def run
23
26
  log("Command", type)
24
27
  log("Options", options)
25
28
  log("Environment", environment)
26
29
  log("Cluster", cluster_arn)
27
30
  log("Service", service_arn)
28
- log("Tag", tag)
31
+ log("Version", version)
29
32
  log("Service task definition", task_definition_arn)
30
33
  log("Containers", pretty_container_definitions)
31
34
  log("New task definition", new_task_definition.task_definition_arn)
@@ -37,7 +40,7 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
37
40
  def wait_for_deployment(time = 0)
38
41
  service = helper.client.describe_service(cluster_arn, service_arn)
39
42
  return true if service.deployments.count == 1
40
- error("Deployment timeout (#{TIMEOUT})") if time > TIMEOUT
43
+ error("Deployment timeout (#{timeout})") if time > timeout
41
44
  sleep STEP
42
45
  wait_for_deployment(time + STEP)
43
46
  end
@@ -56,8 +59,12 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
56
59
  helper.current_service
57
60
  end
58
61
 
59
- def tag
60
- options[:tag] || helper.version
62
+ def version
63
+ options[:version] || helper.version
64
+ end
65
+
66
+ def timeout
67
+ options[:timeout] || DEFAULT_TIMEOUT
61
68
  end
62
69
 
63
70
  def service
@@ -77,11 +84,11 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
77
84
  end
78
85
 
79
86
  def repositories
80
- @repositories ||= client.repositories
87
+ @repositories ||= client.private_repositories
81
88
  end
82
89
 
83
- def tag_image(repo)
84
- client.describe_images({repository_name: repo.repository_name, image_ids: [image_tag: tag]})
90
+ def version_image(repo)
91
+ client.describe_images({repository_name: repo.repository_name, image_ids: [image_tag: version]})
85
92
  rescue
86
93
  nil
87
94
  end
@@ -99,7 +106,7 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
99
106
  def container_definition_to_ecr(cd)
100
107
  repo = repo_for(cd.name)
101
108
  is_ecr = cd.image.include?(ecr_base)
102
- image = repo && tag_image(repo)
109
+ image = repo && version_image(repo)
103
110
  should_update = is_ecr && repo && image
104
111
  [repo, is_ecr, image, should_update]
105
112
  end
@@ -107,7 +114,7 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
107
114
  def new_container_definitions
108
115
  container_definitions.map do |cd|
109
116
  repo, is_ecr, image, should_be_updated = container_definition_to_ecr(cd)
110
- cd.image = "#{repo.repository_uri}:#{tag}" if should_be_updated
117
+ cd.image = "#{repo.repository_uri}:#{version}" if should_be_updated
111
118
  cd.to_hash
112
119
  end
113
120
  end
@@ -120,7 +127,7 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
120
127
  cd.image,
121
128
  is_ecr ? "ECR image" : "Not a ECR image",
122
129
  repo ? "Repo #{repo.repository_name}" : "Repo not found",
123
- image ? "Image tag #{tag}" : "Image tag #{tag} not found",
130
+ image ? "Image version #{version}" : "Image version #{version} not found",
124
131
  should_be_updated ? "Will be updated" : "Not applicable"
125
132
  ].join(' | ')
126
133
  end.join("\n")
@@ -16,10 +16,16 @@ class ECSHelper::Command::ECRLogin < ECSHelper::Command::Base
16
16
 
17
17
  def run
18
18
  log("Command", type)
19
- log("Auth", auth)
19
+ log("Auth Private", auth_private)
20
+ log("Auth Public", auth_public)
20
21
  end
21
22
 
22
- def auth
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
23
29
  auth_cmd = Terrapin::CommandLine.new("aws ecr get-login --no-include-email | sh")
24
30
  auth_cmd.run
25
31
  end
@@ -18,12 +18,6 @@ class ECSHelper::Command::ExportImages < ECSHelper::Command::Base
18
18
  puts export_images
19
19
  end
20
20
 
21
- def auth
22
- auth_cmd = Terrapin::CommandLine.new("aws ecr get-login --no-include-email | sh")
23
- auth_cmd.run
24
- end
25
-
26
-
27
21
  private
28
22
 
29
23
  def project
@@ -35,7 +29,7 @@ class ECSHelper::Command::ExportImages < ECSHelper::Command::Base
35
29
  end
36
30
 
37
31
  def export_images
38
- variables = (['export'] + client.repositories.map do |repo|
32
+ variables = (['export'] + client.private_repositories.map do |repo|
39
33
  container_name = repo.repository_name.scan(/#{project}-#{application}-(.*)/).flatten.first
40
34
  key = container_name.upcase.gsub("-", "_") + "_IMAGE"
41
35
  value = "#{repo.repository_uri}:#{helper.version}"
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
4
+ version: 0.0.9
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-14 00:00:00.000000000 Z
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
@@ -50,6 +50,26 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '1.42'
53
+ - !ruby/object:Gem::Dependency
54
+ name: aws-sdk-ecrpublic
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.3'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '1.3'
53
73
  - !ruby/object:Gem::Dependency
54
74
  name: json
55
75
  requirement: !ruby/object:Gem::Requirement