sonic-screwdriver 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37ec82ca43bde6ed94fef35b7c6f275890be09f3
4
- data.tar.gz: dcb1bbf176d88da619c25561b1f947b2cbc52e28
3
+ metadata.gz: 4e57a38964860cd1bb9eda130089260cb75aeca6
4
+ data.tar.gz: 40339059f215ef4b643cb7d16d2f3da251808554
5
5
  SHA512:
6
- metadata.gz: 36e8aee57411d03defaee3439abc17684f8aca3f1c8dac1c6203cd496e499e05b9bc3d93601f9dfa120d7b36c68fb728e2efe78e2369c144b21f5561ac4c571a
7
- data.tar.gz: 70ec6d267b6db685832816648a51b6cb7495f652d74d91f2b4fd742298422b0d3151e1c916069ae3e272985006306d7ad9b6f1beec5120e8fc0833bc18f30ea8
6
+ metadata.gz: e3aa5c463b9e60841adc238db79d1cdd45ee41ff1a0bbb9b74c241534e5c63e9a8151fd39375b889a568805480327dc28cc964c18a1e4f66c51398ec60a3b925
7
+ data.tar.gz: 7fd9256e2820fed70aa533cc558cc2d7131eeb49de76d7d71120297207c3ce1ed61ef1e2fc4d5a3e39cbc0d3ba81db2bcfbaa02bb35684b93b373f6935ca3138
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.1.0]
7
+ - standardize filter to be first argument
8
+
6
9
  ## [1.0.0]
7
10
  - sonic ecs-exec
8
11
  - sonic ecs-run
data/README.md CHANGED
@@ -4,7 +4,7 @@ Sonic is a multi-functional tool that helps you manage AWS resources. Sonic cont
4
4
 
5
5
  ## Why Sonic Was Created
6
6
 
7
- After I exhaust debugging an ECS service with CloudWatch Logs I usually take it to the the next step: ssh into the instance. I jump into an instance with a running task or docker container and poke around to figure out the root issue.
7
+ After I exhaust debugging an ECS service with CloudWatch Logs I usually take it to the next step: ssh into the instance. I jump into an instance with a running task or docker container and poke around to figure out the root issue.
8
8
 
9
9
  In order to find the instance with the service's docker container I click around on the ECS console website until I find the container instance's DNS name and then paste it to the terminal. While this process is not complicated, it is tedious. For example, the typical process is:
10
10
 
@@ -0,0 +1,21 @@
1
+ ---
2
+ title: Help
3
+ ---
4
+
5
+ You can run help for quick help information right at the cli. Example:
6
+
7
+ ```sh
8
+ sonic help
9
+ ```
10
+
11
+ You can append `help`, `-h` or `--help` to the end of any command to get more help information about that specific command. These all work.
12
+
13
+ ```sh
14
+ sonic ssh help
15
+ sonic ecs-exec --help
16
+ sonic execute -h
17
+ ```
18
+
19
+ <a id="prev" class="btn btn-basic" href="{% link _docs/settings.md %}">Back</a>
20
+ <a id="next" class="btn btn-primary" href="{% link _docs/why.md %}">Next Step</a>
21
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -4,7 +4,7 @@ title: How It Works
4
4
 
5
5
  ### Internals
6
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.
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. Here's an overview of what actually happens internally for those who are interested.
8
8
 
9
9
  Steps:
10
10
 
@@ -17,9 +17,9 @@ Steps:
17
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
18
  8. Run docker command
19
19
  1. docker exec -ti CONTAINER_ID `options[:command]`
20
- 2. docker run `options[:run_options]` IMAGE `options[:command]`
20
+ 2. docker run -ti IMAGE `options[:command]`
21
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:
22
+ In order to pass info over from your local machine to the container instance a file is generated and copied in step 5. The file contains:
23
23
 
24
24
  * Options all the way from the original cli call like command to run. This is in json form.
25
25
  A bash script is also copied.
@@ -29,6 +29,6 @@ A bash script is also copied.
29
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
30
 
31
31
 
32
- <a id="prev" class="btn btn-basic" href="{% link _docs/why.md %}">Back</a>
32
+ <a id="prev" class="btn btn-basic" href="{% link _docs/why-ec2-run-command.md %}">Back</a>
33
33
  <a id="next" class="btn btn-primary" href="{% link _docs/next-steps.md %}">Next Step</a>
34
34
  <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,35 @@
1
+ ---
2
+ title: Bastion Setup
3
+ ---
4
+
5
+ It is common to secure your network setup by restricting access to your servers by placing them in internal subnets. In this case you will have a bastion host server that you must use to jump through to get to your instance. Sonic provides built-in support for a bastion host.
6
+
7
+ You can configure the [settings.yml]({% link _docs/settings.md %}) file to use a bastion host. Here's an example:
8
+
9
+ ```yaml
10
+ bastion: bastion.mydomain.com
11
+ ```
12
+
13
+ This directs the `sonic ssh` to jump through the bastion host. This works completely transparently. The sonic commands are exactly the same as if there is no bastion host.
14
+
15
+ ```
16
+ sonic ssh i-0f7f833131a51ce35
17
+ ```
18
+
19
+ You should notice that the built up command now includes the bastion jump host.
20
+
21
+ ```
22
+ $ sonic ssh i-0f7f833131a51ce35 uptime
23
+ => ssh -At ec2-user@34.211.223.3 ssh ec2-user@10.10.110.135 uptime
24
+ Warning: Permanently added '34.211.223.3' (ECDSA) to the list of known hosts.
25
+ Warning: Permanently added '10.10.110.135' (ECDSA) to the list of known hosts.
26
+ 18:35:18 up 1:14, 0 users, load average: 0.24, 0.07, 0.02
27
+ Connection to 34.211.223.3 closed.
28
+ $
29
+ ```
30
+
31
+ You can also specify the bastion host as a CLI option with `--bastion`, though it is recommended that you configure it in a `settings.yml` file so you do not have to repeatedly type it.
32
+
33
+ <a id="prev" class="btn btn-basic" href="{% link _docs/install.md %}">Back</a>
34
+ <a id="next" class="btn btn-primary" href="{% link _docs/tutorial.md %}">Next Step</a>
35
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -30,23 +30,29 @@ gem "sonic-screwdriver"
30
30
 
31
31
  #### sonic ecs-* dependencies
32
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.
33
+ In order for the `sonic ecs-*` commands to work `jq` is required on the server side. This is covered in the [How It Works]({% link _docs/how-it-works.md %}) section.
34
34
 
35
35
  One way to install `jq` quickly is by using the `sonic execute` command. For example:
36
36
 
37
37
  ```sh
38
- sonic execute -f hi-web-stag yum install -y jq
38
+ sonic execute hi-web-stag yum install -y jq
39
39
  ```
40
40
 
41
41
  It is recommended that you install `jq` with the UserData script or bake it into the AMI though.
42
42
 
43
43
  #### sonic execute dependencies
44
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.
45
+ The `sonic execute` works alongside [Amazon EC2 Run Command](https://aws.amazon.com/ec2/execute/). So it is required to be installed on the servers for `sonic execute` to work.
46
46
 
47
47
  #### Amazon EC2 Run Manager Installation
48
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.
49
+ Installing the EC2 Run Manager agent on your linux servers is super simple and is only one command.
50
+
51
+ ```sh
52
+ sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
53
+ ```
54
+
55
+ The full recommended instructions are on the offical Amazon EC2 Systems Manager [Install SSM Agent](http://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html) documentation.
50
56
 
51
57
  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
58
 
@@ -58,7 +64,7 @@ You can verify the instances that have successfully checked into SSM with `aws s
58
64
  aws ssm describe-instance-information --output text --query "InstanceInformationList[*]"
59
65
  ```
60
66
 
61
- Here's an exmaple of the output:
67
+ Here's an example of the output:
62
68
 
63
69
  ```sh
64
70
  $ aws ssm describe-instance-information --output text --query "InstanceInformationList[*]"
@@ -70,6 +76,6 @@ $
70
76
  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
77
 
72
78
  <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>
79
+ <a id="next" class="btn btn-primary" href="{% link _docs/install-bastion.md %}">Next Step</a>
74
80
  <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
75
81
 
@@ -2,7 +2,7 @@
2
2
  title: Settings
3
3
  ---
4
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:
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 all get loaded and merged. The options from the files follow the following precedence rules:
6
6
 
7
7
  1. project - The project's `.sonic/settings.yml` values take the highest precedence.
8
8
  2. user - The user's `~/.sonic/settings.yml` values take the second highest precedence.
@@ -33,11 +33,11 @@ host_key_check | Controls whether or not use the strict host checking ssh optio
33
33
  service_cluster | Service to cluster mapping. This is a Hash structure that maps the service name to cluster names. | (no value)
34
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
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).
36
+ The default settings are located tool source code at [lib/sonic/default/settings.yml](https://github.com/boltopslabs/sonic/blob/master/lib/sonic/default/settings.yml).
37
37
 
38
38
  ### Service to Cluster Mapping
39
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`:
40
+ One of the useful options is the `service_cluster`. 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
41
 
42
42
  ```yaml
43
43
  user: ec2-user
@@ -69,5 +69,5 @@ sonic ssh hi-worker-stag --cluster stag
69
69
 
70
70
 
71
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>
72
+ <a id="next" class="btn btn-primary" href="{% link _docs/help.md %}">Next Step</a>
73
73
  <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -2,11 +2,11 @@
2
2
  title: ECS Exec
3
3
  ---
4
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.
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 ECS smart.
6
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`.
7
+ One of the additional 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
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.
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 go through examples of how sonic can help you get into an running ECS docker container quickly.
10
10
 
11
11
  ### sonic ecs-exec
12
12
 
@@ -31,7 +31,7 @@ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
31
31
  root@fc4035f90bdc:/app#
32
32
  ```
33
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 🎉
34
+ What you see in the last line above is a bash prompt because you are in a bash shell within the docker container! With one command you have placed yourself into the running container 🎉
35
35
 
36
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
37
 
@@ -2,7 +2,7 @@
2
2
  title: ECS Run
3
3
  ---
4
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.
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
6
 
7
7
  ### sonic ecs-run
8
8
 
@@ -35,7 +35,7 @@ Connection to 34.211.195.71 closed.
35
35
  $
36
36
  ```
37
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.
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 to start shell for debugging. To start a bash shell just tack the bash command at the end.
39
39
 
40
40
  ```sh
41
41
  $ sonic ecs-run hi-web-stag bash
@@ -46,7 +46,7 @@ Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
46
46
  root@56a495dbd5cd:/app#
47
47
  ```
48
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.
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 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.
50
50
 
51
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
52
 
@@ -61,7 +61,7 @@ bf646ae7789a amazon/amazon-ecs-agent:latest "/agent"
61
61
  $
62
62
  ```
63
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`
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`. This is how we know that this is a container outside of ECS control.
65
65
 
66
66
  ```sh
67
67
  $ sonic ecs-run hi-web-stag bash
@@ -75,7 +75,7 @@ Connection to 34.211.195.71 closed.
75
75
  $
76
76
  ```
77
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.
78
+ Let's exit out of the first terminal where you ran the original `sonic ecs-run` command and then list the running containers again.
79
79
 
80
80
  ```sh
81
81
  $ sonic ssh hi-web-stag docker ps
@@ -87,7 +87,7 @@ bf646ae7789a amazon/amazon-ecs-agent:latest "/agent"
87
87
  $
88
88
  ```
89
89
 
90
- Zapped! The container that was created with `sonic ecs-run` is no more.
90
+ Zapped! The `cocky_goldstine` container that was created with `sonic ecs-run` is no more.
91
91
 
92
92
  <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-exec.md %}">Back</a>
93
93
  <a id="next" class="btn btn-primary" href="{% link _docs/tutorial-execute.md %}">Next Step</a>
@@ -2,36 +2,50 @@
2
2
  title: Sonic Execute
3
3
  ---
4
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:
5
+ ### Run One Liners
6
+
7
+ Sonic provides a way to execute commands remotely and securely across a list of AWS servers. It does this by leveraging [Amazon EC2 Run Command](https://aws.amazon.com/ec2/execute/). Sonic hides any complexity and provides a simple interface for you. Example:
6
8
 
7
9
  ```sh
8
- sonic execute --filter hi-web-stag "uptime"
10
+ sonic execute hi-web-stag uptime
9
11
  ```
10
12
 
11
13
  Let's do something more useful:
12
14
 
13
15
  ```sh
14
- sonic execute --filter hi-web-stag "yum install -y curl"
16
+ sonic execute hi-web-stag yum install -y curl
15
17
  ```
16
18
 
17
- The output of the commands ran are showed in the EC2 Run Command Console. Here's an example:
19
+ The output of the command will show a useful `aws ssm list-commands` command to get status of the requested command.
18
20
 
19
21
  ```
20
- $ sonic execute --filter hi-web-stag uptime
22
+ $ sonic execute hi-web-stag uptime
21
23
  Command sent to AWS SSM. To check the details of the command:
22
24
  aws ssm list-commands --command-id 4133e5eb-aa18-40dd-be25-a176eb15e515
23
25
  Pro tip: the aws ssm command is already in your copy/paste clipboard.
24
26
  $
25
27
  ```
26
28
 
27
- ### Why Amazon EC2 Run Command
29
+ The output of the commands ran are also showed in the EC2 Run Command Console. Here's an example:
30
+
31
+ <img src="/img/tutorials/ec2-console-run-command.png" class="doc-photo" />
32
+
33
+ ### Run Scripts
28
34
 
29
- Why use Amazon EC2 Run Command vs just using a multi-ssh session?
35
+ Sometimes you might want to run more than just a one-liner command. If you need to run a full script, you can provide the file path to the script by designating it with `file://`. For example, here's a file called `hi.sh`:
36
+
37
+ ```bash
38
+ #!/bin/bash
39
+ echo "hello world"
40
+ ```
41
+
42
+ Here's how you run that file:
43
+
44
+ ```sh
45
+ sonic execute hi-web-stag file://hi.sh
46
+ ```
30
47
 
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.
48
+ The file gets read by `sonic execute` and sent to EC2 Run Command to be executed.
35
49
 
36
50
  <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-run.md %}">Back</a>
37
51
  <a id="next" class="btn btn-primary" href="{% link _docs/settings.md %}">Next Step</a>
@@ -6,7 +6,7 @@ title: SSH
6
6
 
7
7
  Sonic allows you to quickly ssh into an instance.
8
8
 
9
- When working with AWS EC2 often times it is helpful ssh into the instance to debug. In order to ssh into the instance the first thing you do is go to the EC2 Console and grab the public ip address.
9
+ Often times when working with AWS EC2 it is helpful to ssh into an instance to debug. In order to ssh into an instance the first thing you do is go to the EC2 Console and grab the public ip address.
10
10
 
11
11
  <img src="/img/tutorials/ec2-console-public-ip.png" class="doc-photo" />
12
12
 
@@ -16,11 +16,11 @@ You use that ip address to build up an ssh command for accessing the instance.
16
16
  ssh ec2-user@52.24.216.170
17
17
  ```
18
18
 
19
- You often have to go through this manual process of identifying the public ip address and building up the ssh command.
19
+ You often have to go through this manual process of identifying the public ip address and building up the ssh command repeatedly.
20
20
 
21
21
  ### Usage
22
22
 
23
- Sonic will automatically build up the ssh command for you. Here's an example of the concise sonic ssh command.
23
+ Sonic automatically builds up the ssh command for you. Here's an example of the sonic ssh command.
24
24
 
25
25
  ```sh
26
26
  sonic ssh i-027363802c6ff314f
@@ -32,27 +32,30 @@ The above command effectively translate to:
32
32
  ssh ec2-user@52.24.216.170
33
33
  ```
34
34
 
35
- By default the user that sonic uses to login to the server is `ec2-user`. This can easily be overriden at the CLI:
35
+ By default the user that sonic uses to login to the server is `ec2-user`. This can easily be overriden:
36
36
 
37
37
  ```sh
38
38
  sonic ssh ubuntu@i-0f7f833131a51ce35
39
39
  ```
40
40
 
41
- The user can also be configure with a `~/.sonic/settings.yml` or the project's `.sonic/settings.yml` file like so:
41
+ The default user can also be configure with a `~/.sonic/settings.yml` or the project's `.sonic/settings.yml` file like so:
42
42
 
43
43
  ```yaml
44
44
  user: ec2-user
45
45
  ```
46
46
 
47
- The `sonic ssh` command can auto-detect the proper ip address with a variety of different identifiers; it is not just limited to the instance id. This is convenient if you happen to be on a dashboard with another identifer handy. Here are examples of other identifiers that `sonic ssh` understands.
47
+ More information about sonic settings in available in the docs: [Settings]({% link _docs/settings.md %}).
48
+
49
+ The `sonic ssh` command can auto-detect the proper ip address with a variety of different identifiers. It is not just limited to the instance id. This is convenient in case you happen to be on a dashboard with another identifer close by and handy. Here are examples of other identifiers that `sonic ssh` understands.
48
50
 
49
51
  ```
52
+ sonic ssh EC2_TAG_FILTER
50
53
  sonic ssh ECS_CONTAINER_ID --cluster stag
51
54
  sonic ssh ECS_SERVICE --cluster stag
52
55
  sonic ssh ECS_TASK_ID --cluster stag
53
56
  ```
54
57
 
55
- Notice, that when the `sonic ssh` is passed an ECS identifier then it also requires the ECS cluster name. The commands above with the ECS identifier are normally shorten further by configuring the `~/.sonic/settings.yml` or the project's `.sonic/settings.yml` file. Here's an example:
58
+ Notice, that when the `sonic ssh` is passed an ECS identifier then it also requires the ECS cluster name. The commands above with the ECS identifier are normally shorten further by configuring the a [settings]({% link _docs/settings.md %}) file. Here's an example:
56
59
 
57
60
  ```yaml
58
61
  service_cluster:
@@ -74,7 +77,7 @@ sonic ssh ECS_SERVICE
74
77
  sonic ssh ECS_TASK_ID
75
78
  ```
76
79
 
77
- It becomes very easy to ssh into an EC2 Container Instance with the ECS service name. For example if the ECS service name is `hi-web-stag`.
80
+ It then becomes very easy to ssh into an EC2 Container Instance with the ECS service name. For example if the ECS service name is `hi-web-stag` then the command becomes.
78
81
 
79
82
  ```sh
80
83
  sonic ssh hi-web-stag
@@ -82,37 +85,10 @@ sonic ssh hi-web-stag
82
85
 
83
86
  ### Bastion Host
84
87
 
85
- If you have an bastion host server which provides access to your internal servers then it is even more work to build up the ssh command. The good news is that `sonic ssh` command also automates this!
86
-
87
- Thus far we have assumed that the instances we are hopping into are publicly available on a public subnet and have an public ip address associate with it. A common AWS setup is to have your servers on internal subnets without public addresses. In this case we must first ssh into the bastion host and from there you can "jump" to the actually server. This why the bastion host is also called a jump host.
88
-
89
- You can configure the `settings.yml` file again to use a bastion host. Here's an example:
90
-
91
- ```yaml
92
- bastion: bastion.mydomain.com
93
- ```
94
-
95
- You run the `sonic ssh` command exactly the same way:
96
-
97
- ```
98
- sonic ssh i-0f7f833131a51ce35
99
- ```
100
-
101
- You should notice that the built up command now includes the bastion jump host.
102
-
103
- ```
104
- $ sonic ssh i-0f7f833131a51ce35 uptime
105
- => ssh -At ec2-user@34.211.223.3 ssh ec2-user@10.10.110.135 uptime
106
- Warning: Permanently added '34.211.223.3' (ECDSA) to the list of known hosts.
107
- Warning: Permanently added '10.10.110.135' (ECDSA) to the list of known hosts.
108
- 18:35:18 up 1:14, 0 users, load average: 0.24, 0.07, 0.02
109
- Connection to 34.211.223.3 closed.
110
- $
111
- ```
88
+ Thus far we have assumed that the instances we are hopping into are publicly available on a public subnet and have an public ip address associate with it. A common AWS setup is to have your servers on internal subnets without public addresses. In this case we must first ssh into the bastion host and from there we can "jump" into the actually server. This why the bastion host is also called a jump host.
112
89
 
113
- Notice that the ssh command produced has the bastion jump host daisy chained in the command for you.
90
+ If you have an bastion host server which provides access to your internal servers then it is even more work to build up the ssh command. The good news is that the `sonic ssh` command supports bastion hosts and automates this process! The [Bastion Setup]({% link _docs/install-bastion.md %}) doc covers how to set this up.
114
91
 
115
- You can also specify the bastion host as a CLI option with `--bastion`, though it is recommended that you configure it in a `settings.yml` file so you don't have to type it repeatedly.
116
92
 
117
93
  <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial.md %}">Back</a>
