sonic-screwdriver 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/bin/commit_docs.sh +26 -0
  3. data/.circleci/config.yml +70 -0
  4. data/.gitignore +1 -1
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +13 -2
  7. data/Gemfile +3 -3
  8. data/Gemfile.lock +43 -14
  9. data/Guardfile +17 -10
  10. data/LICENSE.txt +2 -2
  11. data/README.md +10 -10
  12. data/Rakefile +9 -2
  13. data/docs/_config.yml +3 -0
  14. data/docs/_docs/help.md +1 -1
  15. data/docs/_docs/install-bastion.md +5 -15
  16. data/docs/_docs/install.md +3 -3
  17. data/docs/_docs/settings.md +40 -56
  18. data/docs/_docs/tutorial-ecs-exec.md +16 -20
  19. data/docs/_docs/tutorial-ecs-sh.md +73 -0
  20. data/docs/_docs/tutorial-execute.md +93 -17
  21. data/docs/_docs/tutorial-ssh.md +13 -18
  22. data/docs/_docs/why-ec2-run-command.md +1 -1
  23. data/docs/_includes/commands.html +5 -5
  24. data/docs/_includes/content.html +5 -0
  25. data/docs/_includes/css/main.css +15 -9
  26. data/docs/_includes/css/sonic.css +7 -5
  27. data/docs/_includes/example.html +4 -4
  28. data/docs/_includes/reference.md +1 -0
  29. data/docs/_includes/subnav.html +2 -1
  30. data/docs/_reference/sonic-completion.md +44 -0
  31. data/docs/_reference/sonic-completion_script.md +25 -0
  32. data/docs/_reference/sonic-ecs-exec.md +30 -0
  33. data/docs/_reference/sonic-ecs-help.md +21 -0
  34. data/docs/_reference/sonic-ecs-sh.md +35 -0
  35. data/docs/_reference/sonic-ecs.md +25 -0
  36. data/docs/_reference/sonic-execute.md +84 -0
  37. data/docs/_reference/sonic-list.md +40 -0
  38. data/docs/_reference/sonic-ssh.md +86 -0
  39. data/docs/_reference/sonic-version.md +21 -0
  40. data/docs/img/tutorials/ec2-console-run-command.png +0 -0
  41. data/docs/quick-start.md +9 -10
  42. data/docs/reference.md +12 -0
  43. data/{bin → exe}/sonic +3 -3
  44. data/lib/bash_scripts/docker-exec.sh +1 -0
  45. data/lib/bash_scripts/docker-run.sh +8 -1
  46. data/lib/sonic.rb +10 -2
  47. data/lib/sonic/{aws_services.rb → aws_service.rb} +6 -1
  48. data/lib/sonic/base_command.rb +82 -0
  49. data/lib/sonic/cli.rb +37 -27
  50. data/lib/sonic/command.rb +8 -22
  51. data/lib/sonic/completer.rb +161 -0
  52. data/lib/sonic/completer/script.rb +6 -0
  53. data/lib/sonic/completer/script.sh +10 -0
  54. data/lib/sonic/core.rb +15 -0
  55. data/lib/sonic/default/settings.yml +6 -16
  56. data/lib/sonic/docker.rb +29 -1
  57. data/lib/sonic/ecs.rb +22 -0
  58. data/lib/sonic/execute.rb +153 -18
  59. data/lib/sonic/help.rb +9 -0
  60. data/lib/sonic/help/command/send.md +10 -0
  61. data/lib/sonic/help/completion.md +22 -0
  62. data/lib/sonic/help/completion_script.md +3 -0
  63. data/lib/sonic/help/ecs/exec.md +8 -0
  64. data/lib/sonic/help/ecs/sh.md +13 -0
  65. data/lib/sonic/help/execute.md +60 -0
  66. data/lib/sonic/help/list.md +17 -0
  67. data/lib/sonic/help/ssh.md +60 -0
  68. data/lib/sonic/list.rb +4 -1
  69. data/lib/sonic/setting.rb +47 -0
  70. data/lib/sonic/ssh.rb +41 -20
  71. data/lib/sonic/ssh/identifier_detector.rb +6 -2
  72. data/lib/sonic/version.rb +1 -1
  73. data/sonic.gemspec +14 -9
  74. data/spec/lib/cli_spec.rb +5 -10
  75. data/spec/lib/sonic/execute_spec.rb +0 -1
  76. data/spec/spec_helper.rb +18 -10
  77. metadata +115 -16
  78. data/docs/_docs/tutorial-ecs-run.md +0 -100
  79. data/lib/sonic/cli/help.rb +0 -152
  80. data/lib/sonic/settings.rb +0 -115
