Class: Bosh::Cli::PackageBuilder
- Includes:
- PackagingHelper
- Defined in:
- lib/cli/package_builder.rb
Defined Under Namespace
Classes: GlobMatch
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#globs ⇒ Object
readonly
Returns the value of attribute globs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tarball_path ⇒ Object
readonly
Returns the value of attribute tarball_path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Attributes included from PackagingHelper
Instance Method Summary collapse
- #build_dir ⇒ Object
- #copy_files ⇒ Object
- #fingerprint ⇒ Object
- #glob_matches ⇒ Object
-
#initialize(spec, release_dir, final, blobstore, sources_dir = nil, blobs_dir = nil, alt_src_dir = nil) ⇒ PackageBuilder
constructor
We have two ways of getting/storing a package: development versions of packages, kept in release directory final versions of packages, kept in blobstore development packages and their metadata should always be gitignored final build tarballs should be ignored as well final builds metadata should be checked in.
- #package_dir ⇒ Object
- #pre_package ⇒ Object
-
#reload ⇒ Object
Mostly for tests.
Methods included from PackagingHelper
#build, #checksum, #dry_run?, #file_checksum, #final?, #generate_tarball, #init_indices, #new_version?, #notes, #older_version?, #tracked_permissions, #upload_tarball, #use_dev_version, #use_final_version
Methods included from VersionCalc
#major_version, #minor_version, #version_cmp, #version_greater, #version_less, #version_same
Constructor Details
#initialize(spec, release_dir, final, blobstore, sources_dir = nil, blobs_dir = nil, alt_src_dir = nil) ⇒ PackageBuilder
We have two ways of getting/storing a package: development versions of packages, kept in release directory final versions of packages, kept in blobstore development packages and their metadata should always be gitignored final build tarballs should be ignored as well final builds metadata should be checked in
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 |
# File 'lib/cli/package_builder.rb', line 46 def initialize(spec, release_dir, final, blobstore, sources_dir = nil, blobs_dir = nil, alt_src_dir = nil) spec = load_yaml_file(spec) if spec.is_a?(String) && File.file?(spec) @name = spec["name"] @globs = spec["files"] @dependencies = Array(spec["dependencies"]) @release_dir = release_dir @sources_dir = sources_dir || File.join(@release_dir, "src") @alt_sources_dir = alt_src_dir || File.join(@release_dir, "src_alt") @blobs_dir = blobs_dir || File.join(@release_dir, "blobs") @final = final @blobstore = blobstore @artefact_type = "package" @metadata_files = %w(packaging pre_packaging) if @final && File.exists?(@alt_sources_dir) err("Please remove `#{File.basename(@alt_sources_dir)}' first") end if @name.blank? raise InvalidPackage, "Package name is missing" end unless @name.bosh_valid_id? raise InvalidPackage, "Package name should be a valid BOSH identifier" end unless @globs.is_a?(Array) && @globs.size > 0 raise InvalidPackage, "Package '#{@name}' doesn't include any files" end @dev_builds_dir = File.join(@release_dir, ".dev_builds", "packages", @name) @final_builds_dir = File.join(@release_dir, ".final_builds", "packages", @name) FileUtils.mkdir_p(package_dir) FileUtils.mkdir_p(@dev_builds_dir) FileUtils.mkdir_p(@final_builds_dir) at_exit { FileUtils.rm_rf(build_dir) } init_indices end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
38 39 40 |
# File 'lib/cli/package_builder.rb', line 38 def dependencies @dependencies end |
#globs ⇒ Object (readonly)
Returns the value of attribute globs.
38 39 40 |
# File 'lib/cli/package_builder.rb', line 38 def globs @globs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/cli/package_builder.rb', line 38 def name @name end |
#tarball_path ⇒ Object (readonly)
Returns the value of attribute tarball_path.
38 39 40 |
# File 'lib/cli/package_builder.rb', line 38 def tarball_path @tarball_path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
38 39 40 |
# File 'lib/cli/package_builder.rb', line 38 def version @version end |
Instance Method Details
#build_dir ⇒ Object
110 111 112 |
# File 'lib/cli/package_builder.rb', line 110 def build_dir @build_dir ||= Dir.mktmpdir end |
#copy_files ⇒ Object
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 |
# File 'lib/cli/package_builder.rb', line 118 def copy_files copied = 0 glob_matches.each do |match| destination = File.join(build_dir, match.path) if File.directory?(match.full_path) FileUtils.mkdir_p(destination) else FileUtils.mkdir_p(File.dirname(destination)) FileUtils.cp(match.full_path, destination, :preserve => true) copied += 1 end end in_package_dir do @metadata_files.each do |filename| destination = File.join(build_dir, filename) next unless File.exists?(filename) if File.exists?(destination) raise InvalidPackage, "Package '#{name}' has '#{filename}' file " + "which conflicts with BOSH packaging" end FileUtils.cp(filename, destination, :preserve => true) copied += 1 end end pre_package copied end |
#fingerprint ⇒ Object
102 103 104 |
# File 'lib/cli/package_builder.rb', line 102 def fingerprint @fingerprint ||= make_fingerprint end |
#glob_matches ⇒ Object
106 107 108 |
# File 'lib/cli/package_builder.rb', line 106 def glob_matches @resolved_globs ||= resolve_globs end |
#package_dir ⇒ Object
114 115 116 |
# File 'lib/cli/package_builder.rb', line 114 def package_dir File.join(@release_dir, "packages", name) end |
#pre_package ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/cli/package_builder.rb', line 150 def pre_package pre_packaging_script = File.join(package_dir, "pre_packaging") if File.exists?(pre_packaging_script) say("Pre-packaging...") FileUtils.cp(pre_packaging_script, build_dir, :preserve => true) old_env = ENV begin ENV.delete_if { |key, _| key[0, 7] == "BUNDLE_" } if ENV["RUBYOPT"] ENV["RUBYOPT"] = ENV["RUBYOPT"].sub("-rbundler/setup", "") end ENV["BUILD_DIR"] = build_dir ENV["RELEASE_DIR"] = @release_dir in_build_dir do pre_packaging_out = `bash -x pre_packaging 2>&1` pre_packaging_out.split("\n").each do |line| say("> #{line}") end unless $?.exitstatus == 0 raise InvalidPackage, "`#{name}' pre-packaging failed" end end ensure ENV.delete("BUILD_DIR") old_env.each { |k, v| ENV[k] = old_env[k] } end FileUtils.rm(File.join(build_dir, "pre_packaging")) end end |
#reload ⇒ Object
Mostly for tests
95 96 97 98 99 100 |
# File 'lib/cli/package_builder.rb', line 95 def reload # Mostly for tests @fingerprint = nil @resolved_globs = nil init_indices self end |