contexto 0.1.1 → 0.2.0

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: 195f6f1cf5e2290f2e30504fc730ceba7dcec5db
4
- data.tar.gz: 8bc00df2ae7f8bc35b8a8a0e55d99bd7e1fc1ba1
3
+ metadata.gz: 70a1d561afdac4ad1e724a0f4e5174b2e302b5c6
4
+ data.tar.gz: 899491e29583693bcde3f42d5f02b17dfb943765
5
5
  SHA512:
6
- metadata.gz: 12dfdc35a021d798a55ae622d9c86e863e14e45724508ee4add2904f899dea55ce0015b5ea1d3acec4a4443e43ae2cb838382da3ea2ae9adfb5abe0ba5e64a7c
7
- data.tar.gz: 508654ea0e00261c36fc85bb5619ac450dd1c1784f95fbcd7577f6a6bf35af17c1c3e4ebfd1d51dc42e0565d21803b7a71c74ee037c4299758753d24ca3822b2
6
+ metadata.gz: ed11c289dd07940251a6a75eb67f6d8d1f158a0b36b98380871103f503203ae84a728cebd400c117eb6c2819de7259eea377c3055211caa0cf5a1b3f074e7b79
7
+ data.tar.gz: e0c9492d095b2af5b3284295c9a47e1e4839a84579d49b0006053e00e0532439c289f71eb7091e39fe5f57b2b0366bd071cc6ebb2710823f2ec5cc945cf1a8fa
data/README.md CHANGED
@@ -68,25 +68,40 @@ Containers
68
68
 
69
69
  ### SSH
70
70
 
71
- You can also get Contexto to spit out an SSH command you can use to connect to
72
- a specific container.
71
+ You can also get Contexto to connect via SSH to a Rails console or run a `rake` task.
73
72
 
74
- To do so specify the cluster, servicec and container and the `--ssh`
75
- flag.
73
+ #### Rails console
74
+
75
+ To connect to a Rails console, specify the cluster, service and container and the `--console` flag.
76
76
 
77
77
  ```shell
78
- $ contexto -c sandbox -s backend-app -t app --ssh
78
+ $ contexto -c sandbox -s backend-app -t app --console
79
79
 
80
80
  ** Contexto Contextualizes **
81
81
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
82
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'"
83
+ I, [2017-03-28T22:36:35.555604 #181] INFO -- sentry: ** [Raven] Raven 2.4.0 ready to catch errors
84
+ Loading sandbox environment (Rails 5.0.1)
85
+ irb(main):001:0>
84
86
  ```
85
87
 
86
- ## TODO
88
+ #### Rake tasks
89
+
90
+ You can run `rake` tasks. To run the `test` task you would do:
91
+
92
+ ```shell
93
+ $ contexto -c sandbox -s backend-app -t sidekiq --rake test
94
+
87
95
 
88
- 1. Automate the SSH login process.
89
- 2. ???
96
+ ** Contexto Contextualizes **
97
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
98
+
99
+ Run options: --seed 52808
100
+
101
+ # Running:
102
+
103
+ ................................................E
104
+ ```
90
105
 
91
106
  ## Development
92
107
 
data/bin/contexto CHANGED
@@ -11,20 +11,20 @@ require 'English'
11
11
  $stderr.sync = true
12
12
 
13
13
  options = {}
14
- options[:cluster] = 'sandbox'
15
- options[:ssh] = false
14
+ options[:console] = false
16
15
 
17
16
  optparse = OptionParser.new do |opts|
18
17
  opts.banner = 'Usage: contexto [options]'
19
18
  opts.on('-c', '--cluster CLUSTER', 'Cluster') { |v| options[:cluster] = v }
20
19
  opts.on('-s', '--service SERVICE', 'Service') { |v| options[:service] = v }
21
20
  opts.on('-t', '--container CONTAINER', 'Container') { |v| options[:container] = v }
22
- opts.on('-b', '--ssh') { options[:ssh] = true }
21
+ opts.on('-r', '--rake COMMAND', 'Rake command') { |v| options[:rake] = v }
22
+ opts.on('-b', '--console') { options[:console] = true }
23
23
  end
24
24
 
25
25
  begin
26
26
  optparse.parse!
27
- mandatory = [:cluster]
27
+ mandatory = []
28
28
  missing = mandatory.select { |param| options[param].nil? }
29
29
  unless missing.empty?
30
30
  raise OptionParser::MissingArgument.new(missing.join(', '))
@@ -7,54 +7,80 @@ module Contexto
7
7
  attr_reader :display, :cluster, :service
8
8
 
9
9
  def initialize(params = {})