data/spec/lib/cli_spec.rb CHANGED
@@ -1,28 +1,23 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- # to run specs with what's remembered from vcr
4
- # $ rake
5
- #
6
- # to run specs with new fresh data from aws api calls
7
- # $ rake clean:vcr ; time rake
8
3
  describe Sonic::CLI do
9
4
  before(:all) do
10
- @args = "--project-root spec/fixtures/project --noop"
5
+ @args = "--noop"
11
6
  end
12
7
 
13
8
  describe "sonic" do
14
9
  it "ssh should print out ssh command to be ran" do
15
- out = execute("bin/sonic ssh #{@args} --cluster default my-service")
10
+ out = execute("exe/sonic ssh #{@args} --cluster default my-service")
16
11
  expect(out).to include("=> ssh")
17
12
  end
18
13
 
19
14
  it "execute should print that command has been sent" do
20
- out = execute("bin/sonic execute #{@args} 1,2,3 uptime")
15
+ out = execute("exe/sonic execute #{@args} 1,2,3 uptime")
21
16
  expect(out).to include("Command sent")
22
17
  end
23
18
 
24
19
  it "list should list running instances" do
25
- out = execute("bin/sonic list #{@args} --header 1,2,3")
20
+ out = execute("exe/sonic list #{@args} --header 1,2,3")
26
21
  expect(out).to include("No instances found")
27
22
  end
28
23
  end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe Sonic::Execute do
4
4
  before(:each) do
5
5
  @options = {
6
- project_root: "spec/fixtures/project",
7
6
  filter: "i-066b140d9479e9681,i-09482b1a6e330fbf7"
8
7
  }
9
8
  end
data/spec/spec_helper.rb CHANGED
@@ -1,24 +1,32 @@
1
- ENV['TEST'] = '1'
1
+ ENV["TEST"] = "1"
2
2
  # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
3
- ENV['HOME'] = "spec/fixtures/home"
3
+ ENV["HOME"] = "spec/fixtures/home"
4
+ ENV["SONIC_ROOT"] = "spec/fixtures/project"
4
5
 
5
- # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
6
- ENV['HOME'] = "spec/fixtures/home"
6
+ # CodeClimate test coverage: https://docs.codeclimate.com/docs/configuring-test-coverage
7
+ # require 'simplecov'
8
+ # SimpleCov.start
7
9
 
8
10
  require "pp"
9
-
10
- root = File.expand_path('../../', __FILE__)
11
+ require "byebug"
12
+ root = File.expand_path("../", File.dirname(__FILE__))
11
13
  require "#{root}/lib/sonic"
12
14
 
13
- module Helpers
15
+ module Helper
14
16
  def execute(cmd)
15
- puts "Running: #{cmd}" if ENV['DEBUG']
17
+ puts "Running: #{cmd}" if show_command?
16
18
  out = `#{cmd}`
17
- puts out if ENV['DEBUG']
19
+ puts out if show_command?
18
20
  out
19
21
  end
22
+
23
+ # Added SHOW_COMMAND because DEBUG is also used by other libraries like
24
+ # bundler and it shows its internal debugging logging also.
25
+ def show_command?
26
+ ENV['DEBUG'] || ENV['SHOW_COMMAND']
27
+ end
20
28
  end
21
29
 
22
30
  RSpec.configure do |c|
23
- c.include Helpers
31
+ c.include Helper
24
32
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonic-screwdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,49 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: hashie
28
+ name: aws-sdk-ec2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-ecs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk-s3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-ssm
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
73
  - - ">="
@@ -53,7 +95,7 @@ dependencies:
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
- name: aws-sdk-ec2
98
+ name: hashie
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - ">="
@@ -67,7 +109,7 @@ dependencies:
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
- name: aws-sdk-ecs
112
+ name: memoist
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - ">="
@@ -81,7 +123,7 @@ dependencies:
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
- name: aws-sdk-ssm
126
+ name: thor
85
127
  requirement: !ruby/object:Gem::Requirement