118
94
  <a id="next" class="btn btn-primary" href="{% link _docs/tutorial-ecs-exec.md %}">Next Step</a>
@@ -2,10 +2,10 @@
2
2
  title: Tutorial
3
3
  ---
4
4
 
5
- In the next sections, we'll walk through using sonic in detail. It turns out that easiest way to actually explain the different uses of sonic is to actually use it.
5
+ In the next sections, we'll walk through using sonic in detail. The easiest way to learn and understand sonic is to actually use it.
6
6
 
7
7
  Let's start!
8
8
 
9
- <a id="prev" class="btn btn-basic" href="{% link _docs/install.md %}">Back</a>
9
+ <a id="prev" class="btn btn-basic" href="{% link _docs/install-bastion.md %}">Back</a>
10
10
  <a id="next" class="btn btn-primary" href="{% link _docs/tutorial-ssh.md %}">Next Step</a>
11
11
  <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -0,0 +1,16 @@
1
+ ---
2
+ title: Why Use EC2 Run Command
3
+ ---
4
+
5
+ Why use Amazon EC2 Run Command vs just using a multi-ssh session?
6
+
7
+ * 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.
8
+ * EC2 Run Command provides auditability. Any command that runs the EC2 Run Command gets logged and is tracked.
9
+ * 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.
10
+ * This is all provided for free by using EC2 Run Manager.
11
+
12
+ The iniitial ertia of setting up EC2 Run Manager is actually very little. The [installation instructions]({% link _docs/install.md %}) demonstrate that installing EC2 Run Manager is literally one command.
13
+
14
+ <a id="prev" class="btn btn-basic" href="{% link _docs/why.md %}">Back</a>
15
+ <a id="next" class="btn btn-primary" href="{% link _docs/how-it-works.md %}">Next Step</a>
16
+ <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
data/docs/_docs/why.md CHANGED
@@ -2,7 +2,7 @@
2
2
  title: Why Sonic Was Created
