ecs-rails 0.0.2 → 0.0.4

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: 35b782be8674d1202475c5feb01d7db1f60cc44c405728e0d209b36ed73dbf36
4
- data.tar.gz: 12b35c703f133f94e98a958100369fa8a55b2f6c5a00ba05fd15f7f45260606a
3
+ metadata.gz: c08e4e91434f407ea8df658c3493bffca339b819540d0c20a9cc6a46e62f8c2c
4
+ data.tar.gz: 982257395f3f3f4aff5eef242a1a8d3608ffa59c71bf9d87c4e6238ecd6843e1
5
5
  SHA512:
6
- metadata.gz: 14993ab00ee2a4c16050dac6e8697164b8ee107d19b0aa6258b4ae69cdc416f8bf3ebc44183b8d74002e717393ded177756ecc73d482f396a4a1c7a92da0c7b9
7
- data.tar.gz: 56a7b7c237a810666872fc34b3e376cf7a87bd75b1793602b0fb3d217abc5d0ae786d1515dab745a747af7528b2ad4d03293f178c229143bc3af22365289508c
6
+ metadata.gz: 6fc00dadac2b0d17c2ab0c96312b2157f79b38f6c278e811080636d9d53e90986f8d731eccf2b1b78a994c7e8f5548b9735258aa1949b9352c6e2910d7de34e7
7
+ data.tar.gz: f18f580b67798d22634fd3e89e4d1fcd7cc96aac200653efb704aeb940ab4c4f8b504f221cd9574e4e8d612b05b5d6bf294d3bd713137a00e761e078d410a5bd
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gemspec
6
6
 
7
7
  gem 'byebug'
8
8
  gem 'rspec', '~> 3.0'
9
+ gem 'activesupport', '> 5.2'
data/bin/ecs CHANGED
@@ -1,14 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'byebug'
4
-
5
4
  require 'optparse'
6
- require_relative '../lib/ecs-rails'
7
5
 
8
- EcsRails.aws_region = ENV['AWS_REGION']
9
- EcsRails.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
10
- EcsRails.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
11
- EcsRails.container_name = ENV['CONTAINER_NAME'] || 'webapp'
6
+ require_relative '../lib/ecs-rails'
12
7
 
13
8
  options = {}
14
9
  OptionParser.new do |opts|
@@ -21,13 +16,22 @@ OptionParser.new do |opts|
21
16
  opts.on("-s", "--service SERVICE_STRING", "Give a substring present in your service name. Ex: 'ecs console -c prod -s app' to connect to service webapp-app-prod-7c7cad7") do |c|
22
17
  options[:service] = c
23
18
  end
19
+
20
+ opts.on("-f", "--file-path FILE_PATH", "file path to yaml config file") do |c|
21
+ options[:config_file] = c
22
+ end
23
+
24
24
  end.parse!
25
25
 
26
26
  command_keyword = ARGV[0]
27
27
 
28
- # byebug
29
-
30
- # command = EcsRails::CommandFactory.new(command_keyword, options).command
31
- # command.call
28
+ if !options[:config_file].nil?
29
+ EcsRails.load_settings(options[:config_file])
30
+ else
31
+ EcsRails.aws_region = ENV['AWS_REGION']
32
+ EcsRails.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
33
+ EcsRails.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
34
+ EcsRails.container_name = ENV['CONTAINER_NAME'] || 'webapp'
35
+ end
32
36
 
33
37
  EcsRails::CommandExecutor.call(command_keyword, options)
data/ecs-rails.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency "aws-sdk-ecs", "~> 1.132", "> 1.132"
25
25
  s.add_runtime_dependency "aws-sdk-ec2", "~> 1.425", "> 1.425"
26
26
  s.add_runtime_dependency "tty-prompt", "~> 0.23", "> 0.23"
27
+ s.add_runtime_dependency "activesupport", "> 5.2"
27
28
  end
@@ -38,10 +38,7 @@ module EcsRails
38
38
  attr_reader :client, :filter
39
39
 
40
40
  def connecting_to_cluster(cluster_name)
41
- puts('')
42
41
  puts("Connecting to cluster '#{cluster_name}':")