86
128
  requirements:
87
129
  - - ">="
@@ -123,7 +165,7 @@ dependencies:
123
165
  - !ruby/object:Gem::Version
124
166
  version: '0'
125
167
  - !ruby/object:Gem::Dependency
126
- name: rake
168
+ name: byebug
127
169
  requirement: !ruby/object:Gem::Requirement
128
170
  requirements:
129
171
  - - ">="
@@ -178,7 +220,35 @@ dependencies:
178
220
  - - ">="
179
221
  - !ruby/object:Gem::Version
180
222
  version: '0'
181
- description: Multi-functional tool to manage AWS infrastructure
223
+ - !ruby/object:Gem::Dependency
224
+ name: rake
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: cli_markdown
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ description:
182
252
  email:
183
253
  - tung@boltops.com
184
254
  executables:
@@ -186,8 +256,11 @@ executables:
186
256
  extensions: []
187
257
  extra_rdoc_files: []
188
258
  files:
259
+ - ".circleci/bin/commit_docs.sh"
260
+ - ".circleci/config.yml"
189
261
  - ".gitignore"
190
262
  - ".rspec"
263
+ - ".ruby-version"
191
264
  - CHANGELOG.md
192
265
  - CONTRIBUTING.md
193
266
  - Gemfile
@@ -196,7 +269,6 @@ files:
196
269
  - LICENSE.txt
197
270
  - README.md
198
271
  - Rakefile
199
- - bin/sonic
200
272
  - docs/.gitignore
201
273
  - docs/CNAME
202
274
  - docs/Gemfile
@@ -210,7 +282,7 @@ files:
210
282
  - docs/_docs/next-steps.md
211
283
  - docs/_docs/settings.md
212
284
  - docs/_docs/tutorial-ecs-exec.md
213
- - docs/_docs/tutorial-ecs-run.md
285
+ - docs/_docs/tutorial-ecs-sh.md
214
286
  - docs/_docs/tutorial-execute.md
215
287
  - docs/_docs/tutorial-list.md
216
288
  - docs/_docs/tutorial-ssh.md
@@ -241,11 +313,22 @@ files:
241
313
  - docs/_includes/modals.html
242
314
  - docs/_includes/nav.html
243
315
  - docs/_includes/quotes.html
316
+ - docs/_includes/reference.md
244
317
  - docs/_includes/subnav.html
245
318
  - docs/_includes/ufo-ship-options.md
246
319
  - docs/_includes/uses.html
247
320
  - docs/_layouts/default.html
248
321
  - docs/_layouts/style.css
322
+ - docs/_reference/sonic-completion.md
323
+ - docs/_reference/sonic-completion_script.md
324
+ - docs/_reference/sonic-ecs-exec.md
325
+ - docs/_reference/sonic-ecs-help.md
326
+ - docs/_reference/sonic-ecs-sh.md
327
+ - docs/_reference/sonic-ecs.md
328
+ - docs/_reference/sonic-execute.md
329
+ - docs/_reference/sonic-list.md
330
+ - docs/_reference/sonic-ssh.md
331
+ - docs/_reference/sonic-version.md
249
332
  - docs/articles.md
250
333
  - docs/bin/web
251
334
  - docs/css/font-awesome/css/font-awesome.css
@@ -275,20 +358,36 @@ files:
275
358
  - docs/js/jquery.easing.min.js
276
359
  - docs/js/nav.js
277
360
  - docs/quick-start.md
361
+ - docs/reference.md
278
362
  - docs/style.css
363
+ - exe/sonic
279
364
  - lib/bash_scripts/docker-exec.sh
280
365
  - lib/bash_scripts/docker-run.sh
281
366
  - lib/sonic.rb
282
- - lib/sonic/aws_services.rb
367
+ - lib/sonic/aws_service.rb
368
+ - lib/sonic/base_command.rb
283
369
  - lib/sonic/checks.rb
284
370
  - lib/sonic/cli.rb
285
- - lib/sonic/cli/help.rb
286
371
  - lib/sonic/command.rb
372
+ - lib/sonic/completer.rb
373
+ - lib/sonic/completer/script.rb
374
+ - lib/sonic/completer/script.sh
375
+ - lib/sonic/core.rb
287
376
  - lib/sonic/default/settings.yml
288
377
  - lib/sonic/docker.rb