3
3
  ---
4
4
 
5
- After I exhaust debugging an ECS service with CloudWatch Logs I usually take it to the the next step: ssh into the instance. I jump into an instance with a running task or docker container and poke around to figure out the root issue.
5
+ After I exhaust debugging an ECS service with CloudWatch Logs I usually take it to the next step: ssh into the instance. I jump into an instance with a running task or docker container and poke around to figure out the root issue.
6
6
 
7
7
  In order to find the instance with the service's docker container I click around on the ECS console website until I find the container instance's DNS name and then paste it to the terminal. While this process is not complicated, it is tedious. For example, the typical process is:
8
8
 
@@ -22,6 +22,6 @@ By the time I get into the container, I need to remind my brain on what the orig
22
22
 
23
23
  Sonic was created to eliminate mundane infrastructure debugging tasks we normally have to do.
24
24
 
25
- <a id="prev" class="btn btn-basic" href="{% link _docs/settings.md %}">Back</a>
26
- <a id="next" class="btn btn-primary" href="{% link _docs/how-it-works.md %}">Next Step</a>
25
+ <a id="prev" class="btn btn-basic" href="{% link _docs/help.md %}">Back</a>
26
+ <a id="next" class="btn btn-primary" href="{% link _docs/why-ec2-run-command.md %}">Next Step</a>
27
27
  <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -12,7 +12,7 @@
