Class: FPM::Cookery::OmnibusPackager

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/fpm/cookery/omnibus_packager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(packager, config) ⇒ OmnibusPackager

Returns a new instance of OmnibusPackager.



12
13
14
15
16
17
# File 'lib/fpm/cookery/omnibus_packager.rb', line 12

def initialize(packager, config)
  @packager = packager
  @config = config
  @recipe = packager.recipe
  @depends = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/fpm/cookery/omnibus_packager.rb', line 10

def config
  @config
end

#packagerObject (readonly)

Returns the value of attribute packager.



10
11
12
# File 'lib/fpm/cookery/omnibus_packager.rb', line 10

def packager
  @packager
end

#recipeObject (readonly)

Returns the value of attribute recipe.



10
11
12
# File 'lib/fpm/cookery/omnibus_packager.rb', line 10

def recipe
  @recipe
end

Instance Method Details

#install_build_depsObject



43
44
45
46
47
48
49
# File 'lib/fpm/cookery/omnibus_packager.rb', line 43

def install_build_deps
  build_deps = load_omnibus_recipes(recipe).map(&:build_depends).flatten.uniq
  recipe.run_lifecycle_hook(:before_dependency_installation)
  DependencyInspector.verify!([], build_deps)
  recipe.run_lifecycle_hook(:after_dependency_installation)
  Log.info("Build dependencies installed!")
end

#load_omnibus_recipes(_recipe) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fpm/cookery/omnibus_packager.rb', line 19

def load_omnibus_recipes(_recipe)
  dep_recipes = []
  _recipe.omnibus_recipes.each do |name|
    recipe_file = build_recipe_file_path(name)
    Log.info "Loading dependency recipe #{name} from #{recipe_file}"
    unless File.exist?(recipe_file)
      error_message = "Cannot find a recipe for #{name} at #{recipe_file}"
      Log.fatal error_message
      raise Error::ExecutionFailure, error_message
    end

    FPM::Cookery::Book.instance.load_recipe(recipe_file, config) do |dep_recipe|
      dep_recipe.destdir = "#{recipe.omnibus_dir}/embedded" if recipe.omnibus_dir
      dep_recipe.omnibus_installing = true if recipe.omnibus_dir
      if dep_recipe.omnibus_recipes.any?
        dep_recipes += load_omnibus_recipes(dep_recipe)
      end
      dep_recipes << dep_recipe
    end
  end
  dep_recipes
end

#runObject



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
# File 'lib/fpm/cookery/omnibus_packager.rb', line 51

def run
  # Omnibus packages are many builds in one package; e.g. Ruby + Puppet together.
  Log.info "Recipe #{recipe.name} is an Omnibus package; looking for child recipes to build"

  dep_recipes = load_omnibus_recipes(recipe)
  dep_recipes.uniq.each do |dep_recipe|
    pkg = FPM::Cookery::Packager.new(dep_recipe, :skip_package => true,
                                    :keep_destdir => true, :dependency_check => config.dependency_check )
    pkg.target = FPM::Cookery::Facts.target.to_s

    Log.info "Located recipe for child recipe #{dep_recipe.name}; starting build"
    pkg.dispense

    @depends += dep_recipe.depends
    Log.info "Finished building #{dep_recipe.name}, moving on to next recipe"
  end

  # Now all child recipes are built; set depends to combined set of dependencies
  recipe.class.depends(@depends.flatten.uniq)
  Log.info "Combined dependencies: #{recipe.depends.join(', ')}"

  recipe.destdir = recipe.omnibus_dir if recipe.omnibus_dir

  if recipe.omnibus_additional_paths
    packager.config[:input] = [ recipe.destdir ] + recipe.omnibus_additional_paths
  else
    packager.config[:input] = recipe.destdir
  end

  packager.config[:keep_destdir] = true

  packager.dispense
end