Class: Bosh::Gen::Generators::PackageGenerator
- Includes:
- Thor::Actions
- Defined in:
- lib/bosh/gen/generators/package_generator.rb
Constant Summary collapse
- BLOB_FILE_MIN_SIZE =
files over 20k are blobs
20_000
Class Method Summary collapse
Instance Method Summary collapse
- #check_name ⇒ Object
- #check_root_is_release ⇒ Object
-
#copy_src_files ⇒ Object
Copy the local source files into src or blobs * into src/NAME/filename (if < 20k) or * into blobs/NAME/filename (if >= 20k) Skip a file if: * filename already exists as a blob in blobs/NAME/filename * file doesn’t exist.
- #package_specification ⇒ Object
- #packaging ⇒ Object
- #warn_missing_dependencies ⇒ Object
Class Method Details
.source_root ⇒ Object
16 17 18 |
# File 'lib/bosh/gen/generators/package_generator.rb', line 16 def self.source_root File.join(File.dirname(__FILE__), "package_generator", "templates") end |
Instance Method Details
#check_name ⇒ Object
26 27 28 |
# File 'lib/bosh/gen/generators/package_generator.rb', line 26 def check_name raise Thor::Error.new("'#{name}' is not a valid BOSH id") unless name.bosh_valid_id? end |
#check_root_is_release ⇒ Object
20 21 22 23 24 |
# File 'lib/bosh/gen/generators/package_generator.rb', line 20 def check_root_is_release unless File.exist?("jobs") && File.exist?("packages") raise Thor::Error.new("run inside a BOSH release project") end end |
#copy_src_files ⇒ Object
Copy the local source files into src or blobs
-
into src/NAME/filename (if < 20k) or
-
into blobs/NAME/filename (if >= 20k)
Skip a file if:
-
filename already exists as a blob in blobs/NAME/filename
-
file doesn’t exist
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bosh/gen/generators/package_generator.rb', line 86 def copy_src_files files.each do |file| file_path = File.(file) unless File.exist?(file_path) say "Skipping unknown file #{file_path}", :red next end size = File.size(file_path) file_name = File.basename(file_path) src_file = src_dir(file_name) blob_file = blob_dir(file_name) if File.exist?(blob_file) say "Blob '#{file_name}' exists as a blob, skipping..." else # if < 20k, put in src/, else blobs/ target = size >= BLOB_FILE_MIN_SIZE ? blob_file : src_file copy_file File.(file_path), target end end end |
#package_specification ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/bosh/gen/generators/package_generator.rb', line 108 def package_specification src_files = files.map {|f| "#{name}/#{File.basename(f)}"} + # new blobs existing_sources_as_globs # existing directories, like 'myapp' config = { "name" => name, "dependencies" => dependencies, "files" => src_files } create_file package_dir("spec"), YAML.dump(config) end |
#packaging ⇒ Object
39 40 41 42 43 44 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 |
# File 'lib/bosh/gen/generators/package_generator.rb', line 39 def packaging create_file package_dir("packaging") do packaging = <<-SHELL.gsub(/^\s{10}/, '') set -e # exit immediately if a simple command exits with a non-zero status set -u # report the usage of uninitialized variables # Detect # of CPUs so make jobs can be parallelized CPUS=$(grep -c ^processor /proc/cpuinfo) # Available variables # $BOSH_COMPILE_TARGET - where this package & spec'd source files are available # $BOSH_INSTALL_TARGET - where you copy/install files to be included in package export HOME=/var/vcap SHELL language_packs.each do |package| packaging << "source /var/vcap/packages/#{package}/bosh/compile.env\n" end simple_dependencies.each do |package| packaging << "PATH=/var/vcap/packages/#{package}/bin:$PATH\n" end archives_in_files.each do |archive_type, unpack_command, archive_file, unpack_base_path| packaging << <<-SHELL.gsub(/^\s{12}/, '') #{unpack_command} #{name}/#{archive_file} cd #{unpack_base_path} ./configure --prefix=${BOSH_INSTALL_TARGET} make -j${CPUS} && make install # Alternatively, to copy archive contents: # cp -a #{unpack_base_path}/* $BOSH_INSTALL_TARGET SHELL end packaging end end |
#warn_missing_dependencies ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/bosh/gen/generators/package_generator.rb', line 30 def warn_missing_dependencies dependencies.each do |d| raise Thor::Error.new("dependency '#{d}' is not a valid BOSH id") unless d.bosh_valid_id? unless File.exist?(File.join("packages", d)) say_status "warning", "missing dependency '#{d}'", :yellow end end end |