Class: Bosh::Cli::Resources::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/resources/package.rb

Constant Summary collapse

BUILD_HOOK_FILES =
['packaging', 'pre_packaging']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_base, release_base) ⇒ Package

Returns a new instance of Package


24
25
26
27
# File 'lib/cli/resources/package.rb', line 24

def initialize(package_base, release_base)
  @release_base = Pathname.new(release_base)
  @package_base = Pathname.new(package_base)
end

Instance Attribute Details

#package_baseObject (readonly)

Returns the value of attribute package_base


22
23
24
# File 'lib/cli/resources/package.rb', line 22

def package_base
  @package_base
end

#release_baseObject (readonly)

Returns the value of attribute release_base


22
23
24
# File 'lib/cli/resources/package.rb', line 22

def release_base
  @release_base
end

Class Method Details

.discover(release_base) ⇒ Object

Parameters:

  • directory (String)

    base Release directory


13
14
15
16
17
18
19
20
# File 'lib/cli/resources/package.rb', line 13

def self.discover(release_base)
  Dir[File.join(release_base, 'packages', '*')].inject([]) do |packages, package_base|
    if File.directory?(package_base)
      packages << new(package_base, release_base)
    end
    packages
  end
end

Instance Method Details

#additional_fingerprintsObject


94
95
96
# File 'lib/cli/resources/package.rb', line 94

def additional_fingerprints
  dependencies
end

#dependenciesObject


39
40
41
# File 'lib/cli/resources/package.rb', line 39

def dependencies
  @dependencies ||= Array(spec['dependencies']).sort
end

#filesObject


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cli/resources/package.rb', line 51

def files
  resolve_globs
  known_files = {}

  files = []
  files += resolved_globs.map do |match|
    known_files[match.path] = true
    [match.full_path, match.path]
  end

  BUILD_HOOK_FILES.each do |build_hook_file|
    source_file = package_base.join(build_hook_file)
    if source_file.exist?
      if known_files.has_key?(build_hook_file)
        raise Bosh::Cli::InvalidPackage, "Package '#{name}' has '#{build_hook_file}' file " +
            "which conflicts with BOSH packaging"
      end

      files << [source_file.to_s, build_hook_file]
    end
  end

  files
end

#format_fingerprint(digest, filename, name, file_mode) ⇒ Object


98
99
100
101
# File 'lib/cli/resources/package.rb', line 98

def format_fingerprint(digest, filename, name, file_mode)
  is_hook = BUILD_HOOK_FILES.include?(name)
  "%s%s%s" % [name, digest, is_hook ? '' : file_mode]
end

#nameObject


35
36
37
# File 'lib/cli/resources/package.rb', line 35

def name
  spec['name']
end

#plural_typeObject


47
48
49
# File 'lib/cli/resources/package.rb', line 47

def plural_type
  'packages'
end

#run_script(script_name, *args) ⇒ Object


103
104
105
106
107
# File 'lib/cli/resources/package.rb', line 103

def run_script(script_name, *args)
  if BUILD_HOOK_FILES.include?(script_name.to_s)
    send(:"run_script_#{script_name}", *args)
  end
end

#singular_typeObject


43
44
45
# File 'lib/cli/resources/package.rb', line 43

def singular_type
  'package'
end

#specObject


29
30
31
32
33
# File 'lib/cli/resources/package.rb', line 29

def spec
  @spec ||= load_yaml_file(package_base.join('spec'))
rescue
  raise Bosh::Cli::InvalidPackage, 'Package spec is missing'
end

#validate!Object


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cli/resources/package.rb', line 76

def validate!
  basename = File.basename(package_base.to_s)

  unless name == basename
    raise Bosh::Cli::InvalidPackage, "Found '#{name}' package in '#{basename}' directory, please fix it"
  end

  unless name.bosh_valid_id?
    raise Bosh::Cli::InvalidPackage, "Package name, '#{name}', should be a valid BOSH identifier"
  end

  unless spec['files'].is_a?(Array) && spec['files'].size > 0
    raise Bosh::Cli::InvalidPackage, "Package '#{name}' doesn't include any files"
  end

  resolve_globs
end