contexto 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -9
- data/bin/contexto +4 -4
- data/lib/contexto/contextualize.rb +78 -21
- data/lib/contexto/display.rb +1 -1
- data/lib/contexto/ssh.rb +10 -4
- data/lib/contexto/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70a1d561afdac4ad1e724a0f4e5174b2e302b5c6
|
4
|
+
data.tar.gz: 899491e29583693bcde3f42d5f02b17dfb943765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
75
|
-
|
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 --
|
78
|
+
$ contexto -c sandbox -s backend-app -t app --console
|
79
79
|
|
80
80
|
** Contexto Contextualizes **
|
81
81
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
82
82
|
|
83
|
-
|
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
|
-
|
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
|
-
|
89
|
-
|
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[:
|
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('-
|
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 = [
|
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
|
-
@
|
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 @
|
19
|
+
if (@console || @rake)
|
19
20
|
task = describe_tasks
|
20
21
|
ec2_instance_id = describe_container_instance(task[:container_instance_arn])
|
21
|
-
@
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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 =
|
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 =
|
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,
|
data/lib/contexto/display.rb
CHANGED
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
|
18
|
-
|
19
|
-
|
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
|
data/lib/contexto/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|