10
- @cluster = params.fetch(:cluster)
10
+ @cluster = params.fetch(:cluster) if params[: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
+ @rake = params.fetch(:rake) if params[:rake]
14
+ @console = params.fetch(:console)
14
15
  @display = Contexto::Display.new
15
16
  end
16
17
 
17
18
  def run
18
- if @ssh
19
+ if (@console || @rake)
19
20
  task = describe_tasks
20
21
  ec2_instance_id = describe_container_instance(task[:container_instance_arn])
21
- @connect = Contexto::SSH.new(describe_instances(ec2_instance_id), @cluster, @service, @container)
22
+ @ssh = Contexto::SSH.new(describe_instances(ec2_instance_id), @cluster, @service, @container)
23
+ if @console
24
+ @ssh.console
25
+ elsif @rake
26
+ @ssh.rake(@rake)
27
+ end
28
+ return
29
+ end
30
+ if !@cluster
31
+ clusters
22
32
  return
23
33
  end
24
34
  cluster
25
35
  puts "\n"
26
- return unless @service
27
- service
28
- puts "\n"
29
- tasks
36
+ if !@service
37
+ services
38
+ end
39
+ if @service
40
+ puts "\n"
41
+ service
42
+ puts "\n"
43
+ tasks
44
+ end
30
45
  end
31
46
 
32
47
  private
33
48
 
49
+ def clusters
50
+ title = "Clusters"
51
+ headings = %w(Name)
52
+ clusters = list_clusters
53
+ rows = []
54
+ clusters.each do |cluster|
55
+ rows << [cluster.split('/')[-1]]
56
+ end
57
+ @display.create_display(title, headings, rows)
58
+ end
59
+
34
60
  def cluster
35
- resp = ecs_client.describe_clusters(
36
- clusters: [
37
- @cluster
38
- ]
39
- )
40
61
  title = "Cluster #{@cluster}"
41
62
  headings = %w(Name Status Instances Services RunningTasks PendingTasks)
42
- cluster = resp.clusters[0].to_h
63
+ cluster = describe_clusters
43
64
  rows = []
44
65
  rows << [cluster[:cluster_name], cluster[:status], cluster[:registered_container_instances_count], cluster[:active_services_count], cluster[:running_tasks_count], cluster[:pending_tasks_count]]
45
66
  @display.create_display(title, headings, rows)
46
67
  end
47
68
 
69
+ def services
70
+ title = "Services"
71
+ headings = %w(Name)
72
+ services = list_services
73
+ rows = []
74
+ services.each do |service|
75
+ rows << [service.split('/')[-1]]
76
+ end
77
+ @display.create_display(title, headings, rows)
78
+ end
79
+
48
80
  def service
49
- resp = ecs_client.describe_services(
50
- cluster: @cluster,
51
- services: [
52
- @service
53
- ]
54
- )
55
81
  title = "Service #{@service}"
56
82
  headings = %w(Name Status Desired Running Pending)
57
- service = resp.services[0].to_h
83
+ service = describe_services
58
84
  rows = []
59
85
  rows << [service[:service_name], service[:status], service[:desired_count], service[:running_count], service[:pending_count]]
60
86
  @display.create_display(title, headings, rows)
@@ -75,6 +101,37 @@ module Contexto
75
101
  @display.create_display(title, headings, rows)
76
102
  end
77
103
 
104
+ def list_clusters
105
+ resp = ecs_client.list_clusters
106
+ resp.cluster_arns
107
+ end
108
+
109
+ def describe_clusters
110
+ resp = ecs_client.describe_clusters(
111
+ clusters: [
112
+ @cluster
113
+ ]
114
+ )
115
+ resp.clusters[0].to_h
116
+ end
117
+
118
+ def list_services
119
+ resp = ecs_client.list_services(
120
+ cluster: @cluster
121
+ )
122
+ resp.service_arns
123
+ end
124
+
125
+ def describe_services
126
+ resp = ecs_client.describe_services(
127
+ cluster: @cluster,
128
+ services: [
129
+ @service
130
+ ]
131
+ )
132
+ resp.services[0].to_h
133
+ end
134
+
78
135
  def describe_tasks
79
136
  resp = ecs_client.describe_tasks(
80
137
  cluster: @cluster,
@@ -64,7 +64,7 @@ module Contexto
64
64
  end
65
65
 
66
66
  def col_width
67
- @col_width ||= @rows.map(&:size).max + 6
67
+ @col_width ||= @rows.map(&:size).max + 10
68
68
  end
69
69
  end
70
70
  end
data/lib/contexto/ssh.rb CHANGED
@@ -11,12 +11,18 @@ module Contexto
11
11
  @bastion_user = ''
12
12
  @user_name = 'ec2-user'
13
13
  @options = {}
14
- connect
15
14
  end
16
15
 
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
16
+ def console
17
+ exec "#{cmd} c'\""
18
+ end
19
+
20
+ def rake(rake_cmd)
21
+ exec "#{cmd} #{rake_cmd}'\""
22
+ end
23
+
24
+ def cmd
25
+ "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 "
20
26
  end
21
27
  end
22
28
  end
@@ -1,4 +1,4 @@
1
1
  # Contexto version
2
2
  module Contexto
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
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.1
4
+ version: 0.2.0
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-27 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk