knuckle_cluster 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59a86619f9fb8211ea0f2ff5c7f63c376c518594
4
- data.tar.gz: 63403a1079066e89441bc79add6434376014f39f
3
+ metadata.gz: 78dfb68000ce016055de2e6a637eba4ac1f0c1e5
4
+ data.tar.gz: 921123b27124c87bdfd3c3c7c31a7f7073db1e8a
5
5
  SHA512:
6
- metadata.gz: 9bf7bf698d1c171c7f1d014c8776dd2d9bc66c98c2f85a964a05ae3d444c4a58fdb751c00de0ac135f59dcd4a3be902fb3d0db5ddde3978d9beb5149a508f530
7
- data.tar.gz: d3d36dfe6b4681b99365393ca25705c93a999588428cdc2b0488e333da244c729de19abb9b6a78f01af04dde6bbda103a1338214f6d96c3e7a5ef759015e48e3
6
+ metadata.gz: ad430a1a5c47d5674c3dccf646c7dfe315618733680d1b2946f4391cb63e02b5097887335b52ffc88408470f31c4b1f6395ff2e1c49bbabaa0c5da760aa5c63b
7
+ data.tar.gz: 1f21a272f73cf5815c3e4eaed44e367c30df0f443feb89150634e63ae05173e523bbea14a996c937398d8b639ff6c202c9fdac3a20a3b9add941b94b161c0e17
data/bin/knuckle_cluster CHANGED
@@ -12,6 +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
16
  USAGE
16
17
  exit
17
18
  end
@@ -35,6 +36,12 @@ elsif ARGV[1] == 'logs'
35
36
  kc.container_logs(name: ARGV[2])
36
37
  elsif ARGV[1] == 'tunnel'
37
38
  kc.open_tunnel(name: ARGV[2])
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
38
45
  else
39
46
  command = ARGV.drop(2)
40
47
  if command.any?
@@ -68,6 +68,27 @@ module KnuckleCluster
68
68
  run_command_in_container(container: container, command: command)
69
69
  end
70
70
 
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
+
71
92
  def container_logs(name:)
72
93
  container = find_container(name: name)
73
94
  subcommand = "#{'sudo ' if sudo}docker logs -f \\`#{get_container_id_command(container.name)}\\`"
@@ -89,7 +110,7 @@ module KnuckleCluster
89
110
  :region, :bastion, :rsa_key_location, :ssh_username,
90
111
  :sudo, :aws_vault_profile, :shortcuts, :tunnels
91
112
 
92
- def select_agent(auto:)
113
+ def select_agent(auto: false)
93
114
  return agents.first if auto
94
115
 
95
116
  puts "\nListing Agents"
@@ -100,7 +121,7 @@ module KnuckleCluster
100
121
  agents[STDIN.gets.strip.to_i - 1]
101
122
  end
102
123
 
103
- def select_container(auto:)
124
+ def select_container(auto: false)
104
125
  return containers.first if auto
105
126
 
106
127
  puts "\nListing Containers"
@@ -182,6 +203,14 @@ module KnuckleCluster
182
203
  end
183
204
  end
184
205
 
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
+
185
214
  def generate_connection_string(agent:, subcommand: nil, port_forward: nil)
186
215
  ip = bastion ? agent.private_ip : agent.public_ip
187
216
  command = "ssh #{ip} -l#{ssh_username}"
@@ -1,3 +1,3 @@
1
1
  module KnuckleCluster
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.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.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-30 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  requirements: []
175
175
  rubyforge_project:
176
- rubygems_version: 2.6.11
176
+ rubygems_version: 2.6.13
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: Handy cluster tool