43
- puts('')
44
- puts('=' * 50)
45
42
  end
46
43
 
47
44
  def ask_for_cluster(clusters)
@@ -31,12 +31,10 @@ module EcsRails
31
31
  end
32
32
 
33
33
  def selected_service
34
- puts("Selected cluster: #{selected_cluster}")
35
34
  @selected_service ||= EcsRails::ServiceSelector.new(client, selected_cluster, service_name).call
36
35
  end
37
36
 
38
37
  def task_id
39
- puts("Selected service: #{selected_service}")
40
38
  @task_id ||= EcsRails::TaskSelector.new(client, selected_cluster, selected_service).call
41
39
  end
42
40
 
@@ -1,21 +1,37 @@
1
+ require 'yaml'
2
+ require 'singleton'
3
+
1
4
  module EcsRails
2
5
  class EcsRailsConfiguration
6
+ include Singleton
7
+
3
8
  attr_accessor :aws_region
4
9
  attr_accessor :aws_access_key_id
5
10
  attr_accessor :aws_secret_access_key
6
11
  attr_accessor :container_name
7
12
 
8
- def self.setup
9
- new.tap do |config|
10
- yield config if block_given?
11
- end
13
+ def self.delegated
14
+ public_instance_methods - Singleton.instance_methods
12
15
  end
13
16
 
14
17
  def initialize
15
18
  @aws_region = 'us-east-1'
16
19
  @aws_access_key_id = nil
17
20
  @aws_secret_access_key = nil
18
- @container_name = nil
21
+ @container_name = 'webapp'
22
+ end
23
+
24
+ def load_settings(file_path=nil)
25
+ file_path ||= default_settings_file_path
26
+ yaml = YAML.load_file(file_path)
27
+ yaml_settings = yaml['settings']
28
+ yaml_settings.each do |key, value|
29
+ send("#{key}=", value)
30
+ end
31
+ end
32
+
33
+ def aws_region
34
+ @aws_region
19
35
  end
20
36
 
21
37
  def aws_region=(region)
@@ -34,5 +50,11 @@ module EcsRails
34
50
  @container_name = container_name
35
51
  end
36
52
 
53
+ private
54
+
55
+ def default_settings_file_path
56
+ File.join(Dir.pwd, 'config', 'ecs-rails.yml')
57
+ end
58
+
37
59
  end
38
60
  end
@@ -43,10 +43,7 @@ module EcsRails
43
43
  attr_reader :client, :cluster, :service_filter
44
44
 
45
45
  def connecting_to_service(service_name)
46
- puts('')
47
46
  puts("Connecting to service '#{service_name}':")
48
- puts('')
49
- puts('=' * 50)
50
47
  end
51
48
 
52
49
  def ask_for_service(services)
@@ -27,20 +27,8 @@ module EcsRails
27
27
  puts(" Task: #{task_arns.first}")
28
28
  return task_arns.first
29
29
  else
30
- tasks_for_deployment.each_with_index do |task, index|
31
- puts("#{index+1}. Task: #{task.task_arn.split('/').last}, Last Status: #{task.last_status}, Desired Status: #{task.desired_status}")
32
- end
30
+ ask_for_task(tasks_for_deployment)
33
31
  end
34
-
35
- selection = $stdin.gets.chomp.to_i
36
- puts("Selected task: #{tasks_for_deployment[selection - 1].task_arn}")
37
-
38
- unless selection.between?(1, task_arns.size)
39
- puts('Invalid selection.')
40
- exit
41
- end
42
-
43
- return task_arns[selection - 1]
44
32
  end
45
33
  end
46
34
  end
@@ -48,5 +36,12 @@ module EcsRails
48
36
  private
49
37
 
50
38
  attr_reader :client, :cluster_name, :service_name
39
+
40
+ def ask_for_task(tasks)
41
+ prompt = TTY::Prompt.new
42
+ choices = tasks.map { |task| task.split('/').last }
43
+ choice = prompt.enum_select("Select a task:", choices)
44
+ tasks.grep(Regexp.new(choice)).first
45
+ end
51
46
  end
