10
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/vmc_knife/vmc_helper.rb', line 10
def self.static_upload_app_bits(client,appname, path)
display "Uploading Application #{appname} from #{path}:"
upload_file, file = "#{Dir.tmpdir}/#{appname}.zip", nil
FileUtils.rm_f(upload_file)
explode_dir = "#{Dir.tmpdir}/.vmc_#{appname}_files"
FileUtils.rm_rf(explode_dir)
Dir.chdir(path) do
if war_file = Dir.glob('*.war').first
puts "Exploding the war"
VMC::Cli::ZipUtil.unpack(war_file, explode_dir)
puts "Done Exploding the war"
else
puts "Copying the files"
FileUtils.mkdir(explode_dir)
files = Dir.glob('{*,.[^\.]*}')
files.delete('.git') if files
FileUtils.cp_r(files, explode_dir)
puts "Done copying the files"
end
display ' Checking for available resources: ', false
fingerprints = []
total_size = 0
puts "About to compute the fingerprints"
resource_files = Dir.glob("#{explode_dir}/**/*", File::FNM_DOTMATCH)
resource_files.each do |filename|
next if (File.directory?(filename) || !File.exists?(filename))
fingerprints << {
:size => File.size(filename),
:sha1 => Digest::SHA1.file(filename).hexdigest,
:fn => filename
}
total_size += File.size(filename)
end
puts "Finished computing the fingerprints"
if (total_size > (64*1024)) puts "Invoking check_resources with the fingerprints"
appcloud_resources = client.check_resources(fingerprints)
end
display 'OK'.green
if appcloud_resources
display ' Processing resources: ', false
appcloud_resources.each do |resource|
FileUtils.rm_f resource[:fn]
resource[:fn].sub!("#{explode_dir}/", '')
end
display 'OK'.green
end
unless VMC::Cli::ZipUtil.get_files_to_pack(explode_dir).empty?
display ' Packing application: ', false
VMC::Cli::ZipUtil.pack(explode_dir, upload_file)
display 'OK'.green
upload_size = File.size(upload_file);
if upload_size > 1024*1024
upload_size = (upload_size/(1024.0*1024.0)).round.to_s + 'M'
elsif upload_size > 0
upload_size = (upload_size/1024.0).round.to_s + 'K'
end
else
upload_size = '0K'
end
upload_str = " Uploading (#{upload_size}): "
display upload_str, false
unless VMC::Cli::ZipUtil.get_files_to_pack(explode_dir).empty?
VMC::Cli::Command::FileWithPercentOutput.display_str = upload_str
VMC::Cli::Command::FileWithPercentOutput.upload_size = File.size(upload_file);
file = VMC::Cli::Command::FileWithPercentOutput.open(upload_file, 'rb')
end
puts "client.upload_app about to start"
retries = 5
begin
client.upload_app(appname, file, appcloud_resources)
rescue Exception => e
retry if (retries -= 1) > 0
end
puts "Done client.upload_app"
display 'OK'.green if VMC::Cli::ZipUtil.get_files_to_pack(explode_dir).empty?
display 'Push Status: ', false
display 'OK'.green
end
ensure
FileUtils.rm_f(upload_file) if upload_file
FileUtils.rm_rf(explode_dir) if explode_dir
end
|