class Vara::ProductArtifactZipper
Attributes
artifact_path[R]
product_contents[R]
Public Class Methods
new(artifact_path, product_contents, options = {})
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 10 def initialize(artifact_path, product_contents, options = {}) @artifact_path = artifact_path @product_contents = product_contents @options = options end
Public Instance Methods
zip!()
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 16 def zip! remove_previous_artifacts in_tmp_dir do copy_dirs_and_files create_zip! end end
Private Instance Methods
copy_and_validate_compiled_packages(product_metadata)
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 104 def copy_and_validate_compiled_packages(product_metadata) return unless product_contents.has_compiled_packages? FileUtils.mkdir('compiled_packages') FileUtils.cp(product_contents.compiled_packages_path, 'compiled_packages') ProductArtifactValidator.validate_file_checksum( product_metadata.compiled_packages_metadata, File.join('compiled_packages', product_metadata.compiled_packages_file) ) end
copy_and_validate_releases(product_metadata)
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 74 def copy_and_validate_releases(product_metadata) FileUtils.mkdir('releases') product_contents.release_paths.each do |release_path| if @options[:exclude_releases] FileUtils.touch("releases/#{File.basename(release_path)}") else FileUtils.cp(release_path, 'releases') end end return if @options[:exclude_releases] product_metadata.releases_metadata.each do |release_metadata| ProductArtifactValidator.validate_file_checksum( release_metadata, File.join('releases', release_metadata.basename) ) end end
copy_and_validate_stemcell(product_metadata)
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 94 def copy_and_validate_stemcell(product_metadata) FileUtils.mkdir('stemcells') FileUtils.cp(product_contents.stemcell_path, 'stemcells') ProductArtifactValidator.validate_file_checksum( product_metadata.stemcell_metadata, File.join('stemcells', product_metadata.stemcell_file) ) end
copy_dirs_and_files()
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 41 def copy_dirs_and_files product_metadata = ProductMetadata.from_file(product_contents.metadata_path) copy_and_validate_releases(product_metadata) if product_metadata.explicit_stemcell? copy_and_validate_stemcell(product_metadata) copy_and_validate_compiled_packages(product_metadata) end if product_contents.content_migrations_exist? FileUtils.mkdir('content_migrations') FileUtils.cp(product_contents.content_migrations_path, 'content_migrations') end if product_contents.migrations_exist? FileUtils.mkdir('migrations') FileUtils.cp_r(product_contents.migrations_path, '.') end FileUtils.mkdir('metadata') metadata = YAML.load_file(product_contents.metadata_path) metadata.fetch('releases').each do |r| r.delete('aws') end File.write( File.join('metadata', File.basename(product_contents.metadata_path)), metadata.to_yaml ) end
create_zip!()
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 116 def create_zip! log.info("Creating zip file #{artifact_path}") # Split into two steps so that it works inside Docker on a mounted volume `zip -r -0 local.pivotal .` FileUtils.mv('local.pivotal', artifact_path) log.info('Finished creating zip file') end
in_tmp_dir() { || ... }
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 33 def in_tmp_dir Dir.mktmpdir do |temp_dir| FileUtils.cd(temp_dir) do yield end end end
remove_previous_artifacts()
click to toggle source
# File lib/vara/product_artifact_zipper.rb, line 29 def remove_previous_artifacts FileUtils.rm(artifact_path) if File.exist?(artifact_path) end