378
+ - lib/sonic/ecs.rb
289
379
  - lib/sonic/execute.rb
380
+ - lib/sonic/help.rb
381
+ - lib/sonic/help/command/send.md
382
+ - lib/sonic/help/completion.md
383
+ - lib/sonic/help/completion_script.md
384
+ - lib/sonic/help/ecs/exec.md
385
+ - lib/sonic/help/ecs/sh.md
386
+ - lib/sonic/help/execute.md
387
+ - lib/sonic/help/list.md
388
+ - lib/sonic/help/ssh.md
290
389
  - lib/sonic/list.rb
291
- - lib/sonic/settings.rb
390
+ - lib/sonic/setting.rb
292
391
  - lib/sonic/ssh.rb
293
392
  - lib/sonic/ssh/cli_options.rb
294
393
  - lib/sonic/ssh/ec2_tag.rb
@@ -323,7 +422,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
422
  version: '0'
324
423
  requirements: []
325
424
  rubyforge_project:
326
- rubygems_version: 2.7.3
425
+ rubygems_version: 2.7.6
327
426
  signing_key:
328
427
  specification_version: 4
329
428
  summary: Multi-functional tool to manage AWS infrastructure
@@ -1,100 +0,0 @@
1
- ---
2
- title: ECS Run
3
- ---
4
-
5
- The nice thing about the previous `ecs-exec` command we covered is that it allows you to get into the actual running container and debug with the exact environment that is on production. The cavaet with doing this is that we are affecting a live process in actual use. If you do something inadvertently wrong on the server it could affect users. Sometimes it is nice to start up a new container with the exact same environment as the other running containers but be isolated so you cannot affect live requests.
6
-
7
- The `sonic ecs-run` command is similar to the `sonic ecs-exec` command except it'll run a brand new container with the same environment variables as the task associated with the service. This allows you to debug in a container with the exact environment variables as the running tasks/containers without affecting the live service. So this is safer since you will not be able to mess up a live container that is in service.
8
-
9
- ### sonic ecs-run
10
-
11
- ```sh
12
- sonic ecs-run [ECS_SERVICE] --cluster [ECS_CLUSTER]
13
- ```
14
-
15
- Here's an example:
16
-
17
- ```sh
18
- sonic ecs-run hi-web-stag
19
- ```
20
-
21
- You see something like this:
22
-
23
- ```sh
24
- $ sonic ecs-run hi-web-stag
25
- Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
26
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
27
- => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh
28
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
29
- + exec bundle exec rails server -b 0.0.0.0
30
- => Booting WEBrick
31
- => Rails 4.2.3 application starting in development on http://0.0.0.0:3000
32
- => Run `rails server -h` for more startup options
33
- => Ctrl-C to shutdown server
34
- [2017-06-14 19:01:30] INFO WEBrick 1.3.1
35
- [2017-06-14 19:01:30] INFO ruby 2.3.3 (2016-11-21) [x86_64-linux]
36
- [2017-06-14 19:01:30] INFO WEBrick::HTTPServer#start: pid=1 port=3000
37
- ^C[2017-06-14 19:01:34] INFO going to shutdown ...
38
- [2017-06-14 19:01:34] INFO WEBrick::HTTPServer#start done.
39
- Exiting
40
- Connection to 34.211.195.71 closed.
41
- $
42
- ```
43
-
44
- In the above output a WEBrick server gets started. The reason this happens is because the Dockerfile default `CMD` in this project happens to start a webserver. Most of the time you probably want to start shell for debugging. To start a bash shell just tack the bash command at the end.
45
-
46
- ```sh
47
- $ sonic ecs-run hi-web-stag bash
48
- Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
49
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
50
- => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh bash
51
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
52
- root@56a495dbd5cd:/app#
53
- ```
54
-
55
- You are now in a docker container running exactly the same environment as the other running containers with the `hi-web-stag` service. While this looks similiar to the `ecs-exec` command this container is a brand new process and is isolated from any live request. You can do whatever you want in this container and experiment to your heart's content.
56
-
57
- We can prove that this is a brand new docker container that is outside of ECS' knowledge. Let's ssh into the same instance and take a look at all the running docker containers in another terminal.
58
-
59
- ```sh
60
- $ sonic ssh hi-web-stag docker ps
61
- => ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@34.211.195.71 docker ps
62
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
63
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64
- 29e7c1253c46 tongueroo/hi:ufo-2017-06-13T14-48-08-0a9eea5 "bash" 54 seconds ago Up 53 seconds 3000/tcp cocky_goldstine
65
- fc4035f90bdc tongueroo/hi:ufo-2017-06-13T14-48-08-0a9eea5 "bin/web" About an hour ago Up About an hour 0.0.0.0:32768->3000/tcp ecs-hi-web-stag-11-web-9eb081978abad89a9701
66
- bf646ae7789a amazon/amazon-ecs-agent:latest "/agent" About an hour ago Up About an hour ecs-agent
67
- $
68
- ```
69
-
70
- The output shows that there is this extra runnning container called `cocky_goldstine`. This name does not look like the typical ECS managed running docker container: `ecs-hi-web-stag-11-web-9eb081978abad89a9701`. This is how we know that this is a container outside of ECS control.
71
-
72
- ```sh
73
- $ sonic ecs-run hi-web-stag bash
74
- Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
75
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
76
- => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh bash
77
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
78
- root@29e7c1253c46:/app# exit
79
- exit
80
- Connection to 34.211.195.71 closed.
81
- $
82
- ```
83
-
84
- Let's exit out of the first terminal where you ran the original `sonic ecs-run` command and then list the running containers again.
85
-
86
- ```sh
87
- $ sonic ssh hi-web-stag docker ps
88
- => ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@34.211.195.71 docker ps
89
- Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
90
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91
- fc4035f90bdc tongueroo/hi:ufo-2017-06-13T14-48-08-0a9eea5 "bin/web" About an hour ago Up About an hour 0.0.0.0:32768->3000/tcp ecs-hi-web-stag-11-web-9eb081978abad89a9701
92
- bf646ae7789a amazon/amazon-ecs-agent:latest "/agent" About an hour ago Up About an hour ecs-agent
93
- $
94
- ```
95
-
96
- Zapped! The `cocky_goldstine` container that was created with `sonic ecs-run` is no more.
97
-
98
- <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-exec.md %}">Back</a>
99
- <a id="next" class="btn btn-primary" href="{% link _docs/tutorial-execute.md %}">Next Step</a>
100
- <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -1,152 +0,0 @@
1
- # https://github.com/erikhuda/thor/issues/398
2
- class Thor
3
- module Shell
4
- class Basic
5
- def print_wrapped(message, options = {})
6
- pretty_message = message.split("\n").map{|l| " #{l}"}.join("\n")
7
- stdout.puts pretty_message
8
- end
9
- end
10
- end
11
- end
12
-
13
- module Sonic
14
- class CLI < Command
15
- class Help
16
- class << self
17
- def ssh
18
- <<-EOL
19
- Ssh quicky into an EC2 instance using an identifier. The identifier can be many things. Examples of valid identifiers:
20
-
21
- * EC2 instance id. Example: i-067c5e3f026c1e801
22
- * EC2 tag value. Any tag value is search, the tag key does not matter only the tag value matters. Example: hi-web-prod
23
- * ECS service. Example: my-ecs-service
24
- * ECS container instance id. Example: 7fbc8c75-4675-4d39-a5a4-0395ff8cd474
25
- * ECS task id. Example: 1ed12abd-645c-4a05-9acf-739b9d790170
26
-
27
- When using ecs identifiers the `--cluster` option is required or can be set in ~/.sonic/settings.yml.
28
-
29
- Examples:
30
-
31
- $ sonic ssh i-067c5e3f026c1e801
32
- $ sonic ssh hi-web-prod
33
- $ sonic ssh --cluster my-cluster my-ecs-service
34
- $ sonic ssh 7fbc8c75-4675-4d39-a5a4-0395ff8cd474
35
- $ sonic ssh 1ed12abd-645c-4a05-9acf-739b9d790170
36
-
37
- Sonic ssh builds up the ssh command and calls it. For example, the following commands:
38
-
39
- sonic ssh i-027363802c6ff314f
40
-
41
- Translates to:
42
-
43
- ssh ec2-user@ec2-52-24-216-170.us-west-2.compute.amazonaws.com
44
-
45
- You can also tack on any command to be run at the end of the command. Example:
46
-
47
- $ sonic ssh i-027363802c6ff314f uptime
48
- => ssh ec2-user@ec2-52-24-216-170.us-west-2.compute.amazonaws.com uptime
49
- 15:57:02 up 18:21, 0 users, load average: 0.00, 0.01, 0.00
50
-
51
- Specifying pem keys:
52
-
53
- The recommended way to specify custom private keys is to use ssh-agent as covered here: https://blog.boltops.com/2017/09/21/3-ssh-tips-ssh-agent-tunnel-and-escaping-from-the-dead
54
-
55
- But you can also specify the pem key to use with the -i option. Example:
56
-
57
- $ sonic ssh -i ~/.ssh/id_rsa-custom ec2-user@ec2-52-24-216-170.us-west-2.compute.amazonaws.com
58
-
59
- Retry option:
60
-
61
- For newly launched instances, the instance's ssh access might not be quite ready. Typically, you must press up enter repeatedly until the instance is ready. Sonic ssh has a retry option that automates this. Example:
62
-
63
- $ sonic ssh -r i-027363802c6ff314f
64
-
65
- Bastion Host Support
66
-
67
- Sonic ssh also supports a bastion host.
68
-
69
- $ sonic ssh --bastion bastion.domain.com i-027363802c6ff314f
70
- $ sonic ssh --bastion user@bastion.domain.com i-027363802c6ff314f
71
-
72
- Here's what the output looks like:
73
-
74
- $ sonic ssh --bastion 34.211.223.3 i-0f7f833131a51ce35 uptime
75
- => ssh -At ec2-user@34.211.223.3 ssh ec2-user@10.10.110.135 uptime
76
- 17:57:59 up 37 min, 0 users, load average: 0.00, 0.02, 0.00
77
- Connection to 34.211.223.3 closed.
78
- $
79
- EOL
80
- end
81
-
82
- def ecs_exec
83
- <<-EOL
84
- Ssh into an ECS container instance, finds a running docker container associated
85
- with the service and docker exec's into it.
86
-
87
- Examples:
88
-
89
- $ sonic ecs-exec my-service --cluster my-cluster
90
-
91
- You can use a variety of identifiers. These include the ECS service name and task id.
92
- EOL
93
- end
94
-
95
- def ecs_run
96
- <<-EOL
97
- Ssh into an ECS container instance and runs a docker container using the same
98
- environment and image as the specified running service.
99
-
100
- Examples:
101
-
102
- $ sonic ecs-run --cluster my-cluster my-service
103
- $ sonic ecs-run --cluster my-cluster my-service
104
-
105
- # If there are flags in the command that you want to pass down to the docker
106
- run command you will need to put the command in single quotes. This is due to
107
- the way Thor (what this tool uses) parses options.
108
-
109
- $ sonic ecs-run --cluster prod-hi hi-web-prod 'rake -T'
110
- EOL
111
- end
112
-
113
- def execute
114
- <<-EOL
115
- Run as a command across a list of servers. A filter must be provided. The filter can be a mix of instance ids and ec2 tags. This command can also take a path to a file. To specify a path to a file use file:// at the beginning of your file.
116
-
117
- Examples:
118
-
119
- $ sonic execute hi-web-prod uptime
120
- $ sonic execute hi-web-prod,hi-worker-prod,hi-clock-prod uptime
121
- $ sonic execute i-030033c20c54bf149,i-030033c20c54bf150 uname -a
122
- $ sonic execute i-030033c20c54bf149 file://hello.sh
123
-
124
- You cannot mix instance ids and tag names in the filter.
125
- EOL
126
- end
127
-
128
- def list
129
- <<-EOL
130
- List ec2 servers. A filter must be provided. The filter can be a mix of instance ids and ec2 tags. sonic list will auto-detect the what type of filter it is filter appropriately. The filter for listing is optional.
131
-
132
- Examples:
133
-
134
- $ sonic list
135
- $ sonic list hi-web-prod
136
- $ sonic list hi-web-prod,hi-clock-prod
137
- $ sonic list i-09482b1a6e330fbf7
138
-
139
- Example Output:
140
-
141
- $ sonic list --header i-09482b1a6e330fbf7
142
- Instance Id Public IP Private IP Type
143
- i-09482b1a6e330fbf7 54.202.152.168 172.31.21.108 t2.small
144
- $
145
-
146
- You cannot mix instance ids and tag names in the filter.
147
- EOL
148
- end
149
- end
150
- end
151
- end
152
- end