contexto 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 54035544f0eb7fa0de0c9dad30c43354f408983e
4
- data.tar.gz: 877daecadcdd6eee388e035574aa28fbe709d846
3
+ metadata.gz: 195f6f1cf5e2290f2e30504fc730ceba7dcec5db
4
+ data.tar.gz: 8bc00df2ae7f8bc35b8a8a0e55d99bd7e1fc1ba1
5
5
  SHA512:
6
- metadata.gz: 8c75520a641dba12b5f3bcf7060cd93840eb8f6ccec8e8edca845fa59641478326e73535a14616bad5134b6a11a51e484194863d448514f528d37f303add9193
7
- data.tar.gz: c2d00df3d0e5f80c4be26b468f7ef1f88ba26b8efc74f7369e475c50ea8a31b9d12aa9d1610ecdcd53cd69622ab94e72396db966d0fc63ae7adcf891e362292b
6
+ metadata.gz: 12dfdc35a021d798a55ae622d9c86e863e14e45724508ee4add2904f899dea55ce0015b5ea1d3acec4a4443e43ae2cb838382da3ea2ae9adfb5abe0ba5e64a7c
7
+ data.tar.gz: 508654ea0e00261c36fc85bb5619ac450dd1c1784f95fbcd7577f6a6bf35af17c1c3e4ebfd1d51dc42e0565d21803b7a71c74ee037c4299758753d24ca3822b2
data/README.md CHANGED
@@ -66,6 +66,28 @@ Containers
66
66
  ┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
67
67
  ```
68
68
 
69
+ ### SSH
70
+
71
+ You can also get Contexto to spit out an SSH command you can use to connect to
72
+ a specific container.
73
+
74
+ To do so specify the cluster, servicec and container and the `--ssh`
75
+ flag.
76
+
77
+ ```shell
78
+ $ contexto -c sandbox -s backend-app -t app --ssh
79
+
80
+ ** Contexto Contextualizes **
81
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
82
+
83
+ ssh -t -A bastion.empatico.xyz "ssh -t ec2-user@10.2.1.218 'docker exec -it \$(docker ps | grep ecs-sandbox-backend-app-.*-app | cut -d\ -f1) bin/rails c'"
84
+ ```
85
+
86
+ ## TODO
87
+
88
+ 1. Automate the SSH login process.
89
+ 2. ???
90
+
69
91
  ## Development
70
92
 
71
93
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/bin/contexto CHANGED
@@ -8,14 +8,18 @@ require 'contexto'
8
8
  require 'optparse'
9
9
  require 'English'
10
10
 
11
+ $stderr.sync = true
12
+
11
13
  options = {}
12
14
  options[:cluster] = 'sandbox'
15
+ options[:ssh] = false
13
16
 
14
17
  optparse = OptionParser.new do |opts|
15
18
  opts.banner = 'Usage: contexto [options]'
16
19
  opts.on('-c', '--cluster CLUSTER', 'Cluster') { |v| options[:cluster] = v }
17
20
  opts.on('-s', '--service SERVICE', 'Service') { |v| options[:service] = v }
18
21
  opts.on('-t', '--container CONTAINER', 'Container') { |v| options[:container] = v }
22
+ opts.on('-b', '--ssh') { options[:ssh] = true }
19
23
  end
20
24
 
21
25
  begin
@@ -32,4 +36,4 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
32
36
  end
33
37
 
34
38
  c = Contexto::Contextualize.new(options)
35
- c.show
39
+ c.run
data/contexto.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency 'aws-sdk', '~> 2'
23
23
  spec.add_dependency 'command_line_reporter'
24
- spec.add_dependency 'slack-ruby-client', '~> 0.8.0'
24
+ spec.add_dependency 'net-ssh-gateway'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.14'
27
27
  spec.add_development_dependency 'pry', '~> 0.10.4'
@@ -10,10 +10,17 @@ module Contexto
10
10
  @cluster = params.fetch(:cluster)
11
11
  @service = params.fetch(:service) if params[:service]
12
12
  @container = params.fetch(:container) if params[:container]
13
+ @ssh = params.fetch(:ssh)
13
14
  @display = Contexto::Display.new
14
15
  end
15
16
 
16
- def show
17
+ def run
18
+ if @ssh
19
+ task = describe_tasks
20
+ ec2_instance_id = describe_container_instance(task[:container_instance_arn])
21
+ @connect = Contexto::SSH.new(describe_instances(ec2_instance_id), @cluster, @service, @container)
22
+ return
23
+ end
17
24
  cluster
18
25
  puts "\n"
19
26
  return unless @service
@@ -56,11 +63,7 @@ module Contexto
56
63
  end
57
64
 
58
65
  def tasks
59
- resp = ecs_client.describe_tasks(
60
- cluster: @cluster,
61
- tasks: [task_arn]
62
- )
63
- task = resp.tasks[0].to_h
66
+ task = describe_tasks
64
67
  containers = task[:containers]
65
68
  ec2_instance_id = describe_container_instance(task[:container_instance_arn])
66
69
  title = 'Containers'
@@ -72,6 +75,14 @@ module Contexto
72
75
  @display.create_display(title, headings, rows)
73
76
  end
74
77
 
78
+ def describe_tasks
79
+ resp = ecs_client.describe_tasks(
80
+ cluster: @cluster,
81
+ tasks: [task_arn]
82
+ )
83
+ resp.tasks[0].to_h
84
+ end
85
+
75
86
  def task_arn
76
87
  resp = ecs_client.list_tasks(
77
88
  cluster: @cluster,
@@ -0,0 +1,22 @@
1
+ # Context
2
+ module Contexto
3
+ # SSH class
4
+ class SSH
5
+ def initialize(ipaddress, cluster, service, container)
6
+ @ipaddress = ipaddress
7
+ @cluster = cluster
8
+ @service = service
9
+ @container = container
10
+ @bastion_host = 'bastion.empatico.xyz'
11
+ @bastion_user = ''
12
+ @user_name = 'ec2-user'
13
+ @options = {}
14
+ connect
15
+ end
16
+
17
+ def connect
18
+ cmd = "ssh -t -A #{@bastion_host} \"ssh -t ec2-user@#{@ipaddress} 'docker exec -it \\$(docker ps | grep ecs-#{@cluster}-#{@service}-.*-#{@container} | cut -d\\ -f1) bin/rails c'\""
19
+ puts cmd
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,4 @@
1
1
  # Contexto version
2
2
  module Contexto
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.1'.freeze
4
4
  end
data/lib/contexto.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'contexto/version'
2
2
  require 'contexto/contextualize'
3
3
  require 'contexto/display'
4
+ require 'contexto/ssh'
4
5
 
5
6
  # Base module
6
7
  module Contexto
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contexto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Turnbull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: slack-ruby-client
42
+ name: net-ssh-gateway
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.8.0
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.8.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +131,7 @@ files:
131
131
  - lib/contexto.rb
132
132
  - lib/contexto/contextualize.rb
133
133
  - lib/contexto/display.rb
134
+ - lib/contexto/ssh.rb
134
135
  - lib/contexto/version.rb
135
136
  homepage: https://github.com/EmpaticoOrg/contexto
136
137
  licenses: