sonic-screwdriver 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +6 -6
- data/README.md +3 -1
- data/docs/_docs/settings.md +1 -1
- data/docs/_docs/tutorial-ecs-exec.md +3 -1
- data/docs/_docs/tutorial-ecs-run.md +7 -1
- data/docs/_docs/tutorial-execute.md +23 -2
- data/docs/_docs/tutorial-ssh.md +7 -3
- data/docs/quick-start.md +5 -1
- data/lib/sonic/cli.rb +0 -4
- data/lib/sonic/cli/help.rb +6 -2
- data/lib/sonic/execute.rb +3 -1
- data/lib/sonic/list.rb +8 -2
- data/lib/sonic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bab148a2ed5638be1af0462d0e8d8e594bb17b8b
|
4
|
+
data.tar.gz: ab33bc905251629ebfe0afb313b1467652ec14f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 448ee390aeaf1d33395515f30d0a7aafd1347a6c8cf07230325441cd4a38027f7d3eb0a7dd361d0698b96a4a36088a0eadc8631050c56e303bac017dd6efc7f1
|
7
|
+
data.tar.gz: 5f346a3756cd24f8025eafd1ac227fc075d3f9948164ba076544f7bafb7905a5a35e01d3cad32d3a5a991605f456da72dec052ad11b93ce6f4acaeb6801b337a
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
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.2.0]
|
7
|
+
- add old instance id support
|
8
|
+
- update docs and help
|
9
|
+
|
6
10
|
## [1.1.1]
|
7
11
|
- update docs and help
|
8
12
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sonic-screwdriver (
|
4
|
+
sonic-screwdriver (1.1.1)
|
5
5
|
aws-sdk
|
6
6
|
colorize
|
7
7
|
hashie
|
@@ -11,13 +11,13 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
aws-sdk (2.9.
|
15
|
-
aws-sdk-resources (= 2.9.
|
16
|
-
aws-sdk-core (2.9.
|
14
|
+
aws-sdk (2.9.43)
|
15
|
+
aws-sdk-resources (= 2.9.43)
|
16
|
+
aws-sdk-core (2.9.43)
|
17
17
|
aws-sigv4 (~> 1.0)
|
18
18
|
jmespath (~> 1.0)
|
19
|
-
aws-sdk-resources (2.9.
|
20
|
-
aws-sdk-core (= 2.9.
|
19
|
+
aws-sdk-resources (2.9.43)
|
20
|
+
aws-sdk-core (= 2.9.43)
|
21
21
|
aws-sigv4 (1.0.0)
|
22
22
|
codeclimate-test-reporter (1.0.8)
|
23
23
|
simplecov (<= 0.13)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Sonic
|
1
|
+
# Sonic Screwdriver
|
2
2
|
|
3
3
|
[![CircleCI](https://circleci.com/gh/boltopslabs/sonic.svg?style=svg)](https://circleci.com/gh/boltopslabs/sonic)
|
4
4
|
|
@@ -69,6 +69,8 @@ sonic list hi-web-stag
|
|
69
69
|
|
70
70
|
## Contributing
|
71
71
|
|
72
|
+
Everyone can contribute to make sonic-screwdriver better. Please fork the project and open a pull request! We love your pull requests. Contributions are encouraged and welcomed!
|
73
|
+
|
72
74
|
1. Fork it
|
73
75
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
76
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/docs/_docs/settings.md
CHANGED
@@ -4,7 +4,7 @@ title: Settings
|
|
4
4
|
|
5
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
|
-
1.
|
7
|
+
1. current folder - The current folder's `.sonic/settings.yml` values take the highest precedence. The current folder is typically the project folder.
|
8
8
|
2. user - The user's `~/.sonic/settings.yml` values take the second highest precedence.
|
9
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
10
|
|
@@ -33,6 +33,8 @@ root@fc4035f90bdc:/app#
|
|
33
33
|
|
34
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
35
|
|
36
|
+
### Possibilities
|
37
|
+
|
36
38
|
Here are examples to show what is possible:
|
37
39
|
|
38
40
|
```
|
@@ -59,7 +61,7 @@ sonic ecs-exec 9f1dadc7-4f67-41da-abec-ec08810bfbc9 bash
|
|
59
61
|
sonic ecs-exec i-006a097bb10643e20 bash
|
60
62
|
```
|
61
63
|
|
62
|
-
### Settings - service_cluster
|
64
|
+
### Settings - service_cluster mapping
|
63
65
|
|
64
66
|
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:
|
65
67
|
|
@@ -4,9 +4,15 @@ title: ECS Run
|
|
4
4
|
|
5
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
|
+
The `sonic ecs-run` command is similar to the `sonic ecs-exec` command except it'll run a brand new container with the same environment variables as the task associated with the service. This allows you to debug in a container with the exact environment variables as the running tasks/containers without affecting the live service. So this is safer since you will not be able to mess up a live container that is in service.
|
8
|
+
|
7
9
|
### sonic ecs-run
|
8
10
|
|
9
|
-
|
11
|
+
```sh
|
12
|
+
sonic ecs-run [ECS_SERVICE] --cluster [ECS_CLUSTER]
|
13
|
+
```
|
14
|
+
|
15
|
+
Here's an example:
|
10
16
|
|
11
17
|
```sh
|
12
18
|
sonic ecs-run hi-web-stag
|
@@ -4,10 +4,20 @@ title: Sonic Execute
|
|
4
4
|
|
5
5
|
### Run One Liners
|
6
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.
|
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. The command is called `sonic execute`:
|
8
|
+
|
9
|
+
```sh
|
10
|
+
sonic execute [FILTER] [COMMAND]
|
11
|
+
```
|
12
|
+
|
13
|
+
Examples:
|
8
14
|
|
9
15
|
```sh
|
10
16
|
sonic execute hi-web-stag uptime
|
17
|
+
sonic execute hi-web-prod uptime
|
18
|
+
sonic execute hi-web-prod,hi-worker-prod,hi-clock-prod uptime
|
19
|
+
sonic execute i-030033c20c54bf149,i-030033c20c54bf150 uname -a
|
20
|
+
sonic execute i-030033c20c54bf149 file://hello.sh
|
11
21
|
```
|
12
22
|
|
13
23
|
Let's do something more useful:
|
@@ -30,7 +40,11 @@ The output of the commands ran are also showed in the EC2 Run Command Console.
|
|
30
40
|
|
31
41
|
<img src="/img/tutorials/ec2-console-run-command.png" class="doc-photo" />
|
32
42
|
|
33
|
-
|
43
|
+
### Polymorphic Filter
|
44
|
+
|
45
|
+
The `sonic execute` command can understand a variety of different filters. The filters can be a list of instances ids or a list of EC2 tag names. Note, ECS service names are *not* supported for the filter.
|
46
|
+
|
47
|
+
Here is an example, where the uptime command will run on any server with a tag value of hi-web-stag,hi-clock-stag, or hi-worker-stag.
|
34
48
|
|
35
49
|
```sh
|
36
50
|
sonic execute hi-web-stag,hi-clock-stag,hi-worker-stag uptime
|
@@ -53,6 +67,13 @@ sonic execute hi-web-stag file://hi.sh
|
|
53
67
|
|
54
68
|
The file gets read by `sonic execute` and sent to EC2 Run Command to be executed.
|
55
69
|
|
70
|
+
### Amazon EC2 Run Manager Installation
|
71
|
+
|
72
|
+
The `sonic execute` command relies on EC2 Run Manager. So you will need to have EC2 Run Manager installed on the servers where you want to the commands to be executed.
|
73
|
+
|
74
|
+
* You can follow the [installation guide]({% link _docs/install.md %}) to install EC2 Run Manager.
|
75
|
+
* You can read on [Why EC2 Run Manager]({% link _docs/why-ec2-run-command.md %}) is used also.
|
76
|
+
|
56
77
|
<a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-run.md %}">Back</a>
|
57
78
|
<a id="next" class="btn btn-primary" href="{% link _docs/settings.md %}">Next Step</a>
|
58
79
|
<p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
|
data/docs/_docs/tutorial-ssh.md
CHANGED
@@ -46,17 +46,21 @@ 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
|
-
###
|
49
|
+
### Polymorphic Identifiers
|
50
50
|
|
51
|
-
The `sonic ssh` command can auto-detect the proper ip address with a variety of different identifiers.
|
51
|
+
The `sonic ssh` command can auto-detect the proper ip address with a variety of different identifiers. The identifier is not just limited to the instance id. The identifier can be also an EC2 tag-value filter, ECS service name, ECS container id or ECS task id.
|
52
|
+
|
53
|
+
This is convenient in case you happen to be on a dashboard with another identifer close by and handy. Here are example usage with identifiers that `sonic ssh` understands.
|
52
54
|
|
53
55
|
```
|
54
56
|
sonic ssh EC2_TAG_FILTER
|
55
|
-
sonic ssh ECS_CONTAINER_ID --cluster stag
|
56
57
|
sonic ssh ECS_SERVICE --cluster stag
|
58
|
+
sonic ssh ECS_CONTAINER_ID --cluster stag
|
57
59
|
sonic ssh ECS_TASK_ID --cluster stag
|
58
60
|
```
|
59
61
|
|
62
|
+
The EC2 tag filter uses the 'tag-value' filter as described in the [AWS describe-instances](http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) filter docs. This filter is independent of the tag-key filter, which means any EC2 tag value will match, regardless of the tag key name. Sonic does not support spaces in the EC2 tag filter.
|
63
|
+
|
60
64
|
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:
|
61
65
|
|
62
66
|
```yaml
|
data/docs/quick-start.md
CHANGED
@@ -15,7 +15,11 @@ brew cask install boltopslabs/software/bolts
|
|
15
15
|
```sh
|
16
16
|
# ssh into an instance
|
17
17
|
sonic ssh i-0f7f833131a51ce35
|
18
|
-
sonic ssh hi-web-stag
|
18
|
+
sonic ssh hi-web-stag # ec2 tag
|
19
|
+
sonic ssh hi-web-stag --cluster stag # ecs service name
|
20
|
+
sonic ssh hi-web-stag --cluster stag # ecs service name
|
21
|
+
sonic ssh 7fbc8c75-4675-4d39-a5a4-0395ff8cd474 --cluster stag # ECS container id
|
22
|
+
sonic ssh 1ed12abd-645c-4a05-9acf-739b9d790170 --cluster stag # ECS task id
|
19
23
|
|
20
24
|
# docker exec to a running ECS docker container
|
21
25
|
sonic ecs-exec hi-web-stag
|
data/lib/sonic/cli.rb
CHANGED
@@ -9,14 +9,12 @@ 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
|
-
stop_on_unknown_option! :ssh
|
13
12
|
desc "ssh [IDENTIFER]", "ssh into a instance using identifier. identifer can be several things: instance id, ec2 tag, ECS service name, etc"
|
14
13
|
long_desc Help.ssh
|
15
14
|
def ssh(identifier, *command)
|
16
15
|
Ssh.new(identifier, options.merge(command: command)).run
|
17
16
|
end
|
18
17
|
|
19
|
-
stop_on_unknown_option! :ecs_exec
|
20
18
|
desc "ecs-exec [ECS_SERVICE]", "docker exec into running docker container associated with the service on a container instance"
|
21
19
|
long_desc Help.ecs_exec
|
22
20
|
def ecs_exec(service, *command)
|
@@ -24,14 +22,12 @@ module Sonic
|
|
24
22
|
end
|
25
23
|
|
26
24
|
# Cannot name the command run because that is a reserved Thor keyword :(
|
27
|
-
stop_on_unknown_option! :ecs_run
|
28
25
|
desc "ecs-run [ECS_SERVICE]", "docker run with the service on a container instance"
|
29
26
|
long_desc Help.ecs_run
|
30
27
|
def ecs_run(service, *command)
|
31
28
|
Docker.new(service, options.merge(command: command)).run
|
32
29
|
end
|
33
30
|
|
34
|
-
stop_on_unknown_option! :execute
|
35
31
|
desc "execute [FILTER] [COMMAND]", "runs command across fleet of servers via AWS Run Command"
|
36
32
|
long_desc Help.execute
|
37
33
|
# filter - Filter ec2 instances by tag name or instance_ids separated by commas
|
data/lib/sonic/cli/help.rb
CHANGED
@@ -24,11 +24,13 @@ Ssh quicky into an EC2 instance using an identifier. The identifier can be many
|
|
24
24
|
* ECS container instance id. Example: 7fbc8c75-4675-4d39-a5a4-0395ff8cd474
|
25
25
|
* ECS task id. Example: 1ed12abd-645c-4a05-9acf-739b9d790170
|
26
26
|
|
27
|
+
When using ecs identifiers the `--cluster` option is required or can be set in ~/.sonic/settings.yml.
|
28
|
+
|
27
29
|
Examples:
|
28
30
|
|
29
31
|
$ sonic ssh i-067c5e3f026c1e801
|
30
32
|
$ sonic ssh hi-web-prod
|
31
|
-
$ sonic ssh --cluster my-cluster my-ecs-service
|
33
|
+
$ sonic ssh --cluster my-cluster my-ecs-service
|
32
34
|
$ sonic ssh 7fbc8c75-4675-4d39-a5a4-0395ff8cd474
|
33
35
|
$ sonic ssh 1ed12abd-645c-4a05-9acf-739b9d790170
|
34
36
|
|
@@ -55,7 +57,7 @@ $ sonic ssh --bastion user@bastion.domain.com i-027363802c6ff314f
|
|
55
57
|
|
56
58
|
Here's what the output looks like:
|
57
59
|
|
58
|
-
$ sonic ssh
|
60
|
+
$ sonic ssh --bastion 34.211.223.3 i-0f7f833131a51ce35 uptime
|
59
61
|
=> ssh -At ec2-user@34.211.223.3 ssh ec2-user@10.10.110.135 uptime
|
60
62
|
17:57:59 up 37 min, 0 users, load average: 0.00, 0.02, 0.00
|
61
63
|
Connection to 34.211.223.3 closed.
|
@@ -71,6 +73,8 @@ with the service and docker exec's into it.
|
|
71
73
|
Examples:
|
72
74
|
|
73
75
|
$ sonic ecs-exec my-service --cluster my-cluster
|
76
|
+
|
77
|
+
You can use a variety of identifiers. These include the ECS service name and task id.
|
74
78
|
EOL
|
75
79
|
end
|
76
80
|
|
data/lib/sonic/execute.rb
CHANGED
data/lib/sonic/list.rb
CHANGED
@@ -29,15 +29,21 @@ module Sonic
|
|
29
29
|
UI.say("No instances found with the filter #{@filter.join('')}") if zero_instances
|
30
30
|
|
31
31
|
if @options[:header] && !zero_instances
|
32
|
-
|
32
|
+
header = ["Instance Id", "Name", "Public IP", "Private IP", "Type"]
|
33
|
+
UI.say header.join("\t").colorize(:green)
|
33
34
|
end
|
34
35
|
|
35
36
|
instances.each do |i|
|
36
|
-
line = [i.instance_id, i.public_ip_address, i.private_ip_address, i.instance_type].join("\t")
|
37
|
+
line = [i.instance_id, tag_value(i, "Name"), i.public_ip_address, i.private_ip_address, i.instance_type].join("\t")
|
37
38
|
UI.say(line)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
def tag_value(instance, key)
|
43
|
+
tag = instance.tags.find { |i| i.key == key }
|
44
|
+
tag.value
|
45
|
+
end
|
46
|
+
|
41
47
|
#
|
42
48
|
# Public: Transform the filter to the ssm send_command equivalent options
|
43
49
|
#
|
data/lib/sonic/version.rb
CHANGED
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.
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|