knuckle_cluster 1.4.0 → 2.0.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: 78dfb68000ce016055de2e6a637eba4ac1f0c1e5
4
- data.tar.gz: 921123b27124c87bdfd3c3c7c31a7f7073db1e8a
3
+ metadata.gz: 59963fda23e1d0884eac11bf2a2847143e401bdc
4
+ data.tar.gz: d928d2f5075505884aa89f32ebbdb62acd66b0a9
5
5
  SHA512:
6
- metadata.gz: ad430a1a5c47d5674c3dccf646c7dfe315618733680d1b2946f4391cb63e02b5097887335b52ffc88408470f31c4b1f6395ff2e1c49bbabaa0c5da760aa5c63b
7
- data.tar.gz: 1f21a272f73cf5815c3e4eaed44e367c30df0f443feb89150634e63ae05173e523bbea14a996c937398d8b639ff6c202c9fdac3a20a3b9add941b94b161c0e17
6
+ metadata.gz: ba13719e348fd5fa75ed0de38820e37e1629d3992c747e5a9d61a2f9ec71550923b3b1ce98671749b1bf329be615caa826a4f57fbafc1a40597312b3fa97791d
7
+ data.tar.gz: c42358f506487275be118c2654f58167fc0233a6c366c9ec39e1597e4bebcd691688cc17c0988310c1ede496dcbee305adf2af5778fd2237319627d911ab8350
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [2.0.0] - 2018-03-27
9
+ Refactor SCP implementation to use new syntax
10
+ Allow SCP copy files FROM agents or containers
data/README.md CHANGED
@@ -102,6 +102,7 @@ knuckle_cluster CLUSTER_PROFILE logs CONTAINER_NAME - tail the logs for a contai
102
102
  knuckle_cluster CLUSTER_PROFILE CONTAINER_NAME [OPTIONAL COMMANDS] - connect to a container and start a shell or run a command
103
103
  knuckle_cluster CLUSTER_PROFILE SHORTCUT_NAME - run a shortcut defined in your knuckle_cluster configuration
104
104
  knuckle_cluster CLUSTER_PROFILE tunnel TUNNEL_NAME - open a tunnel defined in your knuckle_cluster configuration
