11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/vagrant/docker_load/command.rb', line 11
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant docker-load src-img dst-img"
o.separator ""
end
src_img, dst_img = parse_options(opts)
return if dst_img.nil?
src = Tempfile.new("vagrant-docker_load")
run("docker save -o #{src.path} #{src_img}")
with_target_vms(nil) do |machine|
ssh_info = machine.ssh_info
raise Vagrant::Errors::SSHNotReady if ssh_info.nil?
log_level = ssh_info[:log_level] || "FATAL"
args = [
"-p", ssh_info[:port].to_s,
"-o", "LogLevel=#{log_level}"]
if ssh_info[:verify_host_key] == :never || !ssh_info[:verify_host_key]
args += [
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null"]
end
if ssh_info[:proxy_command]
args += ["-o", "ProxyCommand=#{ssh_info[:proxy_command]}"]
end
if ssh_info[:private_key_path]
ssh_info[:private_key_path].each do |path|
args += ["-i", path]
end
end
args += ["#{ssh_info[:username]}@#{ssh_info[:host]}"]
ssh_command = ["ssh", args]
load_command = ssh_command + ["sudo", "docker", "load"]
Open3.pipeline(load_command.join(" "), :in => src.path)
tag_command = ssh_command + ["sudo", "docker", "tag", src_img, dst_img]
system(tag_command.join(" "))
end
end
|