ecs-rails 0.0.1 → 0.0.2

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: 6381c88cb4b0507a1f9f667290768c0b0d060b1308108b4699e7b0d6107f048b
4
- data.tar.gz: 1ca8e857d5ea22a9dae7e07388c5124f85f41a81d20b4a5e169852ce942fcba0
3
+ metadata.gz: 35b782be8674d1202475c5feb01d7db1f60cc44c405728e0d209b36ed73dbf36
4
+ data.tar.gz: 12b35c703f133f94e98a958100369fa8a55b2f6c5a00ba05fd15f7f45260606a
5
5
  SHA512:
6
- metadata.gz: ab8bda757afb402c1cdb8096a24ec51a8973fb78e8be9c6f4241e936b68aff153f3d913fa5c15d7336421365972e750130bb36ce91a3da410cf6077cd47321f8
7
- data.tar.gz: 87c30bb9091b7fff68cb535770d22dd4f6d8da21ee9c119eeec06e649f36a8e42f9e9a27d8c2815c67d2894904ff7b38c3c879c79465f3f34e28773c0406f251
6
+ metadata.gz: 14993ab00ee2a4c16050dac6e8697164b8ee107d19b0aa6258b4ae69cdc416f8bf3ebc44183b8d74002e717393ded177756ecc73d482f396a4a1c7a92da0c7b9
7
+ data.tar.gz: 56a7b7c237a810666872fc34b3e376cf7a87bd75b1793602b0fb3d217abc5d0ae786d1515dab745a747af7528b2ad4d03293f178c229143bc3af22365289508c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Franck D'agostini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ If you are hosting your Rails app on ECS Fargate and want to connect to the Rails console or launch a bash session, you need to use AWS cli like so :
2
+
3
+ ```bash
4
+ aws ecs execute-command --region eu-west-3 --cluster CLUSTER_ARN --task TASK_ARN --container CONTAINER_NAME --command 'bundle exec rails console' --interactive
5
+ ```
6
+
7
+ This gem helps to get the correct cluster arn and task id so that you don't have to get them yourself.
8
+
9
+ ```bash
10
+ ecs console
11
+ ecs bash
12
+ ```
13
+
14
+ # Installation
15
+
16
+ Install [AWS cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
17
+
18
+ Install [AWS Session Manager plugin](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html)
19
+
20
+ Install gem
21
+
22
+ ```ruby
23
+ gem install 'ecs-rails'
24
+ ```
25
+
26
+ # Configuration
27
+
28
+ ## Plain Ruby
29
+
30
+ Via environment variables:
31
+
32
+ ```
33
+ export ENV['AWS_REGION'] = 'us-east-1'
34
+ export ENV['AWS_ACCESS_KEY_ID'] = 'your-access-key-id'
35
+ export ENV['AWS_SECRET_ACCESS_KEY'] = 'your-secret-access-key'
36
+ export ENV['CONTAINER_NAME'] = 'your-container-name'
37
+ ```
38
+
39
+ ## Rails
40
+
41
+ ```ruby
42
+ # config/initializers/ecs-rails.rb
43
+ EcsRails.aws_region = 'us-east-1'
44
+ EcsRails.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
45
+ EcsRails.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
46
+ EcsRails.container_name = 'webapp'
47
+ ```
48
+
49
+ # Usage
50
+
51
+ Connect to Rails console on a running Task.
52
+
53
+ ```ruby
54
+ ecs console
55
+
56
+ Select a cluster:
57
+ 1) cluster-prod
58
+ 2) cluster-staging
59
+ Choose 1-2 [1]:
60
+
61
+ Select a service:
62
+ 1) app
63
+ 2) worker
64
+ Choose 1-2 [1]:
65
+
66
+ irb(main)>
67
+ ```
68
+
69
+ You can specify cluster name via -c option by giving a string included in cluster arn.
70
+ You can specify service name via -s option by giving a string included in service arn.
71
+
72
+ ```ruby
73
+ # with cluster name: webapp-cluster-prod-e950a13
74
+ # with service name: webapp-app-prod-7c7cad7
75
+ ecs console -c prod -s app
76
+ irb(main)>
77
+ ```
data/ecs-rails.gemspec CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.files = `git ls-files -z`.split("\x0")
18
18
 
19
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+
19
21
  s.add_development_dependency 'byebug', '~> 11.1'
20
22
  s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
21
23
 
@@ -0,0 +1,22 @@
1
+ module EcsRails
2
+ class Bash < Command
3
+
4
+ def call
5
+ return full_command if test_mode?
6
+
7
+ puts "Executing command: #{full_command}"
8
+ system(full_command)
9
+ end
10
+
11
+ private
12
+
13
+ def full_command
14
+ @full_command ||= "aws ecs execute-command --region #{region} --cluster #{selected_cluster} --task #{task_id} --container #{container_name} --command \'#{command}\' --interactive"
15
+ end
16
+
17
+
18
+ def command
19
+ "bash"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ module EcsRails
2
+ class CommandExecutor
3
+
4
+ def self.call(command_keyword, options = {})
5
+ CommandFactory.new(command_keyword, options).command.call
6
+ end
7
+
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EcsRails
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,5 @@
1
+ require 'ecs-rails'
2
+ require 'byebug'
3
+
4
+ RSpec.configure do |config|
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck D'agostini
@@ -106,18 +106,23 @@ dependencies:
106
106
  version: '0.23'
107
107
  description: Connect to your AWS ECS tasks
108
108
  email: franck.dagostini@gmail.com
109
- executables: []
109
+ executables:
110
+ - ecs
110
111
  extensions: []
111
112
  extra_rdoc_files: []
112
113
  files:
113
114
  - ".gitignore"
114
115
  - Gemfile
116
+ - LICENSE
117
+ - README.md
115
118
  - bin/ecs
116
119
  - ecs-rails.gemspec
117
120
  - lib/ecs-rails.rb
121
+ - lib/ecs-rails/bash.rb
118
122
  - lib/ecs-rails/client.rb
119
123
  - lib/ecs-rails/cluster_selector.rb
120
124
  - lib/ecs-rails/command.rb
125
+ - lib/ecs-rails/command_executor.rb
121
126
  - lib/ecs-rails/command_factory.rb
122
127
  - lib/ecs-rails/console.rb
123
128
  - lib/ecs-rails/ecs_rails_configuration.rb
@@ -125,6 +130,8 @@ files:
125
130
  - lib/ecs-rails/service_selector.rb
126
131
  - lib/ecs-rails/task_selector.rb
127
132
  - lib/ecs-rails/version.rb
133
+ - spec/bin/ecs_spec.rb
134
+ - spec/spec_helper.rb
128
135
  homepage: https://rubygems.org/gems/ecs-rails
129
136
  licenses:
130
137
  - MIT