105
+ knuckle_cluster CLUSTER_PROFILE scp source destination - copied a file via scp to or from a container or agent. Use container:<location> or agent:<location>
105
106
  ```
106
107
 
107
108
  ### Rakefile usage
@@ -203,6 +204,22 @@ If you wish to see what instances are running within a spot fleet, KnuckleCluste
203
204
  ## AutoScaling Groups
204
205
  If you wish to see what instances are running within an ASG, KnuckleCluster can do that too!. In your config, use `asg_name` instead of `cluster_name`. Note that the `containers` command will not work when invoking (use `agents` instead).
205
206
 
207
+ ## SCP
208
+ You can use Knuckle Cluster to copy files in and out of agents or containers. Note that this will only work where one of the source or destination is your local machine, copying between containers is not yet supported. Use a syntax similar to existing `scp` syntax when specifying a source or destination, but use the keyword `container` or `agent` for the remote. When using one of these keywords, you will be prompted as to which agent/container you wish to use.
209
+ ```
210
+ #Copy some_file.txt into a container at /app/some_file.txt
211
+ knuckle_cluster super_platform scp ./some_file.txt container:/app/some_file.txt
212
+
213
+ #Copy /app/some_file.txt from a remote container to ./some_file.txt on your local machine
214
+ knuckle_cluster super_platform scp container:/app/some_file.txt ./some_file.txt
215
+
216
+ #Copy some_file.txt into an agent at ~/some_file.txt
217
+ knuckle_cluster super_platform scp ./some_file.txt agent:~/some_file.txt
218
+
219
+ #Copy /app/some_file.txt from a remote container to ./some_file.txt on your local machine
220
+ knuckle_cluster super_platform scp agent:~/some_file.txt ./some_file.txt
221
+ ```
222
+
206
223
  ## Maintainer
207
224
  [Envato](https://github.com/envato)
208
225
 
data/bin/knuckle_cluster CHANGED
@@ -12,7 +12,7 @@ if ARGV.count < 2
12
12
  knuckle_cluster CLUSTER_PROFILE CONTAINER_NAME [OPTIONAL COMMANDS] - connect to a container and start a shell or run a command
13
13
  knuckle_cluster CLUSTER_PROFILE SHORTCUT_NAME - run a shortcut defined in your knuckle_cluster configuration
14
14
  knuckle_cluster CLUSTER_PROFILE tunnel TUNNEL_NAME - open a tunnel defined in your knuckle_cluster configuration
15
- knuckle_cluster CLUSTER_PROFILE scp [agent|container] source_file destination - copies a file from your local machine to a destaination container or agent
15
+ knuckle_cluster CLUSTER_PROFILE scp source destination - copied a file via scp to or from a container or agent. Use container:<location> or agent:<location>
16
16
  USAGE
17
17
  exit
18
18
  end
@@ -37,11 +37,7 @@ elsif ARGV[1] == 'logs'
37
37
  elsif ARGV[1] == 'tunnel'
38
38
  kc.open_tunnel(name: ARGV[2])
39
39
  elsif ARGV[1] == 'scp'
40
- if ARGV[2] == 'agent'
41
- kc.scp_to_agent(source: ARGV[3], destination: ARGV[4])
42
- elsif ARGV[2] == 'container'
43
- kc.scp_to_container(source: ARGV[3], destination: ARGV[4])
44
- end
40
+ kc.initiate_scp(source: ARGV[2], destination: ARGV[3])
45
41
  else
46
42
  command = ARGV.drop(2)
47
43
  if command.any?
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.14"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "pry", "~> 0.11"
25
26
 
26
27
  spec.add_dependency 'aws-sdk-core', '~> 3'
27
28
  spec.add_dependency 'aws-sdk-ec2', '~> 1'
@@ -1,6 +1,7 @@
1
1
  require 'knuckle_cluster/asg_instance_registry'
2
2
  require 'knuckle_cluster/ecs_agent_registry'
3
3
  require 'knuckle_cluster/spot_request_instance_registry'
4
+ require "knuckle_cluster/scp"
4
5
  require "knuckle_cluster/version"
5
6
  require "knuckle_cluster/configuration"
6
7
 
@@ -16,6 +17,8 @@ module KnuckleCluster
16
17
  class << self
17
18
  extend Forwardable
18
19
 
20
+ include Scp
21
+
19
22
  def new(
20
23
  cluster_name: nil,
21
24
  spot_request_id: nil,
@@ -68,27 +71,6 @@ module KnuckleCluster
68
71
  run_command_in_container(container: container, command: command)
69
72
  end
70
73
 
71
- def scp_to_agent(source:, destination:, agent: nil)
72
- agent ||= select_agent
73
- target_ip = bastion ? agent.private_ip : agent.public_ip
74
- command = generate_scp_connection_string(agent: agent)
75
- command += " #{source}"
76
- command += " #{ssh_username}@#{target_ip}:#{destination}"
77
- system(command)
78
- puts "Done!"
79
- end
80
-
81
- def scp_to_container(source:, destination:)
82
- container = select_container
83
- agent = container.task.agent
84
- tmp_destination_file = '~/tmp_kc.tmp'
85
- scp_to_agent(source: source, agent: agent, destination: tmp_destination_file)
86
- container_id = get_container_id_command(container.name)
87
- subcommand = "#{'sudo ' if sudo}docker cp #{tmp_destination_file} \\`#{container_id}\\`:#{destination} && rm #{tmp_destination_file}"
88
- run_command_in_agent(agent: agent, command: subcommand)
89
- puts "Done!"
90
- end
91
-
92
74
  def container_logs(name:)
93
75
  container = find_container(name: name)
94
76
  subcommand = "#{'sudo ' if sudo}docker logs -f \\`#{get_container_id_command(container.name)}\\`"
@@ -203,14 +185,6 @@ module KnuckleCluster
203
185
  end
204
186
  end
205
187
 
206
- def generate_scp_connection_string(agent:)
207
- ip = bastion ? agent.private_ip : agent.public_ip
208
- command = "scp"
209
- command += " -i #{rsa_key_location}" if rsa_key_location
210
- command += " -o ProxyCommand='ssh -qxT #{bastion} nc #{ip} 22'" if bastion
211
- command
212
- end
213
-
214
188
  def generate_connection_string(agent:, subcommand: nil, port_forward: nil)
215
189
  ip = bastion ? agent.private_ip : agent.public_ip
216
190
  command = "ssh #{ip} -l#{ssh_username}"
@@ -0,0 +1,81 @@
1
+ module KnuckleCluster
2
+ module Scp
3
+ def initiate_scp(source:, destination:)
4
+ if source.start_with?('agent') || destination.start_with?('agent')
5
+ agent = select_agent
6
+
7
+ if source.start_with?('agent')
8
+ source = generate_agent_scp_string(source, agent)
9
+ elsif destination.start_with?('agent')
10
+ destination = generate_agent_scp_string(destination, agent)
11
+ end
12
+
13
+ scp_with_agent(source: source, destination: destination, agent: agent)
14
+ elsif source.start_with?('container') || destination.start_with?('container')
15
+ container = select_container
16
+ agent = container.task.agent
17
+ if source.start_with?('container')
18
+ #This is SCP FROM container
19
+ source = source.split(':').last
20
+ tmp_source_file = '~/tmp_kc.tmp'
21
+ container_id = get_container_id_command(container.name)
22
+
23
+ subcommand = "#{'sudo ' if sudo}docker cp \\`#{container_id}\\`:#{source} #{tmp_source_file}"
24
+ run_command_in_agent(agent: agent, command: subcommand)
25
+
26
+ scp_source = generate_agent_scp_string(tmp_source_file, agent)
27
+ scp_with_agent(source: scp_source, agent: agent, destination: destination)
28
+
29
+ subcommand = "#{'sudo ' if sudo} rm #{tmp_source_file}"
30
+ run_command_in_agent(agent: agent, command: subcommand)
31
+
32
+ puts "Done!"
33
+ elsif destination.start_with?('container')
34
+ #SCP TO container
35
+ destination = destination.split(':').last
36
+ tmp_destination_file = '~/tmp_kc.tmp'
37
+ tmp_destination = generate_agent_scp_string(tmp_destination_file, agent)
38
+ scp_with_agent(source: source, agent: agent, destination: tmp_destination)
39
+ container_id = get_container_id_command(container.name)
40
+ subcommand = "#{'sudo ' if sudo}docker cp #{tmp_destination_file} \\`#{container_id}\\`:#{destination} && rm #{tmp_destination_file}"
41
+ run_command_in_agent(agent: agent, command: subcommand)
42
+ puts "Done!"
43
+ end
44
+ end
45
+ end
46
+
47
+ def generate_agent_scp_string(input, agent)
48
+ split_input = input.split(':')
49
+ location = split_input.last
50
+ target_ip = bastion ? agent.private_ip : agent.public_ip
51
+ return "#{ssh_username}@#{target_ip}:#{location}"
52
+ end
53
+
54
+ def scp_with_agent(source:, destination:, agent: nil)
55
+ command = generate_scp_connection_string(agent: agent)
56
+ command += " #{source}"
57
+ command += " #{destination}"
58
+ system(command)
59
+ puts "Done!"
60
+ end
61
+
62
+ def generate_scp_connection_string(agent:)
63
+ ip = bastion ? agent.private_ip : agent.public_ip
64
+ command = "scp"
65
+ command += " -i #{rsa_key_location}" if rsa_key_location
66
+ command += " -o ProxyCommand='ssh -qxT #{bastion} nc #{ip} 22'" if bastion
67
+ command
68
+ end
69
+
70
+ def scp_to_container(source:, destination:)
71
+ container = select_container
72
+ agent = container.task.agent
73
+ tmp_destination_file = '~/tmp_kc.tmp'
74
+ scp_to_agent(source: source, agent: agent, destination: tmp_destination_file)
75
+ container_id = get_container_id_command(container.name)
76
+ subcommand = "#{'sudo ' if sudo}docker cp #{tmp_destination_file} \\`#{container_id}\\`:#{destination} && rm #{tmp_destination_file}"
77
+ run_command_in_agent(agent: agent, command: subcommand)
78
+ puts "Done!"
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
1
  module KnuckleCluster
2
- VERSION = '1.4.0'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knuckle_cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.11'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: aws-sdk-core
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +148,7 @@ files:
134
148
  - ".gitignore"
135
149
  - ".rspec"
136
150
  - ".travis.yml"
151
+ - CHANGELOG.md
137
152
  - CODE_OF_CONDUCT.md
138
153
  - Gemfile
139
154
  - LICENSE.txt
@@ -149,6 +164,7 @@ files:
149
164
  - lib/knuckle_cluster/configuration.rb
150
165
  - lib/knuckle_cluster/container.rb
151
166
  - lib/knuckle_cluster/ecs_agent_registry.rb
167
+ - lib/knuckle_cluster/scp.rb
152
168
  - lib/knuckle_cluster/spot_request_instance_registry.rb
153
169
  - lib/knuckle_cluster/task.rb
154
170
  - lib/knuckle_cluster/task_registry.rb