Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

151 lines (135 sloc) 5.117 kB
require 'yaml'
require 'fileutils'
require 'digest/md5'
require 'digest/sha1'
require 'tmpdir'
require 'erb'
update_steps = [#'tomcat:download',
#'tomcat:prepare',
#'tomcat:package',
#'tomcat:fingerprint',
'tomcat:install']
desc "Update Tomcat installation used by Cloud Foundry"
task :update => update_steps
namespace "tomcat" do
desc "Download Tomcat from an Apache mirror"
task :download do
puts "\nStarting Tomcat download"
manifest_file = "tomcat_manifest.yml"
@manifest = load_yaml(manifest_file)
@download_dest = File.join(Dir.tmpdir, "tomcat-v#{@manifest['version']}")
puts "\tDownloading Tomcat v#{@manifest['version']} from '#{@manifest['download_uri']}' to '#{@download_dest}'"
if File.exists?(@download_dest)
FileUtils.remove_dir(@download_dest)
end
FileUtils.mkdir_p(@download_dest)
Dir.chdir(@download_dest) do
system "wget -q #{@manifest['download_uri']}"
system "wget -q #{@manifest['download_uri']}.md5"
@download_file = @manifest['download_uri'].split("/").last
verify_download
end
puts "Tomcat download completed"
end
desc "Prepare Tomcat for Cloud Foundry"
task :prepare => 'tomcat:download' do
puts "\nPreparing Tomcat"
Dir.chdir(@download_dest) do
system "tar xzf #{@download_file}"
exp_dir = `tar ztf "#{@download_file}" | cut -f1 -d\/ | uniq`.strip
tomcat_dir = "tomcat"
FileUtils.mv exp_dir, tomcat_dir
@targetdir = File.join(@download_dest, tomcat_dir)
end
handle_replace_files
handle_clear_dirs
handle_remove_files
handle_add_jars
puts "Tomcat prepare completed"
end
desc "Generate the Tomcat for Cloud Foundry package"
task :package => 'tomcat:prepare' do
puts "\nGenerating Tomcat for Cloud Foundry package"
Dir.chdir(@download_dest) do
system "zip -q -r tomcat.zip tomcat"
end
puts "Tomcat for Cloud Foundry package generation completed"
end
desc "Generate SHA1 fingerprint of the Cloud Foundry Tomcat package"
task :fingerprint => 'tomcat:package' do
# Note: This fingerprint is used in a specific manner -
# A unit test in the CloudController component consults this fingerprint
# and verifies that it matches the fingerprint of the Tomcat package used
# by the CloudContoller for Java apps thus ensuring that the Tomcat package
# was not somehow modified outside of this update script.
puts "\nFingerprinting Tomcat prepared for Cloud Foundry"
target_file = File.join(@download_dest, "tomcat.zip")
digest = Digest::SHA1.file(target_file).hexdigest
puts "\tFingerprint of Tomcat package: '#{digest}'"
save_fingerprint digest
puts "Fingerprint of Tomcat for Cloud Foundry completed"
end
desc "Installing Tomcat into Cloud Foundry code-base"
task :install => 'tomcat:fingerprint' do
puts "\nInstalling Tomcat into CloudFoundry code-base"
source = File.join(@download_dest, "tomcat.zip")
dest = @manifest['destination']
puts "\tCopying Tomcat from '#{source}' to '#{dest}'"
FileUtils.copy(source, dest)
puts "Tomcat install into Cloud Foundry code-base completed\n"
end
def verify_download
puts "\tVerifying download"
# Note that we have to use MD5 here because that is the digest type
# published by Apache.
digest = Digest::MD5.file(@download_file).hexdigest
md5sum = IO.readlines("#{@download_file}.md5")[0].split[0]
raise "MD5Sum verification check failed" unless digest == md5sum
puts "\tDownload verification completed"
end
def handle_replace_files
@manifest['replace_files'].each do |file|
target_file = File.join(@targetdir, file)
source_file = File.join("resources", file)
puts "\tReplacing '#{target_file}' with '#{source_file}'"
FileUtils.remove(target_file)
FileUtils.copy(source_file, target_file)
end
end
def handle_clear_dirs
@manifest['clear_dirs'].each do |file|
target_file = File.join(@targetdir, file)
puts "\tClearing '#{target_file}'"
Dir.chdir target_file do
FileUtils.rm_r Dir.glob('*')
end
end
end
def handle_remove_files
@manifest['remove_files'].each do |file|
target_file = File.join(@targetdir, file)
puts "\tRemoving '#{target_file}'"
FileUtils.rm target_file
end
end
def handle_add_jars
@manifest['add_jars'].each do |file|
target_file = File.join(@targetdir, file)
source_file = File.join("resources", file)
puts "\tCopying jar '#{source_file}' to '#{target_file}'"
FileUtils.copy(source_file, target_file)
end
end
def save_fingerprint digest
digest_file = @manifest['digest']
puts "\tSaving fingerprint in '#{digest_file}'"
# Digest file follows the conventions as per the Apache Tomcat MD5 file
File.open(digest_file, 'w') {|f| f.puts("#{digest} *tomcat.zip") }
end
def load_yaml(path)
File.open(path, 'rb') do |fh|
yaml = ERB.new(fh.read).result(binding)
return YAML.load(yaml)
end
end
end
Jump to Line
Something went wrong with that request. Please try again.