Module: Sprinkle::Package

Included in:
Object
Defined in:
lib/sprinkle/package.rb

Overview

Packages

A package defines one or more things to provision onto the server. There is a lot of flexibility in a way a package is defined but let me give you a basic example:

package :ruby do
  description 'Ruby MRI'
  version '1.8.6'
  apt 'ruby'

  verify { has_executable 'ruby' }
end

The above would define a package named ‘ruby’ and give it a description and explicitly say its version. It is installed via apt and to verify the installation was successful sprinkle will check for the executable ‘ruby’ being availble. Pretty simple, right?

Note: Defining a package does not INSTALL it. To install a package, you must require it in a Sprinkle::Policy block.

Pre-Requirements

Most packages have some sort of pre-requisites in order to be installed. Sprinkle allows you to define the requirements of the package, which will be installed before the package itself. An example below:

package :rubygems do
  source 'http://rubyforge.org/rubygems.tgz'
  requires :ruby
end

In this case, when rubygems is being installed, Sprinkle will first provision the server with Ruby to make sure the requirements are met. In turn, if ruby has requirements, it installs those first, and so on.

Verifications

Most of the time its important to know whether the software you’re attempting to install was installed successfully or not. For this, Sprinkle provides verifications. Verifications are one or more blocks which define rules with which Sprinkle can check if it installed the package successfully. If these verification blocks fail, then Sprinkle will gracefully stop the entire process. An example below:

package :rubygems do
  source 'http://rubyforge.org/rubygems.tgz'
  requires :ruby

  verify { has_executable 'gem' }
end

In addition to verifying an installation was successfully, by default Sprinkle runs these verifications before the installation to check if the package is already installed. If the verifications pass before installing the package, it skips the package. To override this behavior, set the -f flag on the sprinkle script or set the :force option to true in Sprinkle::OPTIONS

For more information on verifications and to see all the available verifications, see Sprinkle::Verify

Virtual Packages

Sometimes, there are multiple packages available for a single task. An example is a database package. It can contain mySQL, postgres, or sqlite! This is where virtual packages come in handy. They are defined as follows:

package :sqlite3, :provides => :database do
  apt 'sqlite3'
end

The :provides option allows you to reference this package either by :sqlite3 or by :database. But whereas the package name is unique, multiple packages may share the same provision. If this is the case, when running Sprinkle, the script will ask you which provision you want to install. At this time, you can only install one.

Meta-Packages

A package doesn’t require an installer. If you want to define a package which merely encompasses other packages, that is fine too. Example:

package :meta do
  requires :magic_beans
  requires :magic_sauce
end

– FIXME: Should probably document recommendations. ++

Defined Under Namespace

Classes: Package

Constant Summary collapse

PACKAGES =
{}
VIRTUAL_PACKAGES =

Keep a list of all the virtual packages defined, so if multiple packages are defined that provide this virtual package we can ask the user which they would like to install.

[]

Instance Method Summary collapse

Instance Method Details

#find(name) ⇒ Object

Returns a list of packages with the given name. If multiple packages were defined with the same name (ie. different versions of the same software) then all versions are returned. If the given name identifies a virtual package then and there are multiple providers, then prompt the user to choose which to install.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/sprinkle/package.rb', line 119

def find(name)
  packages = PACKAGES[name]
  if packages and packages.length > 1 and VIRTUAL_PACKAGES.include? name
    selected = []
    choose do |menu|
      menu.layout = :one_line
      menu.header = "Choose #{name}"
      packages.sort!.each do |package|
        menu.choice(package.to_s) do
          selected << package
        end
      end
      menu.choice("all") do
        selected = packages
      end
    end
    packages = selected
  end
  packages.sort! if packages
  packages
end

#package(name, metadata = {}, &block) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/sprinkle/package.rb', line 102

def package(name,  = {}, &block)
  package = Package.new(name, , &block)
  # there might be multiple versions of a package so append to the list
  (PACKAGES[name] ||= []) << package
  if package.provides
    # there might be multiple providers so append to provider list and remember
    # that this packages is virtual
    (PACKAGES[package.provides] ||= []) << package
    VIRTUAL_PACKAGES << package.provides
  end
  package
end