sonic-screwdriver 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/Gemfile.lock +26 -2
  4. data/README.md +156 -23
  5. data/bin/sonic +8 -1
  6. data/docs/.gitignore +4 -0
  7. data/docs/CNAME +1 -0
  8. data/docs/Gemfile +3 -0
  9. data/docs/LICENSE +21 -0
  10. data/docs/README.md +21 -0
  11. data/docs/_config.yml +69 -0
  12. data/docs/_docs/commands.md +10 -0
  13. data/docs/_docs/how-it-works.md +34 -0
  14. data/docs/_docs/install.md +75 -0
  15. data/docs/_docs/next-steps.md +18 -0
  16. data/docs/_docs/settings.md +73 -0
  17. data/docs/_docs/sonic-ecs-exec.md +7 -0
  18. data/docs/_docs/sonic-ecs-run.md +7 -0
  19. data/docs/_docs/sonic-execute.md +7 -0
  20. data/docs/_docs/sonic-help.md +7 -0
  21. data/docs/_docs/sonic-list.md +7 -0
  22. data/docs/_docs/sonic-ssh.md +7 -0
  23. data/docs/_docs/tutorial-ecs-exec.md +69 -0
  24. data/docs/_docs/tutorial-ecs-run.md +94 -0
  25. data/docs/_docs/tutorial-execute.md +38 -0
  26. data/docs/_docs/tutorial-ssh.md +119 -0
  27. data/docs/_docs/tutorial.md +11 -0
  28. data/docs/_docs/why.md +27 -0
  29. data/docs/_includes/about.html +19 -0
  30. data/docs/_includes/commands.html +28 -0
  31. data/docs/_includes/contact.html +17 -0
  32. data/docs/_includes/contact_disqus.html +16 -0
  33. data/docs/_includes/contact_static.html +17 -0
  34. data/docs/_includes/content.html +21 -0
  35. data/docs/_includes/css/bootstrap.min.css +7 -0
  36. data/docs/_includes/css/main.css +481 -0
  37. data/docs/_includes/css/quotes.css +102 -0
  38. data/docs/_includes/css/sonic.css +163 -0
  39. data/docs/_includes/css/syntax.css +60 -0
  40. data/docs/_includes/css/table.css +53 -0
  41. data/docs/_includes/css/timeline.css +201 -0
  42. data/docs/_includes/edit-on-github.html +11 -0
  43. data/docs/_includes/example.html +21 -0
  44. data/docs/_includes/footer.html +49 -0
  45. data/docs/_includes/head.html +32 -0
  46. data/docs/_includes/header.html +15 -0
  47. data/docs/_includes/js.html +28 -0
  48. data/docs/_includes/js_disqus.html +21 -0
  49. data/docs/_includes/modals.html +40 -0
  50. data/docs/_includes/nav.html +27 -0
  51. data/docs/_includes/quotes.html +19 -0
  52. data/docs/_includes/subnav.html +35 -0
  53. data/docs/_includes/ufo-ship-options.md +13 -0
  54. data/docs/_includes/uses.html +19 -0
  55. data/docs/_layouts/default.html +11 -0
  56. data/docs/_layouts/style.css +6 -0
  57. data/docs/articles.md +5 -0
  58. data/docs/css/font-awesome/css/font-awesome.css +1566 -0
  59. data/docs/css/font-awesome/css/font-awesome.min.css +4 -0
  60. data/docs/css/font-awesome/fonts/FontAwesome.otf +0 -0
  61. data/docs/css/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  62. data/docs/css/font-awesome/fonts/fontawesome-webfont.svg +504 -0
  63. data/docs/css/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  64. data/docs/css/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  65. data/docs/docs.md +21 -0
  66. data/docs/img/logos/boltops-logo-full.png +0 -0
  67. data/docs/img/logos/boltops-logo.png +0 -0
  68. data/docs/img/sonic-screwdriver.jpg +0 -0
  69. data/docs/img/tutorials/ec2-console-public-ip.png +0 -0
  70. data/docs/img/ufo.jpg +0 -0
  71. data/docs/index.html +9 -0
  72. data/docs/js/bootstrap.js +2114 -0
  73. data/docs/js/bootstrap.min.js +6 -0
  74. data/docs/js/cbpAnimatedHeader.js +44 -0
  75. data/docs/js/cbpAnimatedHeader.min.js +11 -0
  76. data/docs/js/classie.js +80 -0
  77. data/docs/js/contact_me.js +70 -0
  78. data/docs/js/contact_me_static.js +23 -0
  79. data/docs/js/freelancer.js +37 -0
  80. data/docs/js/jqBootstrapValidation.js +912 -0
  81. data/docs/js/jquery-1.11.0.js +4 -0
  82. data/docs/js/jquery.easing.min.js +44 -0
  83. data/docs/js/nav.js +53 -0
  84. data/docs/quick-start.md +39 -0
  85. data/docs/style.css +3 -0
  86. data/lib/bash_scripts/docker-exec.sh +15 -0
  87. data/lib/bash_scripts/docker-run.sh +15 -0
  88. data/lib/sonic.rb +11 -2
  89. data/lib/sonic/aws_services.rb +19 -0
  90. data/lib/sonic/cli.rb +37 -8
  91. data/lib/sonic/cli/help.rb +123 -3
  92. data/lib/sonic/default/settings.yml +12 -0
  93. data/lib/sonic/docker.rb +128 -0
  94. data/lib/sonic/execute.rb +131 -0
  95. data/lib/sonic/list.rb +85 -0
  96. data/lib/sonic/settings.rb +80 -0
  97. data/lib/sonic/ssh.rb +136 -0
  98. data/lib/sonic/ssh/ec2_tag.rb +59 -0
  99. data/lib/sonic/ssh/identifier_detector.rb +145 -0
  100. data/lib/sonic/ui.rb +26 -0
  101. data/lib/sonic/version.rb +2 -2
  102. data/qa.md +21 -0
  103. data/sonic.gemspec +3 -1
  104. data/spec/fixtures/home/.gitkeep +0 -0
  105. data/spec/fixtures/project/.gitkeep +0 -0
  106. data/spec/fixtures/project/command.txt +2 -0
  107. data/spec/lib/cli_spec.rb +16 -6
  108. data/spec/lib/sonic/execute_spec.rb +35 -0
  109. data/spec/spec_helper.rb +5 -3
  110. metadata +133 -3
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: Commands
3
+ ---
4
+
5
+ The [tutorial]({% link _docs/tutorial.md %}) does a great job of covering the main sonic commands and overall usage. In the next sections we'll cover the sonic commands in more detail.
6
+
7
+ <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-execute.md %}">Back</a>
8
+ <a id="next" class="btn btn-primary" href="{% link _docs/sonic-ssh.md %}">Next Step</a>
9
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
10
+
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: How It Works
3
+ ---
4
+
5
+ ### Internals
6
+
7
+ The process that I outline in the [Why]({% link _docs/why.md %}) about clicking around is close to the logic that actually takes place in the tool but it is actually slightly different. Here's an overview of what actually happens internally for those who are interested.
8
+
9
+ Steps:
10
+
11
+ 1. list-tasks: list all the tasks for their task_arns (scoped to service). this is all tasks on the service. We already know the service name!
12
+ 2. describe-tasks: Using the task_arns from list-tasks. This will provide the container instance scoped the service since list-tasks was scoped to service. Keep the task arn for step 7. Also describe-task-definition and capture env vars and image for step 8b.
13
+ 3. describe-container-instances: Using container\_instance\_arn from step 2. This will provide the instance_id to ssh into.
14
+ 4. ec2 describe-instances to get the dns name or IP address.
15
+ 5. Copy over files with required info over to the server with scp.
16
+ 6. ssh into the machine with IP address.
17
+ 7. Use the ecs metadata and pass it the task_arn from step 2. This will provide the map to the container id.
18
+ 8. Run docker command
19
+ 1. docker exec -ti CONTAINER_ID `options[:command]`
20
+ 2. docker run `options[:run_options]` IMAGE `options[:command]`
21
+
22
+ In order to pass info over from your local machine to the container instance a file is generated and copied in step 5. File contains:
23
+
24
+ * Options all the way from the original cli call like command to run. This is in json form.
25
+ A bash script is also copied.
26
+ * Bash script gets the container id using the task_arn. It also will run the docker exec or run command.
27
+ * So bash script does steps 7 and 8.1 or 8.2.
28
+
29
+ NOTE: I thought it would be possible to map the container instance info from `aws ecs describe-services` but it is not possible. But we can map to the container instance DNS name starting from `aws ecs list-tasks`.
30
+
31
+
32
+ <a id="prev" class="btn btn-basic" href="{% link _docs/why.md %}">Back</a>
33
+ <a id="next" class="btn btn-primary" href="{% link _docs/next-steps.md %}">Next Step</a>
34
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,75 @@
1
+ ---
2
+ title: Installation
3
+ ---
4
+
5
+ ### Install with Bolts Toolbelt
6
+
7
+ If you want to quickly install sonic without having to worry about sonic's dependency you can simply install the Bolts Toolbelt which has sonic included.
8
+
9
+ ```sh
10
+ brew cask install boltopslabs/software/bolts
11
+ ```
12
+
13
+ For more information about the Bolts Toolbelt or to get an installer for another operating system visit: [https://boltops.com/toolbelt](https://boltops.com/toolbelt)
14
+
15
+ ### Install with RubyGems
16
+
17
+ If you prefer to install sonic via RubyGems follow the instructions:
18
+
19
+ ```sh
20
+ gem install sonic-screwdriver
21
+ ```
22
+
23
+ Or you can add sonic to your Gemfile in your project if you are working with a ruby project. It is not required for your project to be a ruby project to use sonic.
24
+
25
+ ```ruby
26
+ gem "sonic-screwdriver"
27
+ ```
28
+
29
+ ### Additional Server Side Dependencies
30
+
31
+ #### sonic ecs-* dependencies
32
+
33
+ In order for the `sonic ecs-*` trickery to work `jq` is used on the server side. This is covered in the [How It Works]({% link _docs/how-it-works.md %}) section. So you must have `jq` installed on the servers for the `sonic ecs-*` commands to work.
34
+
35
+ One way to install `jq` quickly is by using the `sonic execute` command. For example:
36
+
37
+ ```sh
38
+ sonic execute -f hi-web-stag yum install -y jq
39
+ ```
40
+
41
+ It is recommended that you install `jq` with the UserData script or bake it into the AMI though.
42
+
43
+ #### sonic execute dependencies
44
+
45
+ The `sonic execute` works alongside [Amazon EC2 Run Command](https://aws.amazon.com/ec2/execute/). So this is the required to be installed on the servers for `sonic execute` to work.
46
+
47
+ #### Amazon EC2 Run Manager Installation
48
+
49
+ Installing the EC2 Run Manager agent on your linux servers is super simple and often only one command. The recommended instructions are the offical Amazon EC2 Systems Manager [Install SSM Agent](http://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html) documentation.
50
+
51
+ The trickest part of installing is likely making sure that the agent on the server has successfully checked into the SSM service. Verify it by tailing `/var/log/amazon/ssm/errors/errors.log`.
52
+
53
+ If you are having issues, it is most likely IAM issues. Amazon also provides [Configuring Security Roles](http://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-access.html) docs to fix any IAM issues.
54
+
55
+ You can verify the instances that have successfully checked into SSM with `aws ssm describe-instance-information`:
56
+
57
+ ```sh
58
+ aws ssm describe-instance-information --output text --query "InstanceInformationList[*]"
59
+ ```
60
+
61
+ Here's an exmaple of the output:
62
+
63
+ ```sh
64
+ $ aws ssm describe-instance-information --output text --query "InstanceInformationList[*]"
65
+ 2.0.822.0 ip-10-10-41-38 10.10.41.38 i-030033c20c54bf149 True 1497482505.12 Online Amazon Linux AMI Linux 2017.03 EC2Instance
66
+ 2.0.822.0 ip-10-10-110-135 10.10.110.135 i-0f7f833131a51ce35 True 1497482686.53 Online Amazon Linux AMI Linu2016.09 EC2Instance
67
+ $
68
+ ```
69
+
70
+ More information is provided in the AWS Run Command Walkthrough [Using the AWS CLI](http://docs.aws.amazon.com/systems-manager/latest/userguide/walkthrough-cli.html).
71
+
72
+ <a id="prev" class="btn btn-basic" href="{% link docs.md %}">Back</a>
73
+ <a id="next" class="btn btn-primary" href="{% link _docs/tutorial.md %}">Next Step</a>
74
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
75
+
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: Next Steps
3
+ ---
4
+
5
+ This concludes the tutorial guide for sonic. Hopefully you are now more comfortable with sonic's basic usage, concepts, and have a feel for the workflow.
6
+
7
+ From here, there are a few resources that can help you continue along:
8
+
9
+ * Check out the [sonic](https://github.com/boltopslabs/sonic) repo on GitHub
10
+ * Submit an issue
11
+ * Write a blog post describing how you are using sonic, or an interesting problem sonic has allowed you to solve
12
+
13
+ Everyone can contribute to make sonic better, including the documentation. These docs are of the same sonic repo in the [docs folder](https://github.com/boltopslabs/sonic/tree/master/docs). Please fork the project and open a pull request! We love your pull requests. Contributions are encouraged and welcomed!
14
+
15
+ <a id="prev" class="btn btn-basic" href="{% link _docs/how-it-works.md %}">Back</a>
16
+ <!-- <a id="next" class="btn btn-primary" href="{% link articles.md %}">Next Step</a> -->
17
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
18
+
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: Settings
3
+ ---
4
+
5
+ You can adjust the behavior of sonic and set some handy default values with `settings.yml` files. There can exist multiple settings files which get loaded and merged. The options from the files follow the the following precedence rules:
6
+
7
+ 1. project - The project's `.sonic/settings.yml` values take the highest precedence.
8
+ 2. user - The user's `~/.sonic/settings.yml` values take the second highest precedence.
9
+ 3. default - The [default settings](https://github.com/boltopslabs/sonic/blob/master/lib/sonic/default/settings.yml) bundled with the tool takes the lowest precedence.
10
+
11
+ Here is an `settings.yml` example:
12
+
13
+ ```yaml
14
+ bastion: bastion.mydomain.com
15
+ host_key_check: false
16
+ service_cluster:
17
+ default: # defaults to nil
18
+ hi-web-prod: prod
19
+ hi-clock-prod: prod
20
+ hi-worker-prod: prod
21
+ hi-web-stag: stag
22
+ hi-clock-stag: stag
23
+ hi-worker-stag: stag
24
+ user: ec2-user
25
+ ```
26
+
27
+ The following table covers the different setting options:
28
+
29
+ Setting | Description | Default
30
+ ------------- | ------------- | -------------
31
+ bastion | Bastion host to use as the jump host. Examples: bastion.mydomain.com, myuser@bastion.myuser.com or 123.123.123.123. | (no value)
32
+ host_key_check | Controls whether or not use the strict host checking ssh option. Since EC2 server host changes often the default value is false. | false
33
+ service_cluster | Service to cluster mapping. This is a Hash structure that maps the service name to cluster names. | (no value)
34
+ user | User to ssh into the server with. This can be overriden at the CLI with the user@host notation but can be set in the settings.yml file also. | ec2-user
35
+
36
+ The default settings are located within the package tool at [lib/sonic/default/settings.yml](https://github.com/boltopslabs/sonic/blob/master/lib/sonic/default/settings.yml).
37
+
38
+ ### Service to Cluster Mapping
39
+
40
+ One of the useful options is the `service_clsuter`. This option maps service names to cluster names. This saves you from typing the `--cluster` option over and over. Here is an example `~/.sonic/settings.yml`:
41
+
42
+ ```yaml
43
+ user: ec2-user
44
+ service_cluster:
45
+ default: my-default-cluster
46
+ hi-web-prod: prod
47
+ hi-clock-prod: prod
48
+ hi-worker-prod: prod
49
+ hi-web-stag: stag
50
+ hi-clock-stag: stag
51
+ hi-worker-stag: stag
52
+ ```
53
+
54
+ This results in shorter commands:
55
+
56
+ ```
57
+ sonic ssh hi-web-prod
58
+ sonic ssh hi-clock-prod
59
+ sonic ssh hi-worker-stag
60
+ ```
61
+
62
+ Instead of what you normally would have to type:
63
+
64
+ ```
65
+ sonic ssh hi-web-prod --cluster prod
66
+ sonic ssh hi-clock-prod --cluster prod
67
+ sonic ssh hi-worker-stag --cluster stag
68
+ ```
69
+
70
+
71
+ <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-execute.md %}">Back</a>
72
+ <a id="next" class="btn btn-primary" href="{% link _docs/why.md %}">Next Step</a>
73
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: sonic ecs-exec
3
+ ---
4
+
5
+ <a id="prev" class="btn btn-basic" href="{% link _docs/sonic-ssh.md %}">Back</a>
6
+ <a id="next" class="btn btn-primary" href="{% link _docs/sonic-ecs-run.md %}">Next Step</a>
7
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: sonic ecs run
3
+ ---
4
+
5
+ <a id="prev" class="btn btn-basic" href="{% link _docs/sonic-ecs-exec.md %}">Back</a>
6
+ <a id="next" class="btn btn-primary" href="{% link _docs/sonic-list.md %}">Next Step</a>
7
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: sonic execute
3
+ ---
4
+
5
+ <a id="prev" class="btn btn-basic" href="{% link _docs/sonic-list.md %}">Back</a>
6
+ <a id="next" class="btn btn-primary" href="{% link _docs/sonic-help.md %}">Next Step</a>
7
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: sonic help
3
+ ---
4
+
5
+ <a id="prev" class="btn btn-basic" href="{% link _docs/sonic-execute.md %}">Back</a>
6
+ <a id="next" class="btn btn-primary" href="{% link _docs/settings.md %}">Next Step</a>
7
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: sonic list
3
+ ---
4
+
5
+ <a id="prev" class="btn btn-basic" href="{% link _docs/sonic-ecs-run.md %}">Back</a>
6
+ <a id="next" class="btn btn-primary" href="{% link _docs/sonic-execute.md %}">Next Step</a>
7
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: sonic-ssh
3
+ ---
4
+
5
+ <a id="prev" class="btn btn-basic" href="{% link _docs/commands.md %}">Back</a>
6
+ <a id="next" class="btn btn-primary" href="{% link _docs/sonic-ecs-exec.md %}">Next Step</a>
7
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,69 @@
1
+ ---
2
+ title: ECS Exec
3
+ ---
4
+
5
+ In the previous section we showed you how to use `sonic ssh` to quickly ssh into an instance. Some of the identifiers used were ECS identifiers. As you can see sonic is very much ECS aware. It was built with ECS in mind.
6
+
7
+ One of the things `sonic` can do is go from your local machine, ssh into an EC2 Container Instance, find the running docker instance and jump into the docker container via `docker exec`.
8
+
9
+ It does this with a variety of scripts and trickery and is covered in [How It Works]({% link _docs/how-it-works.md %}). Let's through examples of how sonic can help you get into an docker container running on ECS quickly.
10
+
11
+ ### sonic ecs-exec
12
+
13
+ ```sh
14
+ sonic ecs-exec [ECS_SERVICE] --cluster [ECS_CLUSTER]
15
+ ```
16
+
17
+ Here's a concrete example:
18
+
19
+ ```sh
20
+ sonic ecs-exec hi-web-stag --cluster stag
21
+ ```
22
+
23
+ You should see something like this:
24
+
25
+ ```sh
26
+ $ sonic ecs-exec hi-web-stag --cluster stag
27
+ Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
28
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
29
+ => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-exec.sh
30
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
31
+ root@fc4035f90bdc:/app#
32
+ ```
33
+
34
+ What you see above is a bash shell within the docker container! With one command you have placed yourself into the running container 🎉
35
+
36
+ As mentioned in the [previous section]({% link _docs/tutorial-ssh.md %}) and also in the [Settings documentation]({% link _docs/settings.md %}) you can configure a `~/.sonic/settings.yml` file which shortens the command further. Let's add this to your settings:
37
+
38
+ ```yaml
39
+ service_cluster:
40
+ default: stag
41
+ hi-web-stag: stag
42
+ ```
43
+
44
+ This makes the command consise and memorable.
45
+
46
+ ```sh
47
+ sonic ecs-exec hi-web-stag
48
+ ```
49
+
50
+ The rest of this section assumes that you have the `~/.sonic/settings.yml` set up.
51
+
52
+ You can also tack on a command at the end of the `ecs-exec` command to be run as a one off instead of starting a bash shell. Example:
53
+
54
+ ```
55
+ $ sonic ecs-exec hi-web-stag uname -a
56
+ Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
57
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
58
+ => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-exec.sh uname -a
59
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
60
+ Linux fc4035f90bdc 4.4.51-40.58.amzn1.x86_64 #1 SMP Tue Feb 28 21:57:17 UTC 2017 x86_64 GNU/Linux
61
+ Connection to 34.211.195.71 closed.
62
+ $
63
+ ```
64
+
65
+ Remember the command runs within the running docker container.
66
+
67
+ <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ssh.md %}">Back</a>
68
+ <a id="next" class="btn btn-primary" href="{% link _docs/tutorial-ecs-run.md %}">Next Step</a>
69
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,94 @@
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 enviornment 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
+ ### sonic ecs-run
8
+
9
+ Sonic provides a `sonic ecs-run` command that allows you to start up a new container with the same environment as one of the running containers. Here's an example:
10
+
11
+ ```sh
12
+ sonic ecs-run hi-web-stag
13
+ ```
14
+
15
+ You see something like this:
16
+
17
+ ```sh
18
+ $ sonic ecs-run hi-web-stag
19
+ Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
20
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
21
+ => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh
22
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
23
+ + exec bundle exec rails server -b 0.0.0.0
24
+ => Booting WEBrick
25
+ => Rails 4.2.3 application starting in development on http://0.0.0.0:3000
26
+ => Run `rails server -h` for more startup options
27
+ => Ctrl-C to shutdown server
28
+ [2017-06-14 19:01:30] INFO WEBrick 1.3.1
29
+ [2017-06-14 19:01:30] INFO ruby 2.3.3 (2016-11-21) [x86_64-linux]
30
+ [2017-06-14 19:01:30] INFO WEBrick::HTTPServer#start: pid=1 port=3000
31
+ ^C[2017-06-14 19:01:34] INFO going to shutdown ...
32
+ [2017-06-14 19:01:34] INFO WEBrick::HTTPServer#start done.
33
+ Exiting
34
+ Connection to 34.211.195.71 closed.
35
+ $
36
+ ```
37
+
38
+ 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 shell to debug. To start a bash shell just tack the bash command at the end.
39
+
40
+ ```sh
41
+ $ sonic ecs-run hi-web-stag bash
42
+ Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
43
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
44
+ => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh bash
45
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
46
+ root@56a495dbd5cd:/app#
47
+ ```
48
+
49
+ 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 is docker container is a new process and is isolated from any live request. You can do whatever you want to this container and experiment to your heart's content.
50
+
51
+ 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.
52
+
53
+ ```sh
54
+ $ sonic ssh hi-web-stag docker ps
55
+ => ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@34.211.195.71 docker ps
56
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
57
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58
+ 29e7c1253c46 tongueroo/hi:ufo-2017-06-13T14-48-08-0a9eea5 "bash" 54 seconds ago Up 53 seconds 3000/tcp cocky_goldstine
59
+ 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
60
+ bf646ae7789a amazon/amazon-ecs-agent:latest "/agent" About an hour ago Up About an hour ecs-agent
61
+ $
62
+ ```
63
+
64
+ 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`
65
+
66
+ ```sh
67
+ $ sonic ecs-run hi-web-stag bash
68
+ Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
69
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
70
+ => ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh bash
71
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
72
+ root@29e7c1253c46:/app# exit
73
+ exit
74
+ Connection to 34.211.195.71 closed.
75
+ $
76
+ ```
77
+
78
+ Let's exit out of the first terminate where you ran the original `sonic ecs-run` command and then list the running containers again.
79
+
80
+ ```sh
81
+ $ sonic ssh hi-web-stag docker ps
82
+ => ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@34.211.195.71 docker ps
83
+ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
84
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85
+ 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
86
+ bf646ae7789a amazon/amazon-ecs-agent:latest "/agent" About an hour ago Up About an hour ecs-agent
87
+ $
88
+ ```
89
+
90
+ Zapped! The container that was created with `sonic ecs-run` is no more.
91
+
92
+ <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-exec.md %}">Back</a>
93
+ <a id="next" class="btn btn-primary" href="{% link _docs/tutorial-execute.md %}">Next Step</a>
94
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,38 @@
1
+ ---
2
+ title: Sonic Execute
3
+ ---
4
+
5
+ Sonic provides a way to execute commands remotely and securely across a list of AWS servers. It does this by relying on [Amazon EC2 Run Command](https://aws.amazon.com/ec2/execute/). Sonic hides any complexity and provides a simplier interface for you. Example:
6
+
7
+ ```sh
8
+ sonic execute --filter hi-web-stag "uptime"
9
+ ```
10
+
11
+ Let's do something more useful:
12
+
13
+ ```sh
14
+ sonic execute --filter hi-web-stag "yum install -y curl"
15
+ ```
16
+
17
+ The output of the commands ran are showed in the EC2 Run Command Console. Here's an example:
18
+
19
+ ```
20
+ $ sonic execute --filter hi-web-stag uptime
21
+ Command sent to AWS SSM. To check the details of the command:
22
+ aws ssm list-commands --command-id 4133e5eb-aa18-40dd-be25-a176eb15e515
23
+ Pro tip: the aws ssm command is already in your copy/paste clipboard.
24
+ $
25
+ ```
26
+
27
+ ### Why Amazon EC2 Run Command
28
+
29
+ Why use Amazon EC2 Run Command vs just using a multi-ssh session?
30
+
31
+ * Some times it is not possible to use ssh across several servers. For example, really secured networks might have [MFA setup](TODO) so you need to authorized the requests via your phone before the command actually gets ran. In this case, you would get annoying confirmation notifications on your phone over and over as you approve each request for each of your servers.
32
+ * EC2 Run Command provides auditability. Any command that runs the EC2 Run Command gets logged and is tracked.
33
+ * The EC2 Run Manager has the ability to run the command in "blue/green" fashion with concurrency controls. Say you have 100 servers, you can tell EC2 Run Manager to run the command on one server first and the expodentially roll it out to the rest of the servers until the command has successfully ran on all servers. If it the command errors then it execute can be told to halt.
34
+ * This is all provided for free by using EC2 Run Manager.
35
+
36
+ <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-run.md %}">Back</a>
37
+ <a id="next" class="btn btn-primary" href="{% link _docs/settings.md %}">Next Step</a>
38
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>