broadside 3.2.0 → 3.3.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: 7f38120e5ed461522f423547c8f4cb6cb1d80dc2
4
- data.tar.gz: 46b2213e403886e691880e640752fd2791bc0b69
3
+ metadata.gz: 899d3a593ec0af2a6d0bf8ac1d57c70effc37ca5
4
+ data.tar.gz: 51a9d9276948eaf1beef32e2392bb66b0d4bd372
5
5
  SHA512:
6
- metadata.gz: 452b96e5e2567b1e954897c3652742199b33402e718c9d0cb63131b1756691ed7f4c9895a06695dce6ee75046042290f7b6c7f015d6d9f057fda561b879e5467
7
- data.tar.gz: 783ae62663751c666413f2a2a72d2ba6d745e419254c0c8fccd2769cb415686cc4378b00b6da3298eaf11549004c2fdb63445e9496d84027c76c5a0d03d0b112
6
+ metadata.gz: 6c828f7cf4ae5c293265af3e8a40955695fd3cd6b346a5628eb716a253fb55216dfb57ca55c34fccc3c98d7b965d44810ade651ed513486b9b8b217cefcaadf7
7
+ data.tar.gz: fcd3efac4301a37d48dab29b91df591a349b2cdd953dbb015d69008c7bd4bd3cbaa7d660448c63f49c8a55b6558c0814c3161deec48bcdafda5fb598999f8ae6
@@ -1,3 +1,9 @@
1
+ # 3.3.0
2
+ -- Add `execute` command to execute arbitrary bash inside a running container
3
+ -- Add `--all` flag to `execute` to run a command on all containers
4
+ -- Always turn on TTY interaction when running remote commands.
5
+ -- Fix bug with command being an array instead of string
6
+
1
7
  # 3.2.0
2
8
  -- Add ability to execute a bash command on a container
3
9
  -- Output actual bash command being run when log level is debug.
data/README.md CHANGED
@@ -15,7 +15,7 @@ Broadside does _not_ attempt to handle operational tasks like infrastructure set
15
15
  - **Inject** environment variables into ECS containers from local configuration files
16
16
  - **Launch a bash shell** on container in the cluster
17
17
  - **SSH** directly onto a host running a container
18
- - **Execute** an arbitrary shell command on a container
18
+ - **Execute** an arbitrary shell command on a container (or all containers)
19
19
  - **Tail logs** of a running container
20
20
  - **Scale** an existing deployment on the fly
21
21
 