52
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EcsRails
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.4'
5
5
  end
data/lib/ecs-rails.rb CHANGED
@@ -24,21 +24,19 @@ require_relative 'ecs-rails/console'
24
24
  require_relative 'ecs-rails/bash'
25
25
  require_relative 'ecs-rails/null_command'
26
26
 
27
+ # delegate
28
+ require 'active_support/core_ext/module/delegation'
27
29
 
28
30
  # prompt
29
31
  require "tty-prompt"
30
32
 
31
33
  module EcsRails
32
34
 
33
- @configuration = EcsRails::EcsRailsConfiguration.setup
34
-
35
35
  class << self
36
- extend Forwardable
37
-
38
- def_delegators :@configuration, :aws_region, :aws_region=
39
- def_delegators :@configuration, :aws_access_key_id, :aws_access_key_id=
40
- def_delegators :@configuration, :aws_secret_access_key, :aws_secret_access_key=
41
- def_delegators :@configuration, :container_name, :container_name=
36
+ def config
37
+ EcsRails::EcsRailsConfiguration.instance
38
+ end
39
+ delegate(*EcsRails::EcsRailsConfiguration.delegated, to: :config)
42
40
  end
43
41
 
44
42
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe EcsRails::EcsRailsConfiguration do
4
+
5
+
6
+ describe '#default' do
7
+
8
+ it 'sets region to us-east-1' do
9
+ expect(EcsRails.aws_region).to eq('us-east-1')
10
+ end
11
+ end
12
+
13
+ describe 'set aws region' do
14
+ describe 'directly' do
15
+ it 'sets region to us-west-2' do
16
+ EcsRails.aws_region = 'us-west-2'
17
+ expect(EcsRails.aws_region).to eq('us-west-2')
18
+ end
19
+ end
20
+ describe 'via configuration file' do
21
+ it 'sets region to us-west-2' do
22
+ EcsRails.load_settings('spec/fixtures/ecs-rails.yml')
23
+ expect(EcsRails.aws_region).to eq('us-west-2')
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ end
@@ -0,0 +1,2 @@
1
+ settings:
2
+ aws_region: 'us-west-2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck D'agostini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-11 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -104,6 +104,20 @@ dependencies:
104
104
  - - ">"
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0.23'
107
+ - !ruby/object:Gem::Dependency
108
+ name: activesupport
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">"
112
+ - !ruby/object:Gem::Version
113
+ version: '5.2'
114
+ type: :runtime
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">"
119
+ - !ruby/object:Gem::Version
120
+ version: '5.2'
107
121
  description: Connect to your AWS ECS tasks
108
122
  email: franck.dagostini@gmail.com
109
123
  executables:
@@ -130,7 +144,8 @@ files:
130
144
  - lib/ecs-rails/service_selector.rb
131
145
  - lib/ecs-rails/task_selector.rb
132
146
  - lib/ecs-rails/version.rb
133
- - spec/bin/ecs_spec.rb
147
+ - spec/ecs-rails/ecs_rails_configuration_spec.rb
148
+ - spec/fixtures/ecs-rails.yml
134
149
  - spec/spec_helper.rb
135
150
  homepage: https://rubygems.org/gems/ecs-rails
136
151
  licenses:
data/spec/bin/ecs_spec.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Ecs binary' do
4
-
5
- context 'without arguments' do
6
- it 'should run ecs help' do
7
- output = EcsRails::CommandExecutor.call('', {})
8
- expect(output).to include('You must specify a command')
9
- end
10
- end
11
-
12
- context 'with console command argument' do
13
- it 'calls the command factory with correct command keyword' do
14
- command_factory_instance = double('command_factory_instance')
15
-
16
- expect(EcsRails::CommandFactory).to receive(:new).with('console', {}).and_return(command_factory_instance)
17
-
18
- command_instance = double('command_instance')
19
-
20
- expect(command_factory_instance).to receive(:command).and_return(command_instance)
21
- expect(command_instance).to receive(:call)
22
-
23
- EcsRails::CommandExecutor.call('bash', {})
24
- end
25
- end
26
- end