12
12
  <p>Sonic Screwdriver is a multi-functional tool to manage AWS infrastructure. It's a swiss army knife type of tool and has a variety of uses. Mainly it's focus is to automate mundane repetitive tasks into simple one line commands. With it you are able to debug environments and issues quickly.</p>
13
13
  </div>
14
14
  <div class="col-lg-4">
15
- <p>The command that Sonic Screwdriver provides is called <code>sonic</code>. One thing you can use it it for is to quickly ssh into an instance provided an identifer. Another use for sonic is to ssh into the instance and run <code>docker exec</code> immediately to the container of interested. Sonic helps with these boring tasks so you can focus your mental energies on solving the actual problem at hand.</p>
15
+ <p>The command that Sonic Screwdriver provides is called <code>sonic</code>. One thing you can use it it for is to quickly ssh into an instance provided an identifer. Another use for sonic is to ssh into the instance and run <code>docker exec</code> to jump immediately into the container. Sonic helps with these boring tasks so you can focus your mental energies on solving the actual problem at hand.</p>
16
16
  </div>
17
17
  </div>
18
18
  </div>
@@ -10,7 +10,7 @@
10
10
  <div class="row">
11
11
  <div class="col-lg-12 text-center">
12
12
  <div id="success"></div>
13
- <a href="{% link quick-start.md %}" class="btn btn-primary btn-xl">Quick Start</a>
13
+ <a id="next" href="{% link quick-start.md %}" class="btn btn-primary btn-xl">Quick Start</a>
14
14
  </div>
15
15
  </div>
16
16
  </div>
@@ -148,8 +148,10 @@ ul.tools li {
148
148
  margin-bottom: 15px;
149
149
  }
150
150
 
151
- table.ship-options td:first-child {
152
- white-space: nowrap;
151
+ @media(min-width:992px) {
152
+ table.ship-options td:first-child {
153
+ white-space: nowrap;
154
+ }
153
155
  }
154
156
 
155
157
  .keyboard-tip {
@@ -1,51 +1,31 @@
1
1
  table {
2
2
  width: 100%;
3
3
  background-color: #4f6879;
4
- /* margin: .5em 0;
5
- border-radius: 5px;
6
- box-shadow: 0 1px 3px rgba(0,0,0,0.3);*/
7
4
  margin-bottom: 20px;
8
5
  }
9
6
 
10
7
  thead {
11
- /* border-top-left-radius: 5px;
12
- border-top-right-radius: 5px;
13
- color: #fff;
14
- background-color: #3a3a3a;
15
- */}
8
+ }
16
9
 
17
10
  tr {
18
-
19
11
  }
20
12
 
21
13
  thead th {
22
14
  background-color: #475161;
23
15
  text-transform: uppercase;
24
16
  color: #cdcdce;
25
- /* position: relative;
26
- box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
27
- */}
17
+ }
28
18
 
29
19
  tbody {
30
- /* display: table-row-group;
31
- vertical-align: middle;
32
- border-color: inherit;
33
- */}
20
+ }
34
21
 
35
22
  tr {
36
- /* display: table-row;
37
- vertical-align: inherit;
38
- border-color: inherit;
39
- */}
23
+ }
40
24
 
41
25
  tbody td {
42
26
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
43
27
  color: #ececec;
44
- /* border-top: 1px solid rgba(0,0,0,0.1);
45
- box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
46
- background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJod…IgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
47
- background-image: -o-linear-gradient(top, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
48
- */}
28
+ }
49
29
 
50
30
  th,
