@@ -60,7 +60,7 @@ def is_configured?
60
60
@is_configured || false
61
61
end
62
62
63
- def extract
63
+ def extract_all
64
64
65
65
# For each container, process extractions
66
66
# Containers are defined in compose, extractions are defined at root under container name e.g.:
@@ -87,22 +87,26 @@ def extract
87
87
next
88
88
end
89
89
90
- extractions . each do |extraction |
91
- if extraction =~ /:/
92
- tokens = extraction . split ( ':' )
93
- from = tokens [ 0 ]
94
- to = tokens [ 1 ]
95
- else
96
- from = extraction
97
- to = '.'
98
- end
90
+ extract ( container , service_name , extractions )
91
+ end
92
+ end
99
93
100
- puts "\n Extracting #{ service_name } #{ from } to #{ to } "
101
- begin
102
- extract_files ( container , from , to )
103
- rescue => e
104
- puts e . message
105
- end
94
+ def extract ( container , service_name , extractions )
95
+ extractions . each do |extraction |
96
+ if extraction =~ /:/
97
+ tokens = extraction . split ( ':' )
98
+ from = tokens [ 0 ]
99
+ to = tokens [ 1 ]
100
+ else
101
+ from = extraction
102
+ to = '.'
103
+ end
104
+
105
+ puts "\n Extracting #{ service_name } #{ from } to #{ to } "
106
+ begin
107
+ extract_files ( container , from , to )
108
+ rescue => e
109
+ puts e . message
106
110
end
107
111
end
108
112
end
@@ -207,28 +211,9 @@ def bash_connect(service_name)
207
211
208
212
def run_ssh_agent
209
213
return if @config [ :'ssh-agent' ] . nil?
210
-
211
- ssh_agent_name = @config . ssh_agent_name
212
- begin
213
- Docker ::Container . get ( ssh_agent_name )
214
- puts "Gem data volume container #{ ssh_agent_name } already exists."
215
- rescue Docker ::Error ::NotFoundError => e
216
- exec "docker run -d --name=#{ ssh_agent_name } #{ ssh_agent_image } "
217
- puts "SSH Agent forwarding container #{ ssh_agent_name } running."
218
- end
219
-
220
- ssh_base_cmd = "docker run --rm --volumes-from=#{ ssh_agent_name } -v ~/.ssh:/ssh #{ ssh_agent_image } "
221
-
222
- ssh_keys = @config [ :'ssh-agent' ] [ :keys ]
223
- puts "Forwarding SSH key(s): #{ ssh_keys . join ( ',' ) } into container(s): #{ @config [ :'ssh-agent' ] [ :containers ] . join ( ',' ) } "
224
- ssh_keys . each do |key_file_name |
225
- local_key_file = "#{ ENV [ 'HOME' ] } /.ssh/#{ key_file_name } "
226
- raise "Local key file #{ local_key_file } doesn't exist." unless File . exists? local_key_file
227
- exec "#{ ssh_base_cmd } ssh-add /ssh/#{ key_file_name } "
228
- end
229
-
230
- # add known hosts
231
- exec "#{ ssh_base_cmd } cp /ssh/known_hosts /root/.ssh/known_hosts"
214
+ run_ssh_agent_daemon
215
+ ssh_add_keys
216
+ ssh_add_known_hosts
232
217
end
233
218
234
219
def rm_ssh_agent
@@ -375,6 +360,36 @@ def kill(container)
375
360
end
376
361
end
377
362
363
+ def ssh_add_known_hosts
364
+ exec "#{ ssh_base_cmd } cp /ssh/known_hosts /root/.ssh/known_hosts"
365
+ end
366
+
367
+ def ssh_base_cmd
368
+ ssh_agent_name = @config . ssh_agent_name
369
+ "docker run --rm --volumes-from=#{ ssh_agent_name } -v ~/.ssh:/ssh #{ ssh_agent_image } "
370
+ end
371
+
372
+ def ssh_add_keys
373
+ ssh_keys = @config [ :'ssh-agent' ] [ :keys ]
374
+ puts "Forwarding SSH key(s): #{ ssh_keys . join ( ',' ) } into container(s): #{ @config [ :'ssh-agent' ] [ :containers ] . join ( ',' ) } "
375
+ ssh_keys . each do |key_file_name |
376
+ local_key_file = "#{ ENV [ 'HOME' ] } /.ssh/#{ key_file_name } "
377
+ raise "Local key file #{ local_key_file } doesn't exist." unless File . exists? local_key_file
378
+ exec "#{ ssh_base_cmd } ssh-add /ssh/#{ key_file_name } "
379
+ end
380
+ end
381
+
382
+ def run_ssh_agent_daemon
383
+ ssh_agent_name = @config . ssh_agent_name
384
+ begin
385
+ Docker ::Container . get ( ssh_agent_name )
386
+ puts "Gem data volume container #{ ssh_agent_name } already exists."
387
+ rescue Docker ::Error ::NotFoundError => e
388
+ exec "docker run -d --name=#{ ssh_agent_name } #{ ssh_agent_image } "
389
+ puts "SSH Agent forwarding container #{ ssh_agent_name } running."
390
+ end
391
+ end
392
+
378
393
def rm_v ( container )
379
394
container . remove ( v : true , force : true )
380
395
end
0 commit comments