ecs_cmd 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 364c2ce1e5efde7c1b03633a2a49538bb3e67a8b7a144ae7f64fe0cd6bf01237
4
- data.tar.gz: acb50a84aa34496a6cead40dac6e6eac938685b59ce6d0fdf1dee7a48de065e2
3
+ metadata.gz: d71f58e4a9633203372ae063a6092f3e240706512e78194d3c826ee917061067
4
+ data.tar.gz: 596040a7991d22b567f6949628bd8e6ff8196f6c43c6b3b12961a7c16e40f11d
5
5
  SHA512:
6
- metadata.gz: 499703cbf2f95e27647ed1f735523aade77009bf078161151dc4609d53ebd3551cddf87ae0d4cb530f63d5397276405caef17c6ed14060e1500bfb74bf460604
7
- data.tar.gz: 84b96c418ac4fe57931185e3f032b5612fddb95b13b11e4c8b25fdb1672babc81f2af94837733f2b42651755ac9f5f89644cc431f027e5739f417e67a7f6f321
6
+ metadata.gz: c15acb739bb663c7a6f42627dd6d8e47b440b7de2964d48ee6d919cfcc2f8517ba2e06647e195058992ce5b1092bc3b9dbcf11c57af1a87892fee683998580b5
7
+ data.tar.gz: 3fd61f53280919e2c9cefc57a02167e7c3fd2c423b427f8be7d8bef0755bbd80f0fe111fe86653d113fcde5d9acc15c156724d881c1e0f63ae873708b85c86bb
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # 0.1.4
2
+
3
+ - Added user flag to shell command. `ecs-cmd shell -c production -s foo -u nobody`
4
+ - Added user flag to exec command. `ecs-cmd exec -c production -s foo -u nobody whoami`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecs_cmd (0.1.3)
4
+ ecs_cmd (0.1.4)
5
5
  aws-sdk-ec2
6
6
  aws-sdk-ecs
7
7
  gli (= 2.17.1)
@@ -52,6 +52,7 @@ GEM
52
52
 
53
53
  PLATFORMS
54
54
  ruby
55
+ x86_64-darwin-17
55
56
 
56
57
  DEPENDENCIES
57
58
  bundler (~> 1.16)
