mofa 0.2.6 → 0.2.7
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.
- data/lib/mofa/upload_cmd.rb +33 -16
- data/lib/mofa/version.rb +1 -1
- metadata +1 -1
data/lib/mofa/upload_cmd.rb
CHANGED
@@ -40,36 +40,53 @@ class UploadCmd < MofaCmd
|
|
40
40
|
|
41
41
|
def upload_cookbook_pkg
|
42
42
|
puts "Will use ssh_user #{Mofa::Config.config['binrepo_ssh_user']} and ssh_key_file #{Mofa::Config.config['binrepo_ssh_keyfile']}"
|
43
|
-
puts "Uploading cookbook pkg #{cookbook.pkg_name} to binrepo import folder #{Mofa::Config.config['binrepo_host']}:#{Mofa::Config.config['binrepo_import_dir']}..."
|
44
43
|
|
45
44
|
fail unless binrepo_up?
|
46
45
|
import_dir = Mofa::Config.config['binrepo_import_dir']
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
begin
|
48
|
+
# if the upload target is not a proper binrepo with a designated ".../import" folder -> create the "right" folder structure
|
49
|
+
unless Mofa::Config.config['binrepo_import_dir'].match(/import$/)
|
50
|
+
Net::SSH.start(Mofa::Config.config['binrepo_host'],
|
51
|
+
Mofa::Config.config['binrepo_ssh_user'],
|
52
|
+
:keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
|
53
|
+
:port => Mofa::Config.config['binrepo_ssh_port'],
|
54
|
+
:verbose => :error,
|
55
|
+
:use_agent => false) do |ssh|
|
56
|
+
puts "Remotely creating target dir \"#{import_dir}/#{cookbook.name}/#{cookbook.version}\""
|
57
|
+
out = ssh_exec!(ssh, "[ -d #{import_dir}/#{cookbook.name}/#{cookbook.version} ] || mkdir -p #{import_dir}/#{cookbook.name}/#{cookbook.version}")
|
58
|
+
fail "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
59
|
+
import_dir = "#{import_dir}/#{cookbook.name}/#{cookbook.version}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# only upload if the file does not exist on the target host:
|
64
|
+
already_uploaded = false
|
50
65
|
Net::SSH.start(Mofa::Config.config['binrepo_host'],
|
51
66
|
Mofa::Config.config['binrepo_ssh_user'],
|
52
67
|
:keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
|
53
68
|
:port => Mofa::Config.config['binrepo_ssh_port'],
|
54
69
|
:verbose => :error,
|
55
70
|
:use_agent => false) do |ssh|
|
56
|
-
|
57
|
-
out = ssh_exec!(ssh, "[ -d #{import_dir}/#{cookbook.name}/#{cookbook.version} ] || mkdir -p #{import_dir}/#{cookbook.name}/#{cookbook.version}")
|
71
|
+
out = ssh_exec!(ssh, "[ -f #{import_dir}/#{cookbook.name}/#{cookbook.version}/#{cookbook.pkg_name} ] || echo -n already_exists")
|
58
72
|
fail "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
59
|
-
|
73
|
+
already_uploaded = true if out[1] == 'already_exists'
|
60
74
|
end
|
61
|
-
end
|
62
75
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
76
|
+
unless already_uploaded
|
77
|
+
puts "Uploading cookbook pkg #{cookbook.pkg_name} to binrepo import folder #{Mofa::Config.config['binrepo_host']}:#{Mofa::Config.config['binrepo_import_dir']}..."
|
78
|
+
Net::SFTP.start(Mofa::Config.config['binrepo_host'],
|
79
|
+
Mofa::Config.config['binrepo_ssh_user'],
|
80
|
+
:keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
|
81
|
+
:port => Mofa::Config.config['binrepo_ssh_port'],
|
82
|
+
:verbose => :error,
|
83
|
+
:use_agent => false) do |sftp|
|
84
|
+
sftp.upload!("#{cookbook.pkg_dir}/#{cookbook.pkg_name}", "#{import_dir}/#{cookbook.pkg_name}")
|
85
|
+
end
|
86
|
+
puts "OK."
|
87
|
+
else
|
88
|
+
puts "Cookbook pkg #{cookbook.pkg_name} already exists in the binrepo. Will NOT upload it again."
|
71
89
|
end
|
72
|
-
puts "OK."
|
73
90
|
rescue RuntimeError => e
|
74
91
|
puts "Error: #{e.message}"
|
75
92
|
raise "Failed to upload cookbook #{cookbook.name}!"
|
data/lib/mofa/version.rb
CHANGED