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_artifact ⇒ Object
readonly
Returns the value of attribute license_artifact.
-
#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 ⇒ 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 50 51 |
# 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_artifact = license_artifact @name = name raise 'Release name is blank' if name.blank? @version = .fetch(:version, nil) raise ReleaseVersionError.new('Version numbers cannot be specified for dev releases') if (@version && !@final) @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_artifact ⇒ Object (readonly)
Returns the value of attribute license_artifact.
5 6 7 |
# File 'lib/cli/release_builder.rb', line 5 def license_artifact @license_artifact 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.
54 55 56 |
# File 'lib/cli/release_builder.rb', line 54 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cli/release_builder.rb', line 69 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
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cli/release_builder.rb', line 86 def build( = {}) = { :generate_tarball => true }.merge() header("Generating manifest...") generate_manifest if [:generate_tarball] header("Generating tarball...") generate_tarball end @build_complete = true end |
#dev_releases_dir ⇒ Object
182 183 184 |
# File 'lib/cli/release_builder.rb', line 182 def dev_releases_dir File.join(@release.dir, 'dev_releases', @name) end |
#final? ⇒ Boolean
Returns Is release final?.
59 60 61 |
# File 'lib/cli/release_builder.rb', line 59 def final? @final end |
#final_releases_dir ⇒ Object
178 179 180 |
# File 'lib/cli/release_builder.rb', line 178 def final_releases_dir File.join(@release.dir, 'releases', @name) end |
#generate_manifest ⇒ Object
Generates release manifest
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 152 153 |
# File 'lib/cli/release_builder.rb', line 99 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_artifact.nil? manifest['license'] = { 'version' => @license_artifact.version, 'fingerprint' => @license_artifact.fingerprint, 'sha1' => @license_artifact.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 end |
#generate_tarball ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/cli/release_builder.rb', line 155 def generate_tarball generate_manifest unless @manifest_generated return if @release_storage.has_file?(release_filename) copy_jobs copy_packages copy_license FileUtils.mkdir_p(File.dirname(tarball_path)) in_build_dir do `tar -czf #{tarball_path} . 2>&1` unless $?.exitstatus == 0 raise InvalidRelease, "Cannot create release tarball" end say("Generated #{tarball_path}") end end |
#manifest_path ⇒ Object
190 191 192 |
# File 'lib/cli/release_builder.rb', line 190 def manifest_path File.join(releases_dir, "#{@name}-#{version}.yml") end |
#release_filename ⇒ Object
63 64 65 |
# File 'lib/cli/release_builder.rb', line 63 def release_filename "#{@name}-#{@version}.tgz" end |
#releases_dir ⇒ Object
174 175 176 |
# File 'lib/cli/release_builder.rb', line 174 def releases_dir @final ? final_releases_dir : dev_releases_dir end |
#tarball_path ⇒ Object
186 187 188 |
# File 'lib/cli/release_builder.rb', line 186 def tarball_path File.join(releases_dir, "#{@name}-#{version}.tgz") end |