data/README.md CHANGED
@@ -2,29 +2,220 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/dschaaff/ecs-cmd.svg?branch=master)](https://travis-ci.org/dschaaff/ecs-cmd) [![Gem Version](https://badge.fury.io/rb/ecs_cmd.svg)](https://badge.fury.io/rb/ecs_cmd)
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ecs_cmd`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- TODO: Delete this and the text above, and describe your gem
5
+ This is a command line application for interacting with AWS ECS. The standard AWS cli can be a bit
6
+ cumbersome for some tasks. Ecs-cmd aims to simplify those tasks.
8
7
 
9
8
  ## Installation
10
9
 
11
- Add this line to your application's Gemfile:
10
+ ```bash
11
+ gem install ecs_cmd
12
+ ```
13
+
14
+ The gem uses the standard aws crendential chain for authentication actions. See https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html for reference.
12
15
 
13
- ```ruby
14
- gem 'ecs_cmd'
16
+ ## Usage
17
+
18
+ ```
19
+ ecs-cmd
20
+ NAME
21
+ ecs-cmd - Command utility for interacting with AWS ECS
22
+
23
+ SYNOPSIS
24
+ ecs-cmd [global options] command [command options] [arguments...]
25
+
26
+ VERSION
27
+ 0.1.3
28
+
29
+ GLOBAL OPTIONS
30
+ --help - Show this message
31
+ -r, --region=region - Set the aws region (default: us-east-1)
32
+ --version - Display the program version
33
+
34
+ COMMANDS
35
+ exec - Execute a Command Within a Service's Container
36
+ get - Get Info on Clusters and Services
37
+ help - Shows a list of commands or help for one command
38
+ logs - Tail Logs From a Service's Container
39
+ run-task - Run a One Off Task On an ECS Cluster
40
+ shell - Open a Shell Inside a Service's Container
41
+ ssh - SSH into Host Task is Running On
15
42
  ```
16
43
 
17
- And then execute:
44
+ ### Get Commands
18
45
 
19
- $ bundle
46
+ These allow you to query information from ECS.
20
47
 
21
- Or install it yourself as:
48
+ #### Get Clusters
22
49
 
23
- $ gem install ecs_cmd
50
+ ```
51
+ ecs-cmd get clusters
52
+ +--------------------+--------------------------+----------+---------------+---------------+
53
+ | CLUSTER NAME | CONTAINER_INSTANCE_COUNT | SERVICES | RUNNING_TASKS | PENDING_TASKS |
54
+ +--------------------+--------------------------+----------+---------------+---------------+
55
+ | production | 20 | 39 | 82 | 0 |
56
+ | development | 1 | 2 | 1 | 0 |
57
+ +--------------------+--------------------------+----------+---------------+---------------+
58
+ ```
24
59
 
25
- ## Usage
60
+ #### Get Services
61
+
62
+ Prints an overview of the services in a given cluster.
63
+
64
+ ```shella
65
+ ecs-cmd get services --help
66
+ NAME
67
+ services -
68
+
69
+ SYNOPSIS
70
+ ecs-cmd [global options] get services [command options]
71
+
72
+ COMMAND OPTIONS
73
+ -c, --cluster=cluster - cluster name (required, default: none)
74
+ ```
75
+
76
+ ```shell
77
+ ecs-cmd get services -c testing
78
+ +--------------------+---------------+---------------+---------------+
79
+ | SERVICE NAME | DESIRED_COUNT | RUNNING_COUNT | PENDING_COUNT |
80
+ +--------------------+---------------+---------------+---------------+
81
+ | datadog-agent | 1 | 0 | 0 |
82
+ | foo-bar | 1 | 1 | 0 |
83
+ +--------------------+---------------+---------------+---------------+
84
+ ```
85
+
86
+ #### Get Service
87
+
88
+ Get information on a specific service in a cluster.
89
+
90
+ ```shell
91
+ cs-cmd get service --help
92
+ NAME
93
+ service -
94
+
95
+ SYNOPSIS
96
+ ecs-cmd [global options] get service [command options]
97
+
98
+ COMMAND OPTIONS
99
+ -c, --cluster=cluster - cluster name (required, default: none)
100
+ -e, --[no-]events - get ecs events
101
+ -s, --service=service - service name (required, default: none)
102
+ -t, --[no-]task_definition - get current task definition for service
103
+ ```
104
+
105
+ ```shell
106
+ ecs-cmd get service -c production -s foo
107
+ +------+--------+---------------+---------------+---------------+-------------+-------------+
108
+ | NAME | STATUS | RUNNING COUNT | DESIRED COUNT | PENDING COUNT | MAX HEALTHY | MIN HEALTHY |
109
+ +------+--------+---------------+---------------+---------------+-------------+-------------+
110
+ | foo | ACTIVE | 2 | 2 | 0 | 200 | 50 |
111
+ +------+--------+---------------+---------------+---------------+-------------+-------------+
112
+ +----------------------------------------------------------------------+
113
+ | TASK DEFINITION |
114
+ +----------------------------------------------------------------------+
115
+ | arn:aws:ecs:us-east-1:xxxxxxxxxxxx:task-definition/foo-production:25 |
116
+ +----------------------------------------------------------------------+
117
+ +---------------------+--------------+
118
+ | INSTANCE ID | IP |
119
+ +---------------------+--------------+
120
+ | i-xxxxxxxxxxxxxxxxx | 10.0.230.1 |
121
+ | i-xxxxxxxxxxxxxxxxx | 10.0.220.3 |
122
+ +---------------------+--------------+
123
+ +-----------------+----------------------------------------------------------------------+
124
+ | DEPLOYMENTS | |
125
+ +-----------------+----------------------------------------------------------------------+
126
+ | id | ecs-svc/xxxxxxxxxxxxxxxxxxx |
127
+ | status | PRIMARY |
128
+ | task definition | arn:aws:ecs:us-east-1:xxxxxxxxxxxx:task-definition/foo-production:25 |
129
+ | desired count | 2 |
130
+ | pending count | 0 |
131
+ | running count | 2 |
132
+ | created at | 2018-12-07 09:44:59 -0800 |
133
+ | updated at | 2018-12-07 09:45:58 -0800 |
134
+
135
+ +-----------------+----------------------------------------------------------------------+
136
+ ```
137
+
138
+ ### Logs
26
139
 
27
- TODO: Write usage instructions here
140
+ *requires ssh access to instance*
141
+
142
+ Streams logs from 1 of a services running tasks using the docker logs command
143
+
144
+ ```shell
145
+ ecs-cmd logs --help
146
+ NAME
147
+ logs - Tail Logs From a Service's Container
148
+
149
+ SYNOPSIS
150
+ ecs-cmd [global options] logs [command options]
151
+
152
+ COMMAND OPTIONS
153
+ -c, --cluster=cluster - cluster name (required, default: none)
154
+ -l, --lines=lines - number of historical lines to tail (default: 30)
155
+ -s, --service=service - service name (required, default: none)
156
+ ```
157
+
158
+ ### Run Task
159
+
160
+ Run a one off task in ECS. This will poll for the task to exit and report its exit code. This is
161
+ handy for tasks like rails migrations. If a docker image is passed it will create a new revision of
162
+ the task definition prior to running the task.
163
+
164
+ ```shell
165
+ ecs-cmd run-task --help
166
+ NAME
167
+ run-task - Run a One Off Task On an ECS Cluster
168
+
169
+ SYNOPSIS
170
+ ecs-cmd [global options] run-task [command options]
171
+
172
+ COMMAND OPTIONS
173
+ -c, --cluster=cluster - cluster name (required, default: none)
174
+ -d, --command=command - override task definition command (default: none)
175
+ -i, --image=image - docker image to use for task (default: none)
176
+ -n, --container-name=container name - container name (default: none)
177
+ -t, --task-definition=arg - the task definition to use for task (required, default: none)
178
+ ```
179
+
180
+ ### Shell
181
+
182
+ *requires ssh access to instance*
183
+
184
+ Open a shell inside of a container for a given service.
185
+
186
+ ```shell
187
+ ecs-cmd shell --help
188
+ NAME
189
+ shell - Open a Shell Inside a Service's Container
190
+
191
+ SYNOPSIS
192
+ ecs-cmd [global options] shell [command options]
193
+
194
+ COMMAND OPTIONS
195
+ -c, --cluster=cluster - cluster name (required, default: none)
196
+ -s, --service=service - service name (required, default: none)
197
+ --[no-]sh - use sh instead of bash
198
+ -u, --user=user - user name or uid (default: root)
199
+ ```
200
+
201
+ ### SSH
202
+
203
+ *requires ssh access to instance*
204
+
205
+ SSH onto a host where a container for a given service is running.
206
+
207
+ ```shell
208
+ ecs-cmd ssh --help
209
+ NAME
210
+ ssh - SSH into Host Task is Running On
211
+
212
+ SYNOPSIS
213
+ ecs-cmd [global options] ssh [command options]
214
+
215
+ COMMAND OPTIONS
216
+ -c, --cluster=cluster - cluster name (required, default: none)
217
+ -s, --service=service - service name (required, default: none)
218
+ ```
28
219
 
29
220
  ## Development
30
221
 
data/bin/ecs-cmd CHANGED
@@ -89,12 +89,13 @@ arg_name 'command', :required
89
89
  command :exec do |c|
90
90
  c.flag %i[c cluster], desc: 'cluster name', arg_name: 'cluster', required: true
91
91
  c.flag %i[s service], desc: 'service name', arg_name: 'service', required: true
92
+ c.flag %i[u user], desc: 'user name or uid', arg_name: 'user', default_value: 'root', required: false
92
93
  c.action do |global_options, options, args|
93
94
  service = EcsCmd::Service.new(options[:c], options[:s], global_options[:region])
94
95
  ip = service.container_instance_ips[0]
95
96
  task_family = service.task_family
96
97
  command = args.join(' ')
97
- EcsCmd::Exec.execute(task_family, ip, command)
98
+ EcsCmd::Exec.execute(task_family, ip, command, options[:u])
98
99
  end
99
100
  end
100
101
 
@@ -102,13 +103,14 @@ desc "Open a Shell Inside a Service's Container"
102
103
  command 'shell' do |c|
103
104
  c.flag %i[c cluster], desc: 'cluster name', arg_name: 'cluster', required: true
104
105
  c.flag %i[s service], desc: 'service name', arg_name: 'service', required: true
106
+ c.flag %i[u user], desc: 'user name or uid', arg_name: 'user', default_value: 'root', required: false
105
107
  c.switch %i[sh], desc: 'use sh instead of bash', default_value: false
106
108
  c.action do |global_options, options, args|
107
109
  service = EcsCmd::Service.new(options[:c], options[:s], global_options[:region])
108
110
  ip = service.container_instance_ips[0]
109
111
  task_family = service.task_family
110
112
  shell = options[:sh] ? 'sh' : 'bash'
111
- EcsCmd::Exec.shell(task_family, ip, shell)
113
+ EcsCmd::Exec.shell(task_family, ip, shell, options[:u])
112
114
  end
113
115
  end
114
116
 
data/lib/ecs_cmd/exec.rb CHANGED
@@ -17,8 +17,8 @@ module EcsCmd
17
17
  end
18
18
 
19
19
  # used to run arbitrary command inside a container
20
- def execute(task_family, ip, command)
21
- cmd = "docker exec -i -t `#{docker_ps_task(task_family)}` #{command}"
20
+ def execute(task_family, ip, command, user = 'root')
21
+ cmd = "docker exec -i -t -u #{user} `#{docker_ps_task(task_family)}` #{command}"
22
22
  Open3.popen2e(ssh_cmd(ip) + " '#{cmd}' ") do |stdin, stdout, stderr, status_thread|
23
23
  stdout.each_line do |line|
24
24
  puts line
@@ -27,8 +27,8 @@ module EcsCmd
27
27
  end
28
28
 
29
29
  # used to open a shell within a container?
30
- def shell(task_family, ip, shell='bash')
31
- cmd = "docker exec -i -t `#{docker_ps_task(task_family)}` #{shell}"
30
+ def shell(task_family, ip, shell = 'bash', user = 'root')
31
+ cmd = "docker exec -i -t -u #{user} `#{docker_ps_task(task_family)}` #{shell}"
32
32
  exec(ssh_cmd(ip) + " '#{cmd}' ")
33
33
  end
34
34
 
@@ -1,3 +1,3 @@
1
1
  module EcsCmd
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs_cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schaaff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-10 00:00:00.000000000 Z
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ec2
@@ -134,6 +134,7 @@ files:
134
134
  - ".rspec"
135
135
  - ".rubocop.yml"
136
136
  - ".travis.yml"
137
+ - CHANGELOG.md
137
138
  - CODE_OF_CONDUCT.md
138
139
  - Gemfile
139
140
  - Gemfile.lock