Class: Bosh::Cli::ReleaseBuilder
- Includes:
- DependencyHelper
- Defined in:
- lib/cli/release_builder.rb
Instance Attribute Summary collapse
-
#build_dir ⇒ Object
readonly
Returns the value of attribute build_dir.
-
#commit_hash ⇒ Object
readonly
Returns the value of attribute commit_hash.
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#license ⇒ Object
readonly
Returns the value of attribute license.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#uncommitted_changes ⇒ Object
readonly
Returns the value of attribute uncommitted_changes.
-
#version ⇒ String
readonly
Release version.
Instance Method Summary collapse
-
#affected_jobs ⇒ Array<Bosh::Cli::BuildArtifact>
List of job artifacts affected by this release compared to the previous one.
-
#build(options = {}) ⇒ Object
Builds release.
- #dev_releases_dir ⇒ Object
-
#final? ⇒ Boolean
Is release final?.
- #final_releases_dir ⇒ Object
-
#generate_manifest ⇒ Object
Generates release manifest.
- #generate_tarball(manifest_path = nil) ⇒ Object
-
#initialize(release, package_artifacts, job_artifacts, license_artifact, name, options = { }) ⇒ ReleaseBuilder
constructor
A new instance of ReleaseBuilder.
- #manifest_path ⇒ Object
- #release_filename ⇒ Object
- #releases_dir ⇒ Object
- #tarball_path ⇒ Object
Methods included from DependencyHelper
Constructor Details
#initialize(release, package_artifacts, job_artifacts, license_artifact, name, options = { }) ⇒ ReleaseBuilder
Returns a new instance of ReleaseBuilder.
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 |
# File 'lib/cli/release_builder.rb', line 21 def initialize(release, package_artifacts, job_artifacts, license_artifact, name, = { }) @release = release @final = .has_key?(:final) ? !![:final] : false @commit_hash = .fetch(:commit_hash, '00000000') @uncommitted_changes = .fetch(:uncommitted_changes, true) @packages = package_artifacts # todo @jobs = job_artifacts # todo @license = license_artifact @name = name raise 'Release name is blank' if name.blank? @version = .fetch(:version, nil) @final_index = Versions::VersionsIndex.new(final_releases_dir) @dev_index = Versions::VersionsIndex.new(dev_releases_dir) @index = @final ? @final_index : @dev_index @release_storage = Versions::LocalArtifactStorage.new(@index.storage_dir) if @version && @release_storage.has_file?(release_filename) raise ReleaseVersionError.new('Release version already exists') end @build_dir = Dir.mktmpdir in_build_dir do FileUtils.mkdir("packages") FileUtils.mkdir("jobs") end end |
Instance Attribute Details
#build_dir ⇒ Object (readonly)
Returns the value of attribute build_dir.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def build_dir @build_dir end |
#commit_hash ⇒ Object (readonly)
Returns the value of attribute commit_hash.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def commit_hash @commit_hash end |
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def jobs @jobs end |
#license ⇒ Object (readonly)
Returns the value of attribute license.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def license @license end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def name @name end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def packages @packages end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def release @release end |
#uncommitted_changes ⇒ Object (readonly)
Returns the value of attribute uncommitted_changes.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def uncommitted_changes @uncommitted_changes end |
#version ⇒ String (readonly)
Returns Release version.
52 53 54 |
# File 'lib/cli/release_builder.rb', line 52 def version @version end |
Instance Method Details
#affected_jobs ⇒ Array<Bosh::Cli::BuildArtifact>
Returns List of job artifacts affected by this release compared to the previous one.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cli/release_builder.rb', line 67 def affected_jobs result = Set.new(@jobs.select { |job_artifact| job_artifact.new_version? }) return result.to_a if @packages.empty? new_package_names = @packages.map do |package_artifact| package_artifact.name if package_artifact.new_version? end.compact @jobs.each do |job| result << job if (new_package_names & job.dependencies).size > 0 end result.to_a end |
#build(options = {}) ⇒ Object
Builds release
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cli/release_builder.rb', line 84 def build( = {}) = { :generate_tarball => true }.merge() header("Generating manifest...") manifest_path = generate_manifest if [:generate_tarball] generate_tarball(manifest_path) end @build_complete = true end |
#dev_releases_dir ⇒ Object
169 170 171 |
# File 'lib/cli/release_builder.rb', line 169 def dev_releases_dir File.join(@release.dir, 'dev_releases', @name) end |
#final? ⇒ Boolean
Returns Is release final?.
57 58 59 |
# File 'lib/cli/release_builder.rb', line 57 def final? @final end |
#final_releases_dir ⇒ Object
165 166 167 |
# File 'lib/cli/release_builder.rb', line 165 def final_releases_dir File.join(@release.dir, 'releases', @name) end |
#generate_manifest ⇒ Object
Generates release manifest
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/cli/release_builder.rb', line 96 def generate_manifest manifest = {} manifest['packages'] = packages.map do |build_artifact| { 'name' => build_artifact.name, 'version' => build_artifact.version, 'fingerprint' => build_artifact.fingerprint, 'sha1' => build_artifact.sha1, 'dependencies' => build_artifact.dependencies, } end manifest['jobs'] = jobs.map do |build_artifact| { 'name' => build_artifact.name, 'version' => build_artifact.version, 'fingerprint' => build_artifact.fingerprint, 'sha1' => build_artifact.sha1, } end unless @license.nil? manifest['license'] = { 'version' => @license.version, 'fingerprint' => @license.fingerprint, 'sha1' => @license.sha1, } end manifest['commit_hash'] = commit_hash manifest['uncommitted_changes'] = uncommitted_changes unless @name.bosh_valid_id? raise InvalidRelease, "Release name '#{@name}' is not a valid BOSH identifier" end manifest['name'] = @name # New release versions are allowed to have the same fingerprint as old versions. # For reverse compatibility, random uuids are stored instead. @index.add_version(SecureRandom.uuid, { 'version' => version }) manifest['version'] = version manifest_yaml = Psych.dump(manifest) say("Writing manifest...") File.open(File.join(build_dir, "release.MF"), "w") do |f| f.write(manifest_yaml) end File.open(manifest_path, "w") do |f| f.write(manifest_yaml) end @manifest_generated = true manifest_path end |
#generate_tarball(manifest_path = nil) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/cli/release_builder.rb', line 153 def generate_tarball(manifest_path = nil) manifest_path ||= generate_manifest return if @release_storage.has_file?(release_filename) archiver = ReleaseArchiver.new(tarball_path, manifest_path, packages, jobs, license) archiver.build end |
#manifest_path ⇒ Object
177 178 179 |
# File 'lib/cli/release_builder.rb', line 177 def manifest_path File.join(releases_dir, "#{@name}-#{version}.yml") end |
#release_filename ⇒ Object
61 62 63 |
# File 'lib/cli/release_builder.rb', line 61 def release_filename "#{@name}-#{@version}.tgz" end |
#releases_dir ⇒ Object
161 162 163 |
# File 'lib/cli/release_builder.rb', line 161 def releases_dir @final ? final_releases_dir : dev_releases_dir end |
#tarball_path ⇒ Object
173 174 175 |
# File 'lib/cli/release_builder.rb', line 173 def tarball_path File.join(releases_dir, "#{@name}-#{version}.tgz") end |