@@ -31,17 +31,17 @@ Broadside.configure do |config|
31
31
  config.targets = {
32
32
  production_web: {
33
33
  scale: 7,
34
- command: ['bundle', 'exec', 'unicorn', '-c', 'config/unicorn.conf.rb'],
34
+ command: %w(bundle exec unicorn -c config/unicorn.conf.rb),
35
35
  env_file: '.env.production'
36
36
  predeploy_commands: [
37
- ['bundle', 'exec', 'rake', 'db:migrate'],
38
- ['bundle', 'exec', 'rake', 'data:migrate']
37
+ %w(bundle exec rake db:migrate),
38
+ %w(bundle exec rake data:migrate)
39
39
  ]
40
40
  },
41
41
  # If you have multiple images or clusters, you can configure them per target
42
42
  staging_web: {
43
43
  scale: 1,
44
- command: ['bundle', 'exec', 'puma'],
44
+ command: %w(bundle exec puma),
45
45
  env_file: '.env.staging',
46
46
  tag: 'latest', # Set a default tag for this target
47
47
  cluster: 'staging-cluster', # Overrides config.aws.ecs_default_cluster
@@ -49,7 +49,7 @@ Broadside.configure do |config|
49
49
  },
50
50
  json_stream: {
51
51
  scale: 1,
52
- command: ['java', '-cp', '*:.', 'path.to.MyClass'],
52
+ command: %w(java -cp *:. path.to.MyClass),
53
53
  # This target has a task_definition and service config which you use to bootstrap a new AWS Service
54
54
  service_config: { deployment_configuration: { minimum_healthy_percent: 0.5 } },
55
55
  task_definition_config: { container_definitions: [ { cpu: 1, memory: 2000, } ] }
@@ -1,3 +1,4 @@
1
+ require 'open3'
1
2
  require 'pp'
2
3
  require 'shellwords'
3
4
  require 'tty-table'
@@ -108,13 +109,24 @@ module Broadside
108
109
  end
109
110
 
110
111
  def bash(options)
111
- command = options[:command] || BASH
112
112
  target = Broadside.config.get_target_by_name!(options[:target])
113
+ cmd = "docker exec -i -t `#{docker_ps_cmd(target.family)}` #{BASH}"
113
114
  ip = get_running_instance_ip!(target, *options[:instance])
115
+ info "Executing #{BASH} on running container at #{ip}..."
116
+
117
+ system_exec(Broadside.config.ssh_cmd(ip, tty: true) + " '#{cmd}'")
118
+ end
119
+
120
+ def execute(options)
121
+ command = options[:command]
122
+ target = Broadside.config.get_target_by_name!(options[:target])
114
123
  cmd = "docker exec -i -t `#{docker_ps_cmd(target.family)}` #{command}"
115
- info "Executing #{command} on running container at #{ip}..."
124
+ ips = options[:all] ? running_instances(target) : [get_running_instance_ip!(target, *options[:instance])]
116
125
 
117
- system_exec(Broadside.config.ssh_cmd(ip, tty: command == BASH) + " '#{cmd}'")
126
+ ips.each do |ip|
127
+ info "Executing '#{command}' on running container at #{ip}..."
128
+ Open3.popen3(Broadside.config.ssh_cmd(ip, tty: true) + " '#{cmd}'") { |_, stdout, _, _| puts stdout.read }
129
+ end
118
130
  end
119
131
 
120
132
  private
@@ -125,16 +137,20 @@ module Broadside
125
137
  end
126
138
 
127
139
  def get_running_instance_ip!(target, instance_index = 0)
128
- EcsManager.check_service_and_task_definition_state!(target)
129
- running_instances = EcsManager.get_running_instance_ips!(target.cluster, target.family)
140
+ instances = running_instances(target)
130
141
 
131
142
  begin
132
- running_instances.fetch(instance_index)
143
+ instances.fetch(instance_index)
133
144
  rescue IndexError
134
- raise Error, "There are only #{running_instances.size} instances; index #{instance_index} does not exist"
145
+ raise Error, "There are only #{instances.size} instances; index #{instance_index} does not exist"
135
146
  end
136
147
  end
137
148
 
149
+ def running_instances(target)
150
+ EcsManager.check_service_and_task_definition_state!(target)
151
+ EcsManager.get_running_instance_ips!(target.cluster, target.family)
152
+ end
153
+
138
154
  def docker_ps_cmd(family)
139
155
  "docker ps -n 1 --quiet --filter name=#{Shellwords.shellescape(family)}"
140
156
  end
@@ -91,19 +91,32 @@ command :ssh do |ssh|
91
91
  end
92
92
  end
93
93
 
94
- desc 'Establish a shell or run a bash command inside a running container.'
94
+ desc 'Establish a shell inside a running container.'
95
95
  command :bash do |bash|
96
96
  add_command_flags(bash)
97
97
 
98
- bash.desc 'bash command to run (wrap argument in quotes)'
99
- bash.arg_name 'BASH_COMMAND'
100
- bash.flag [:c, :command], type: Array
101
-
102
98
  bash.action do |_, options, _|
103
99
  Broadside::Command.bash(options)
104
100
  end
105
101
  end
106
102
 
103
+ desc 'Execute a bash command inside a running container.'
104
+ command :execute do |execute|
105
+ add_command_flags(execute)
106
+
107
+ execute.desc 'bash command to run (wrap argument in quotes)'
108
+ execute.arg_name 'BASH_COMMAND'
109
+ execute.flag [:c, :command], type: String, required: true
110
+
111
+ execute.desc 'run on all containers in series'
112
+ execute.arg_name 'ALL_CONTAINERS'
113
+ execute.switch :all, negatable: false
114
+
115
+ execute.action do |_, options, _|
116
+ Broadside::Command.execute(options)
117
+ end
118
+ end
119
+
107
120
  desc 'Deploy your application.'
108
121
  command :deploy do |d|
109
122
  d.desc 'Deploys WITHOUT running predeploy commands'
@@ -1,3 +1,3 @@
1
1
  module Broadside
2
- VERSION = '3.2.0'.freeze
2
+ VERSION = '3.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: broadside
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Leung
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-14 00:00:00.000000000 Z
12
+ date: 2017-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport