Class: Bosh::Cli::ReleaseCompiler
Overview
Compiles release tarball based on manifest
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #compile ⇒ Object
- #exists? ⇒ Boolean
- #find_in_indices(final_index, dev_index, build, build_type) ⇒ Object
- #find_job(job) ⇒ Object
- #find_license(license) ⇒ Object
- #find_package(package) ⇒ Object
- #find_version_by_sha1(index, sha1) ⇒ Object
-
#initialize(manifest_file, artifacts_dir, blobstore, package_matches = [], release_source = nil) ⇒ ReleaseCompiler
constructor
A new instance of ReleaseCompiler.
-
#remote_job_exists?(local_job) ⇒ Boolean
Checks if local job is already known remotely.
-
#remote_package_exists?(local_package) ⇒ Boolean
Checks if local package is already known remotely.
Constructor Details
#initialize(manifest_file, artifacts_dir, blobstore, package_matches = [], release_source = nil) ⇒ ReleaseCompiler
Returns a new instance of ReleaseCompiler.
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 |
# File 'lib/cli/release_compiler.rb', line 18 def initialize(manifest_file, artifacts_dir, blobstore, package_matches = [], release_source = nil) @blobstore = blobstore @release_source = release_source || Dir.pwd @manifest_file = File.(manifest_file, @release_source) @tarball_path = nil @artifacts_dir = artifacts_dir @build_dir = Dir.mktmpdir @jobs_dir = File.join(@build_dir, "jobs") @packages_dir = File.join(@build_dir, "packages") @package_matches = Set.new(package_matches) FileUtils.mkdir_p(@jobs_dir) FileUtils.mkdir_p(@packages_dir) @manifest = load_yaml_file(manifest_file) @name = @manifest["name"] @version = @manifest["version"] @packages = @manifest.fetch("packages", []).map { |pkg| OpenStruct.new(pkg) } @jobs = @manifest.fetch("jobs", []).map { |job| OpenStruct.new(job) } @license = @manifest["license"] ? OpenStruct.new(@manifest["license"]) : nil end |
Instance Attribute Details
#tarball_path ⇒ Object
103 104 105 106 |
# File 'lib/cli/release_compiler.rb', line 103 def tarball_path @tarball_path || File.join(File.dirname(@manifest_file), "#{@name}-#{@version}.tgz") end |
Class Method Details
.compile(manifest_file, artifacts_dir, blobstore) ⇒ Object
9 10 11 |
# File 'lib/cli/release_compiler.rb', line 9 def self.compile(manifest_file, artifacts_dir, blobstore) new(manifest_file, artifacts_dir, blobstore).compile end |
Instance Method Details
#compile ⇒ Object
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 |
# File 'lib/cli/release_compiler.rb', line 45 def compile if exists? quit("You already have this version in `#{tarball_path.make_green}'") end FileUtils.cp(@manifest_file, File.join(@build_dir, "release.MF"), :preserve => true) header("Copying packages") @packages.each do |package| say("#{package.name} (#{package.version})".ljust(30), " ") if remote_package_exists?(package) say("SKIP".make_yellow) next end nl package_file_path = find_package(package) FileUtils.cp(package_file_path, File.join(@packages_dir, "#{package.name}.tgz"), :preserve => true) end header("Copying jobs") @jobs.each do |job| say("#{job.name} (#{job.version})".ljust(30), " ") if remote_job_exists?(job) say("SKIP".make_yellow) next end nl job_file_path = find_job(job) FileUtils.cp(job_file_path, File.join(@jobs_dir, "#{job.name}.tgz"), :preserve => true) end header("Copying license") if @license say("license (#{@license.version})".ljust(30), " ") nl license_file_path = find_license(@license) FileUtils.cp(license_file_path, File.join(@build_dir, 'license.tgz'), preserve: true) end header("Building tarball") Dir.chdir(@build_dir) do tar_out = `tar -czf #{tarball_path} . 2>&1` unless $?.exitstatus == 0 raise InvalidRelease, "Cannot create release tarball: #{tar_out}" end say("Generated #{tarball_path.make_green}") say("Release size: #{pretty_size(tarball_path).make_green}") end end |
#exists? ⇒ Boolean
99 100 101 |
# File 'lib/cli/release_compiler.rb', line 99 def exists? File.exists?(tarball_path) end |
#find_in_indices(final_index, dev_index, build, build_type) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/cli/release_compiler.rb', line 138 def find_in_indices(final_index, dev_index, build, build_type) desc = "#{build.name} (#{build.version})" index = final_index found_build = find_version_by_sha1(index, build.sha1) if found_build.nil? index = dev_index found_build = find_version_by_sha1(index, build.sha1) end if found_build.nil? say("MISSING".make_red) err("Cannot find #{build_type} with checksum `#{build.sha1}'") end sha1 = found_build["sha1"] blobstore_id = found_build["blobstore_id"] storage = Versions::LocalArtifactStorage.new(@artifacts_dir) resolver = Versions::VersionFileResolver.new(storage, @blobstore) resolver.find_file(blobstore_id, sha1, "#{build_type} #{desc}") rescue Bosh::Blobstore::BlobstoreError => e raise BlobstoreError, "Blobstore error: #{e}" end |
#find_job(job) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/cli/release_compiler.rb', line 117 def find_job(job) name = job.name final_jobs_dir = File.join(@release_source, '.final_builds', 'jobs', name) final_index = Versions::VersionsIndex.new(final_jobs_dir) dev_jobs_dir = File.join(@release_source, '.dev_builds', 'jobs', name) dev_index = Versions::VersionsIndex.new(dev_jobs_dir) find_in_indices(final_index, dev_index, job, 'job') end |
#find_license(license) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/cli/release_compiler.rb', line 126 def find_license(license) final_dir = File.join(@release_source, '.final_builds', 'license') final_index = Versions::VersionsIndex.new(final_dir) dev_dir = File.join(@release_source, '.dev_builds', 'license') dev_index = Versions::VersionsIndex.new(dev_dir) find_in_indices(final_index, dev_index, license, 'license') end |
#find_package(package) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/cli/release_compiler.rb', line 108 def find_package(package) name = package.name final_package_dir = File.join(@release_source, '.final_builds', 'packages', name) final_index = Versions::VersionsIndex.new(final_package_dir) dev_package_dir = File.join(@release_source, '.dev_builds', 'packages', name) dev_index = Versions::VersionsIndex.new(dev_package_dir) find_in_indices(final_index, dev_index, package, 'package') end |
#find_version_by_sha1(index, sha1) ⇒ Object
134 135 136 |
# File 'lib/cli/release_compiler.rb', line 134 def find_version_by_sha1(index, sha1) index.select{ |_, build| build['sha1'] == sha1 }.values.first end |
#remote_job_exists?(local_job) ⇒ Boolean
Checks if local job is already known remotely
178 179 180 |
# File 'lib/cli/release_compiler.rb', line 178 def remote_job_exists?(local_job) false end |
#remote_package_exists?(local_package) ⇒ Boolean
Checks if local package is already known remotely
168 169 170 171 172 173 |
# File 'lib/cli/release_compiler.rb', line 168 def remote_package_exists?(local_package) # If checksum is known to director we can always match it @package_matches.include?(local_package.sha1) || # !!! Needs test coverage (local_package.fingerprint && # !!! Needs test coverage @package_matches.include?(local_package.fingerprint)) # !!! Needs test coverage end |