sonic-screwdriver 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +27 -128
- data/docs/_docs/install.md +1 -1
- data/docs/_docs/tutorial-ecs-exec.md +30 -2
- data/docs/_docs/tutorial-ecs-run.md +1 -1
- data/docs/_docs/tutorial-execute.md +7 -1
- data/docs/_docs/tutorial-ssh.md +16 -3
- data/lib/sonic/cli/help.rb +6 -6
- data/lib/sonic/ssh.rb +2 -0
- data/lib/sonic/version.rb +1 -1
- data/spec/lib/cli_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fcf3cedf767fb24e46f926676e90e6665a16b7e
|
4
|
+
data.tar.gz: 61a4e4f685b0ebff993ade25c55d0c790f440d2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c990f11c3d1bd7f6ddf3d2ed1d2f4156c7dde78601e3964d28e73fe9eff41f0f70d5280910793d9250e78eefef16a46d39e1f544d64d3b1a8d0bd913e480df
|
7
|
+
data.tar.gz: 896df9f8754358469a65376534b564950314e751a3a1c21634c30d0e640f789a295854d46233fd661e2b54735b8a939cfd341772deccfea0e66022f2c4c9a6b9
|
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.1]
|
7
|
+
- update docs and help
|
8
|
+
|
6
9
|
## [1.1.0]
|
7
10
|
- standardize filter to be first argument
|
8
11
|
|
data/README.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# Sonic
|
2
2
|
|
3
|
+
[![CircleCI](https://circleci.com/gh/boltopslabs/sonic.svg?style=svg)](https://circleci.com/gh/boltopslabs/sonic)
|
4
|
+
|
3
5
|
Sonic is a multi-functional tool that helps you manage AWS resources. Sonic contains is a group of commands that help debug EC2 instances and ECS containers quickly.
|
4
6
|
|
7
|
+
See [sonic-screwdriver.cloud](http://sonic-screwdriver.cloud) for full documentation.
|
8
|
+
|
5
9
|
## Why Sonic Was Created
|
6
10
|
|
7
11
|
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.
|
@@ -24,149 +28,44 @@ By the time I get into the container, I need to remind my brain on what the orig
|
|
24
28
|
|
25
29
|
## Install
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
```
|
30
|
-
gem install sonic-screwdriver
|
31
|
-
```
|
32
|
-
|
33
|
-
Set up your AWS credentials at `~/.aws/credentials` and `~/.aws/config`. This is the [AWS standard way of setting up credentials](https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/).
|
34
|
-
|
35
|
-
Note that the gem is named `sonic-screwdriver` but the command is `sonic`.
|
36
|
-
|
37
|
-
## Requirements
|
38
|
-
|
39
|
-
* [jq](https://stedolan.github.io/jq/manual/) - a lightweight and flexible command-line JSON processor
|
40
|
-
|
41
|
-
If you are also using the `ecs-exec` and `ecs-run` commands, then you will need to ensure that [jq](https://stedolan.github.io/jq/) is installed on all of your ECS container instances. If you are only using the `sonic ssh` command then you do not need the jq dependency.
|
42
|
-
|
43
|
-
## Usage
|
44
|
-
|
45
|
-
### sonic ssh
|
46
|
-
|
47
|
-
To ssh into the host or container instance where an ECS service called `my-service` is running, simply run:
|
48
|
-
|
49
|
-
```
|
50
|
-
$ sonic ssh my-service --cluster my-cluster
|
51
|
-
# now you are on the container instance
|
52
|
-
$ docker ps
|
53
|
-
$ curl -s http://localhost:51678/v1/meta | jq .
|
54
|
-
```
|
55
|
-
|
56
|
-
The `my-service` can possible run on multiple container instances. The `sonic` command chooses the first container instance that it finds. If you need to ssh into a specific container instance, use `sonic ssh` instead.
|
57
|
-
|
58
|
-
You can also use the instance id, container instance arn or task arn to ssh into the machine. Examples:
|
59
|
-
|
60
|
-
```
|
61
|
-
$ sonic ssh my-ecs-service --cluster my-cluster # cluster is required or ~/.sonic/settings.yml
|
62
|
-
$ sonic ssh i-067c5e3f026c1e801
|
63
|
-
$ sonic ssh 7fbc8c75-4675-4d39-a5a4-0395ff8cd474
|
64
|
-
$ sonic ssh 1ed12abd-645c-4a05-9acf-739b9d790170
|
65
|
-
```
|
66
|
-
|
67
|
-
### sonic ecs-exec
|
68
|
-
|
69
|
-
`sonic ecs-exec` will hop one more level and get you all the way into a live container for a service. To quickly get yourself into a docker exec bash shell for a service:
|
70
|
-
|
71
|
-
```
|
72
|
-
$ sonic ecs-exec SERVICE bash
|
73
|
-
$ sonic ecs-exec SERVICE # same as above, defaults to bash shell
|
74
|
-
```
|
75
|
-
|
76
|
-
This ultimately runs the following command after it ssh into the container instance:
|
77
|
-
|
78
|
-
```
|
79
|
-
$ docker run -ti SERVICE_CONTAINER bash
|
80
|
-
```
|
81
|
-
|
82
|
-
Here are examples to show what is possible:
|
83
|
-
|
84
|
-
```
|
85
|
-
$ sonic ecs-exec my-service bash
|
86
|
-
# You're in the docker container now
|
87
|
-
$ ls # check out some files to make sure you're the right place
|
88
|
-
$ ps auxxx | grep puma # is the web process up?
|
89
|
-
$ env # are the environment variables properly set?
|
90
|
-
$ bundle exec rails c # start up a rails console to debug
|
91
|
-
```
|
92
|
-
|
93
|
-
You can also pass in bundle exec rails console if you want to get to that as quickly as possible.
|
94
|
-
|
95
|
-
```
|
96
|
-
$ sonic ecs-exec my-service 'bundle exec rails console'
|
97
|
-
# You're a rails console in the docker container now
|
98
|
-
> User.count
|
99
|
-
```
|
100
|
-
|
101
|
-
You must put commands with spaces in quotes.
|
102
|
-
|
103
|
-
You can also use the container instance id or instance id in place of the service name:
|
104
|
-
|
105
|
-
```
|
106
|
-
$ sonic ecs-exec 9f1dadc7-4f67-41da-abec-ec08810bfbc9 bash
|
107
|
-
$ i-006a097bb10643e20
|
108
|
-
```
|
109
|
-
|
110
|
-
### sonic ecs-run
|
111
|
-
|
112
|
-
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.
|
113
|
-
|
114
|
-
This also allows you to run one off commands like a rake task. Here's an example:
|
31
|
+
If you want to quickly install sonic without having to worry about sonic's dependencies you can simply install the Bolts Toolbelt which has sonic included.
|
115
32
|
|
116
|
-
```
|
117
|
-
|
33
|
+
```sh
|
34
|
+
brew cask install boltopslabs/software/bolts
|
118
35
|
```
|
119
36
|
|
120
|
-
|
37
|
+
Or if you prefer you can install ufo with RubyGems
|
121
38
|
|
122
|
-
```
|
123
|
-
|
124
|
-
sonic ecs-run my-service bash # same thing
|
39
|
+
```sh
|
40
|
+
gem install ufo
|
125
41
|
```
|
126
42
|
|
127
|
-
|
43
|
+
Full installation instructions are at [Install Sonic Screwdriver](http://localhost:4000/docs/install/). There are some server side dependencies for some of the sonic commands so it is important to read through the full installation guide.
|
128
44
|
|
129
|
-
|
45
|
+
## Quick Start
|
130
46
|
|
131
|
-
|
132
|
-
service_cluster:
|
133
|
-
default: my-default-cluster
|
134
|
-
hi-web-prod: prod
|
135
|
-
hi-clock-prod: prod
|
136
|
-
hi-worker-prod: prod
|
137
|
-
hi-web-stag: stag
|
138
|
-
hi-clock-stag: stag
|
139
|
-
hi-worker-stag: stag
|
140
|
-
```
|
47
|
+
Here is a quick overview of sonic abilities:
|
141
48
|
|
142
|
-
|
49
|
+
```sh
|
50
|
+
# ssh into an instance
|
51
|
+
sonic ssh i-0f7f833131a51ce35
|
52
|
+
sonic ssh hi-web-stag
|
143
53
|
|
144
|
-
|
145
|
-
sonic
|
146
|
-
sonic ssh hi-clock-prod
|
147
|
-
sonic ssh hi-worker-stag
|
148
|
-
```
|
54
|
+
# docker exec to a running ECS docker container
|
55
|
+
sonic ecs-exec hi-web-stag
|
149
56
|
|
150
|
-
|
57
|
+
# docker run with same environment as the ECS docker running containers
|
58
|
+
sonic ecs-run hi-web-stag
|
151
59
|
|
152
|
-
|
153
|
-
sonic
|
154
|
-
sonic ssh hi-clock-prod --cluster prod
|
155
|
-
sonic ssh hi-worker-stag --cluster stag
|
156
|
-
```
|
60
|
+
# run command on 1 instance
|
61
|
+
sonic execute i-0f7f833131a51ce35 uptime
|
157
62
|
|
158
|
-
|
63
|
+
# run command on all instances tagged with hi-web-stag and worker
|
64
|
+
sonic execute hi-web-stag,hi-worker-stag uptime
|
159
65
|
|
66
|
+
# list ec2 instances
|
67
|
+
sonic list hi-web-stag
|
160
68
|
```
|
161
|
-
sonic help
|
162
|
-
sonic help ssh
|
163
|
-
sonic help ecs-exec
|
164
|
-
sonic help ecs-run
|
165
|
-
```
|
166
|
-
|
167
|
-
## Internals
|
168
|
-
|
169
|
-
If are interested in the internal logic to achieve what the sonic commands it is detailed on the [wiki](https://github.com/boltopslabs/sonic/wiki).
|
170
69
|
|
171
70
|
## Contributing
|
172
71
|
|
data/docs/_docs/install.md
CHANGED
@@ -4,7 +4,7 @@ title: ECS Exec
|
|
4
4
|
|
5
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 additional things `sonic` can do is
|
7
|
+
One of the additional things `sonic` can do is hop one more level and get you all the way to the running docker container via `docker exec`.
|
8
8
|
|
9
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
|
|
@@ -31,7 +31,35 @@ 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 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 🎉
|
34
|
+
What you see in the last line above is a bash prompt because you are in a bash shell within the docker container! Ultimately sonic runs runs a `docker exec -ti ECS_SERVICE_CONTAINER bash` after ssh-ing into the instance. With one command you have placed yourself into the running container 🎉
|
35
|
+
|
36
|
+
Here are examples to show what is possible:
|
37
|
+
|
38
|
+
```
|
39
|
+
$ sonic ecs-exec hi-web-stag bash
|
40
|
+
# You're in the docker container now
|
41
|
+
$ ls # check out some files to make sure you're the right place
|
42
|
+
$ ps auxxx | grep puma # is the web process up?
|
43
|
+
$ env # are the environment variables properly set?
|
44
|
+
$ bundle exec rails c # start up a rails console to debug
|
45
|
+
```
|
46
|
+
|
47
|
+
You can also pass in bundle exec rails console if you want to get to that as quickly as possible.
|
48
|
+
|
49
|
+
```
|
50
|
+
$ sonic ecs-exec hi-web-stag bundle exec rails console
|
51
|
+
# You're a rails console in the docker container now
|
52
|
+
> User.count
|
53
|
+
```
|
54
|
+
|
55
|
+
You can also use the container instance id or instance id in place of the service name:
|
56
|
+
|
57
|
+
```
|
58
|
+
sonic ecs-exec 9f1dadc7-4f67-41da-abec-ec08810bfbc9 bash
|
59
|
+
sonic ecs-exec i-006a097bb10643e20 bash
|
60
|
+
```
|
61
|
+
|
62
|
+
### Settings - service_cluster
|
35
63
|
|
36
64
|
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
65
|
|
@@ -6,7 +6,7 @@ The nice thing about the previous `ecs-exec` command we covered is that it allow
|
|
6
6
|
|
7
7
|
### sonic ecs-run
|
8
8
|
|
9
|
-
|
9
|
+
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. Here's an example:
|
10
10
|
|
11
11
|
```sh
|
12
12
|
sonic ecs-run hi-web-stag
|
@@ -18,7 +18,7 @@ sonic execute hi-web-stag yum install -y curl
|
|
18
18
|
|
19
19
|
The output of the command will show a useful `aws ssm list-commands` command to get status of the requested command.
|
20
20
|
|
21
|
-
```
|
21
|
+
```sh
|
22
22
|
$ sonic execute hi-web-stag uptime
|
23
23
|
Command sent to AWS SSM. To check the details of the command:
|
24
24
|
aws ssm list-commands --command-id 4133e5eb-aa18-40dd-be25-a176eb15e515
|
@@ -30,6 +30,12 @@ The output of the commands ran are also showed in the EC2 Run Command Console.
|
|
30
30
|
|
31
31
|
<img src="/img/tutorials/ec2-console-run-command.png" class="doc-photo" />
|
32
32
|
|
33
|
+
You can execute a command with a list of filters seprated by commas. For example, this will run the uptime command on any server with a tag value of hi-web-stag,hi-clock-stag, or hi-worker-stag.
|
34
|
+
|
35
|
+
```sh
|
36
|
+
sonic execute hi-web-stag,hi-clock-stag,hi-worker-stag uptime
|
37
|
+
```
|
38
|
+
|
33
39
|
### Run Scripts
|
34
40
|
|
35
41
|
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`:
|
data/docs/_docs/tutorial-ssh.md
CHANGED
@@ -46,6 +46,8 @@ user: ec2-user
|
|
46
46
|
|
47
47
|
More information about sonic settings in available in the docs: [Settings]({% link _docs/settings.md %}).
|
48
48
|
|
49
|
+
### Different Identifiers
|
50
|
+
|
49
51
|
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.
|
50
52
|
|
51
53
|
```
|
@@ -68,10 +70,9 @@ service_cluster:
|
|
68
70
|
hi-worker-stag: stag
|
69
71
|
```
|
70
72
|
|
71
|
-
With these settings in place, the commands get shorten to become:
|
73
|
+
With these settings in place, the ECS identifier commands get shorten to become:
|
72
74
|
|
73
75
|
```sh
|
74
|
-
sonic ssh EC2_TAG_VALUE
|
75
76
|
sonic ssh ECS_CONTAINER_ID
|
76
77
|
sonic ssh ECS_SERVICE
|
77
78
|
sonic ssh ECS_TASK_ID
|
@@ -80,7 +81,19 @@ sonic ssh ECS_TASK_ID
|
|
80
81
|
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.
|
81
82
|
|
82
83
|
```sh
|
83
|
-
sonic ssh hi-web-stag
|
84
|
+
$ sonic ssh hi-web-stag
|
85
|
+
# now you are on the container instance
|
86
|
+
$ docker ps
|
87
|
+
$ curl -s http://localhost:51678/v1/meta | jq .
|
88
|
+
```
|
89
|
+
|
90
|
+
The `hi-web-stag` can possibly be running on multiple container instances. The `sonic` command chooses the first container instance that it finds. If you need to ssh into a specific container instance, use `sonic ssh` instead.
|
91
|
+
|
92
|
+
You can also use the ECS container instance arn or task id to ssh into the machine. Examples:
|
93
|
+
|
94
|
+
```
|
95
|
+
$ sonic ssh 7fbc8c75-4675-4d39-a5a4-0395ff8cd474 # ECS container id
|
96
|
+
$ sonic ssh 1ed12abd-645c-4a05-9acf-739b9d790170 # ECS task id
|
84
97
|
```
|
85
98
|
|
86
99
|
### Bastion Host
|
data/lib/sonic/cli/help.rb
CHANGED
@@ -28,7 +28,7 @@ Examples:
|
|
28
28
|
|
29
29
|
$ sonic ssh i-067c5e3f026c1e801
|
30
30
|
$ sonic ssh hi-web-prod
|
31
|
-
$ sonic ssh
|
31
|
+
$ sonic ssh --cluster my-cluster my-ecs-service # cluster is required or ~/.sonic/settings.yml
|
32
32
|
$ sonic ssh 7fbc8c75-4675-4d39-a5a4-0395ff8cd474
|
33
33
|
$ sonic ssh 1ed12abd-645c-4a05-9acf-739b9d790170
|
34
34
|
|
@@ -50,8 +50,8 @@ Bastion Host Support
|
|
50
50
|
|
51
51
|
Sonic ssh also supports a bastion host.
|
52
52
|
|
53
|
-
$ sonic ssh
|
54
|
-
$ sonic ssh
|
53
|
+
$ sonic ssh --bastion bastion.domain.com i-027363802c6ff314f
|
54
|
+
$ sonic ssh --bastion user@bastion.domain.com i-027363802c6ff314f
|
55
55
|
|
56
56
|
Here's what the output looks like:
|
57
57
|
|
@@ -81,8 +81,8 @@ environment and image as the specified running service.
|
|
81
81
|
|
82
82
|
Examples:
|
83
83
|
|
84
|
-
$ sonic ecs-run my-
|
85
|
-
$ sonic ecs-run my-
|
84
|
+
$ sonic ecs-run --cluster my-cluster my-service
|
85
|
+
$ sonic ecs-run --cluster my-cluster my-service
|
86
86
|
|
87
87
|
# If there are flags in the command that you want to pass down to the docker
|
88
88
|
run command you will need to put the command in single quotes. This is due to
|
@@ -120,7 +120,7 @@ $ sonic list i-09482b1a6e330fbf7
|
|
120
120
|
|
121
121
|
Example Output:
|
122
122
|
|
123
|
-
$ sonic list i-09482b1a6e330fbf7
|
123
|
+
$ sonic list --header i-09482b1a6e330fbf7
|
124
124
|
Instance Id Public IP Private IP Type
|
125
125
|
i-09482b1a6e330fbf7 54.202.152.168 172.31.21.108 t2.small
|
126
126
|
$
|
data/lib/sonic/ssh.rb
CHANGED
data/lib/sonic/version.rb
CHANGED
data/spec/lib/cli_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Sonic::CLI do
|
|
12
12
|
|
13
13
|
describe "sonic" do
|
14
14
|
it "ssh should print out ssh command to be ran" do
|
15
|
-
out = execute("bin/sonic ssh
|
15
|
+
out = execute("bin/sonic ssh #{@args} --cluster default my-service")
|
16
16
|
expect(out).to include("=> ssh")
|
17
17
|
end
|
18
18
|
|
@@ -22,8 +22,8 @@ describe Sonic::CLI do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "list should list running instances" do
|
25
|
-
out = execute("bin/sonic list #{@args} 1,2,3
|
26
|
-
expect(out).to include("
|
25
|
+
out = execute("bin/sonic list #{@args} --header 1,2,3")
|
26
|
+
expect(out).to include("No instances found")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
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.1.
|
4
|
+
version: 1.1.1
|
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-
|
11
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|