51
31
  td {
@@ -4,6 +4,7 @@
4
4
  <li><a href="{% link docs.md %}">Docs</a>
5
5
  <ul>
6
6
  <li><a href="{% link _docs/install.md %}">Installation</a></li>
7
+ <li><a href="{% link _docs/install-bastion.md %}">Bastion Setup</a></li>
7
8
  </ul>
8
9
  </li>
9
10
  <li><a href="{% link _docs/tutorial.md %}">Tutorial</a>
@@ -14,22 +15,14 @@
14
15
  <li><a href="{% link _docs/tutorial-execute.md %}">Execute</a></li>
15
16
  </ul>
16
17
  </li>
17
- <!--
18
- <li><a href="{% link _docs/commands.md %}">Commands</a>
18
+ <li><a href="{% link _docs/settings.md %}">Settings</a></li>
19
+ <li><a href="{% link _docs/help.md %}">Help</a></li>
20
+ <li><a href="{% link _docs/why.md %}">Why</a>
19
21
  <ul>
20
- <li><a href="{% link _docs/sonic-ssh.md %}">sonic ssh</a></li>
21
- <li><a href="{% link _docs/sonic-ecs-exec.md %}">sonic ecs-exec</a></li>
22
- <li><a href="{% link _docs/sonic-ecs-run.md %}">sonic ecs-run</a></li>
23
- <li><a href="{% link _docs/sonic-list.md %}">sonic list</a></li>
24
- <li><a href="{% link _docs/sonic-execute.md %}">sonic execute</a></li>
25
- <li><a href="{% link _docs/sonic-help.md %}">sonic help</a></li>
22
+ <li><a href="{% link _docs/why-ec2-run-command.md %}">EC2 Run Command</a></li>
26
23
  </ul>
27
24
  </li>
28
- -->
29
- <li><a href="{% link _docs/settings.md %}">Settings</a></li>
30
- <li><a href="{% link _docs/why.md %}">Why</a></li>
31
25
  <li><a href="{% link _docs/how-it-works.md %}">How It Works</a></li>
32
26
  <li><a href="{% link _docs/next-steps.md %}">Next Steps</a></li>
33
- <!-- <li><a href="{% link articles.md %}">Articles</a></li> -->
34
27
  </ul>
35
28
  </div>
data/docs/quick-start.md CHANGED
@@ -8,7 +8,6 @@ In a hurry? No sweat! Here's a quick overview of how to use sonic.
8
8
 
9
9
  ```sh
10
10
  brew cask install boltopslabs/software/bolts
11
- git clone https:///github.com/tongueroo/hi.git
12
11
  ```
13
12
 
14
13
  ### Usage
@@ -16,18 +15,22 @@ git clone https:///github.com/tongueroo/hi.git
16
15
  ```sh
17
16
  # ssh into an instance
18
17
  sonic ssh i-0f7f833131a51ce35
18
+ sonic ssh hi-web-stag
19
19
 
20
20
  # docker exec to a running ECS docker container
21
21
  sonic ecs-exec hi-web-stag
22
22
 
23
- # docker run the same exact ECS docker container that is already running
23
+ # docker run with same environment as the ECS docker running containers
24
24
  sonic ecs-run hi-web-stag
25
25
 
26
26
  # run command on 1 instance
27
- sonic execute -f i-0f7f833131a51ce35 uptime
27
+ sonic execute i-0f7f833131a51ce35 uptime
28
28
 
29
29
  # run command on all instances tagged with hi-web-stag and worker
30
- sonic execute -f hi-web-stag,hi-worker-stag uptime
30
+ sonic execute hi-web-stag,hi-worker-stag uptime
31
+
32
+ # list ec2 instances
33
+ sonic list hi-web-stag
31
34
  ```
32
35
 
33
36
  Congratulations! You now know the basics sonic screwdriver commands.
data/lib/sonic.rb CHANGED
@@ -13,4 +13,5 @@ module Sonic
13
13
  autoload :Settings, 'sonic/settings'
14
14
  autoload :Ssh, 'sonic/ssh'
15
15
  autoload :UI, 'sonic/ui'
16
+ autoload :Checks, 'sonic/checks'
16
17
  end
@@ -0,0 +1,46 @@
1
+ module Sonic
2
+ module Checks
3
+ def check_cluster_exists!
4
+ cluster = ecs.describe_clusters(clusters: [@cluster]).clusters.first
5
+ unless cluster
6
+ UI.error "The #{@cluster.green} cluster does not exist. Are you sure you specified the right cluster?"
7
+ exit 1
8
+ end
9
+ end
10
+
11
+ def check_service_exists!
12
+ begin
13
+ resp = ecs.describe_services(services: [@service], cluster: @cluster)
14
+ rescue Aws::ECS::Errors::ClusterNotFoundException
15
+ UI.error("Unable to find ECS cluster '#{@cluster}'. Are you sure the cluster exists?")
16
+ UI.say("You can specify the cluster with --cluster or you can specify it as a setting in settings.yml.")
17
+ UI.say("More info about settings available at: http://sonic-screwdriver.cloud/docs/settings")
18
+ exit 1
19
+ end
20
+
21
+ service = resp.services.first
22
+ unless service
23
+ UI.error "The #{@service.green} service does not exist in #{@cluster.green} cluster. Are you sure you specified the right service and cluster?"
24
+ exit 1
25
+ end
26
+ end
27
+
28
+ def check_tasks_running!
29
+ if task_arns.empty?
30
+ puts "Unable to find a running task that belongs to the #{@service} service on the #{@cluster} cluster."
31
+ puts "There must be a running task in order for sonic to look up an container instance."
32
+ exit 1
33
+ end
34
+ end
35
+
36
+ def task_arns
37
+ @task_arns ||= ecs.list_tasks(cluster: @cluster, service_name: @service).task_arns
38
+ end
39
+
40
+ # Only need one container instance to ssh into so we'll just use the first.
41
+ # Useful to have this in a method for subclasses like Sonic::Exec.
42
+ def first_task
43
+ @first_task ||= ecs.describe_tasks(cluster: @cluster, tasks: [task_arns.first]).tasks.first
44
+ end
45
+ end
46
+ end
data/lib/sonic/cli.rb CHANGED
@@ -9,12 +9,14 @@ module Sonic
9
9
  class_option :bastion, desc: "Bastion jump host to use. Defaults to no bastion server."
10
10
  class_option :project_root, desc: "Project root. Useful for testing.", hide: true
11
11
 
12
- desc "ssh [IDENTIFER]", "ssh into a instance using identifier. identifer can be be service name or instance id"
12
+ stop_on_unknown_option! :ssh
13
+ desc "ssh [IDENTIFER]", "ssh into a instance using identifier. identifer can be several things: instance id, ec2 tag, ECS service name, etc"
13
14
  long_desc Help.ssh
14
- def ssh(service, *command)
15
- Ssh.new(service, options.merge(command: command)).run
15
+ def ssh(identifier, *command)
16
+ Ssh.new(identifier, options.merge(command: command)).run
16
17
  end
17
18
 
19
+ stop_on_unknown_option! :ecs_exec
18
20
  desc "ecs-exec [ECS_SERVICE]", "docker exec into running docker container associated with the service on a container instance"
19
21
  long_desc Help.ecs_exec
20
22
  def ecs_exec(service, *command)
@@ -22,6 +24,7 @@ module Sonic
22
24
  end
23
25
 
24
26
  # Cannot name the command run because that is a reserved Thor keyword :(
27
+ stop_on_unknown_option! :ecs_run
25
28
  desc "ecs-run [ECS_SERVICE]", "docker run with the service on a container instance"
26
29
  long_desc Help.ecs_run
27
30
  def ecs_run(service, *command)
@@ -29,20 +32,19 @@ module Sonic
29
32
  end
30
33
 
31
34
  stop_on_unknown_option! :execute
32
- check_unknown_options! :except => :execute
33
- desc "execute [COMMAND]", "runs command across fleet of servers via AWS Run Command"
35
+ desc "execute [FILTER] [COMMAND]", "runs command across fleet of servers via AWS Run Command"
34
36
  long_desc Help.execute
35
- option :filter, aliases: '-f', type: :string, required: true, desc: "Filter ec2 instances by tag name or instance_ids separated by commas"
36
- def execute(*command)
37
- Execute.new(command, options).execute
37
+ # filter - Filter ec2 instances by tag name or instance_ids separated by commas
38
+ def execute(filter, *command)
39
+ Execute.new(command, options.merge(filter: filter)).execute
38
40
  end
39
41
 
40
- desc "list", "lists ec2 instances"
42
+ desc "list [FILTER]", "lists ec2 instances"
41
43
  long_desc Help.list
42
44
  option :header, type: :boolean, desc: "Displays header"
43
- option :filter, aliases: '-f', type: :string, desc: "Filter ec2 instances by tag name or instance_ids separated by commas"
44
- def list
45
- List.new(options).run
45
+ # filter - Filter ec2 instances by tag name or instance_ids separated by commas
46
+ def list(filter)
47
+ List.new(options.merge(filter: filter)).run
46
48
  end
47
49
  end
48
50
  end
@@ -94,13 +94,14 @@ EOL
94
94
 
95
95
  def execute
96
96
  <<-EOL
97
- 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. sonic execute will auto-detect the what type of filter it is and send it properly to EC2 Run Command.
97
+ 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.
98
98
 
99
99
  Examples:
100
100
 
101
- $ sonic execute --filter hi-web-prod uptime
102
- $ sonic execute --filter hi-web-prod,hi-worker-prod,hi-clock-prod uptime
103
- $ sonic execute --filter i-030033c20c54bf149,i-030033c20c54bf150 uname -a
101
+ $ sonic execute hi-web-prod uptime
102
+ $ sonic execute hi-web-prod,hi-worker-prod,hi-clock-prod uptime
103
+ $ sonic execute i-030033c20c54bf149,i-030033c20c54bf150 uname -a
104
+ $ sonic execute i-030033c20c54bf149 file://hello.sh
104
105
 
105
106
  You cannot mix instance ids and tag names in the filter.
106
107
  EOL
@@ -113,13 +114,13 @@ List ec2 servers. A filter must be provided. The filter can be a mix of instanc
113
114
  Examples:
114
115
 
115
116
  $ sonic list
116
- $ sonic list --filter hi-web-prod
117
- $ sonic list --filter hi-web-prod,hi-clock-prod
118
- $ sonic list --filter i-09482b1a6e330fbf7
117
+ $ sonic list hi-web-prod
118
+ $ sonic list hi-web-prod,hi-clock-prod
119
+ $ sonic list i-09482b1a6e330fbf7
119
120
 
120
121
  Example Output:
121
122
 
122
- $ sonic list --filter i-09482b1a6e330fbf7 --header
123
+ $ sonic list i-09482b1a6e330fbf7 --header
123
124
  Instance Id Public IP Private IP Type
124
125
  i-09482b1a6e330fbf7 54.202.152.168 172.31.21.108 t2.small
125
126
  $
data/lib/sonic/docker.rb CHANGED
@@ -2,6 +2,8 @@ require 'fileutils'
2
2
 
3
3
  module Sonic
4
4
  class Docker < Ssh
5
+ include Checks
6
+
5
7
  def exec
6
8
  call("/tmp/sonic/bash_scripts/docker-exec.sh")
7
9
  end
@@ -88,7 +90,7 @@ module Sonic
88
90
  # * image
89
91
  def create_container_data
90
92
  # For container env_vars and image info.
91
- task_definition_arn = task.task_definition_arn # task is a method in the superclass: Ssh
93
+ task_definition_arn = first_task.task_definition_arn # task is a method in the superclass: Ssh
92
94
  response = ecs.describe_task_definition(task_definition: task_definition_arn)
93
95
  task_definition = response.to_h[:task_definition]
94
96
  container_definition = task_definition[:container_definitions].first # assumes care about the first container definition
data/lib/sonic/list.rb CHANGED
@@ -8,17 +8,27 @@ module Sonic
8
8
  end
9
9
 
10
10
  def run
11
- options = transform_filter_option(@filter)
11
+ filter_options = transform_filter_option(@filter)
12
12
  if @options[:noop]
13
13
  instances = []
14
14
  else
15
- instances = ec2_resource.instances(options)
15
+ begin
16
+ instances = ec2_resource.instances(filter_options)
17
+ instances.count # force eager loading
18
+ rescue Aws::EC2::Errors::InvalidInstanceIDNotFound => e
19
+ # ERROR: The instance ID 'i-066b140d9479e9682' does not exist
20
+ UI.error(e.message)
21
+ exit 1
22
+ end
16
23
  end
17
24
  display(instances)
18
25
  end
19
26
 
20
27
  def display(instances)
21
- if @options[:header]
28
+ zero_instances = instances.count == 0
29
+ UI.say("No instances found with the filter #{@filter.join('')}") if zero_instances
30
+
31
+ if @options[:header] && !zero_instances
22
32
  UI.say "Instance Id\tPublic IP\tPrivate IP\tType".colorize(:green)
23
33
  end
24
34
 
data/lib/sonic/ssh.rb CHANGED
@@ -104,7 +104,7 @@ private
104
104
  # -t = Force pseudo-terminal allocati
105
105
  def build_ssh_command
106
106
  ssh = ["ssh"] + ssh_options
107
- ssh += ["-At", bastion_host, "ssh"] if @bastion
107
+ ssh += ["-At", bastion_host, "ssh"] + ssh_options if @bastion
108
108
  # ssh_host is internal ip when bastion is set
109
109
  # ssh_host is public ip when bastion is not set
110
110
  ssh += ["-At", ssh_host]
@@ -5,6 +5,7 @@ class Ssh
5
5
 
6
6
  include Ec2Tag
7
7
  include AwsServices
8
+ include Checks
8
9
 
9
10
  def initialize(cluster, service, identifier, options)
10
11
  @cluster = cluster
@@ -27,7 +28,7 @@ class Ssh
27
28
  check_service_exists!
28
29
  check_tasks_running!
29
30
 
30
- find_container_instance(task.container_instance_arn)
31
+ find_container_instance(first_task.container_instance_arn)
31
32
  when :ec2_tag
32
33
  find_ec2_instance
33
34
  when :ec2_instance
@@ -72,53 +73,9 @@ class Ssh
72
73
  exit 1
73
74
  end
74
75
 
75
- find_container_instance(task.container_instance_arn)
76
+ find_container_instance(first_task.container_instance_arn)
76
77
  end
77
78
 
78
- def check_cluster_exists!
79
- cluster = ecs.describe_clusters(clusters: [@cluster]).clusters.first
80
- unless cluster
81
- UI.error "The #{@cluster.green} cluster does not exist. Are you sure you specified the right cluster?"
82
- exit 1
83
- end
84
- end
85
-
86
- def check_service_exists!
87
- begin
88
- resp = ecs.describe_services(services: [@service], cluster: @cluster)
89
- rescue Aws::ECS::Errors::ClusterNotFoundException
90
- UI.error("Unable to find ECS cluster '#{@cluster}'. Are you sure the cluster exists?")
91
- UI.say("You can specify the cluster with --cluster or you can specify it as a setting in settings.yml.")
92
- UI.say("More info about settings available at: http://sonic-screwdriver.cloud/docs/settings")
93
- exit 1
94
- end
95
-
96
- service = resp.services.first
97
- unless service
98
- UI.error "The #{@service.green} service does not exist in #{@cluster.green} cluster. Are you sure you specified the right service and cluster?"
99
- exit 1
100
- end
101
- end
102
-
103
- def check_tasks_running!
104
- if task_arns.empty?
105
- puts "Unable to find a running task that belongs to the #{@service} service on the #{@cluster} cluster."
106
- puts "There must be a running task in order for sonic to look up an container instance."
107
- exit 1
108
- end
109
- end
110
-
111
- def task_arns
112
- @task_arns ||= ecs.list_tasks(cluster: @cluster, service_name: @service).task_arns
113
- end
114
-
115
- # Only need one container instance to ssh into so we'll just use the first.
116
- # Useful to have this in a method for subclasses like Sonic::Exec.
117
- def task
118
- @task ||= ecs.describe_tasks(cluster: @cluster, tasks: [task_arns.first]).tasks.first
119
- end
120
-
121
-
122
79
  # Examples:
123
80
  #
124
81
  # Container instance ids:
data/lib/sonic/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sonic
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/spec/lib/cli_spec.rb CHANGED
@@ -17,12 +17,12 @@ describe Sonic::CLI do
17
17
  end
18
18
 
19
19
  it "execute should print that command has been sent" do
20
- out = execute("bin/sonic execute #{@args} --filter 1,2,3 uptime")
20
+ out = execute("bin/sonic execute #{@args} 1,2,3 uptime")
21
21
  expect(out).to include("Command sent")
22
22
  end
23
23
 
24
24
  it "list should list running instances" do
25
- out = execute("bin/sonic list #{@args} --filter 1,2,3 --header")
25
+ out = execute("bin/sonic list #{@args} 1,2,3 --header")
26
26
  expect(out).to include("Instance Id")
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonic-screwdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-19 00:00:00.000000000 Z
11
+ date: 2017-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -174,22 +174,18 @@ files:
174
174
  - docs/LICENSE
175
175
  - docs/README.md
176
176
  - docs/_config.yml
177
- - docs/_docs/commands.md
177
+ - docs/_docs/help.md
178
178
  - docs/_docs/how-it-works.md
179
+ - docs/_docs/install-bastion.md
179
180
  - docs/_docs/install.md
180
181
  - docs/_docs/next-steps.md
181
182
  - docs/_docs/settings.md
182
- - docs/_docs/sonic-ecs-exec.md
183
- - docs/_docs/sonic-ecs-run.md
184
- - docs/_docs/sonic-execute.md
185
- - docs/_docs/sonic-help.md
186
- - docs/_docs/sonic-list.md
187
- - docs/_docs/sonic-ssh.md
188
183
  - docs/_docs/tutorial-ecs-exec.md
189
184
  - docs/_docs/tutorial-ecs-run.md
190
185
  - docs/_docs/tutorial-execute.md
191
186
  - docs/_docs/tutorial-ssh.md
192
187
  - docs/_docs/tutorial.md
188
+ - docs/_docs/why-ec2-run-command.md
193
189
  - docs/_docs/why.md
194
190
  - docs/_includes/about.html
195
191
  - docs/_includes/commands.html
@@ -232,6 +228,7 @@ files:
232
228
  - docs/img/logos/boltops-logo.png
233
229
  - docs/img/sonic-screwdriver.jpg
234
230
  - docs/img/tutorials/ec2-console-public-ip.png
231
+ - docs/img/tutorials/ec2-console-run-command.png
235
232
  - docs/img/ufo.jpg
236
233
  - docs/index.html
237
234
  - docs/js/bootstrap.js
@@ -252,6 +249,7 @@ files:
252
249
  - lib/bash_scripts/docker-run.sh
253
250
  - lib/sonic.rb
254
251
  - lib/sonic/aws_services.rb
252
+ - lib/sonic/checks.rb
255
253
  - lib/sonic/cli.rb
256
254
  - lib/sonic/cli/help.rb
257
255
  - lib/sonic/command.rb
@@ -1,10 +0,0 @@
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
-
@@ -1,7 +0,0 @@
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>
@@ -1,7 +0,0 @@
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>
@@ -1,7 +0,0 @@
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>
@@ -1,7 +0,0 @@
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>
@@ -1,7 +0,0 @@
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>
@@ -1,7 +0,0 @@
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>