Saturday, 20 February 2016

Building package using Omnibus


Omnibus is a tool for creating full-stack installers for multiple platforms. In general, it simplifies the installation of any software by including all of the dependencies for that piece of software. It was written by the people at Chef, who use it to package Chef.
Omnibus consists of two pieces- omnibus and omnibus software.
  1. omnibus – the framework, created by Chef Software, by which we create full-stack, cross-platform installers for software. The project is on GitHub at chef/omnibus.
  2. omnibus-software – Chef Software’s open source collection of software definitions that are used to build the Chef Client, the Chef Server, and other Chef Software products. The software definitions can be found on GitHub at chef/omnibus-software.
Omnibus provides both, a DSL for defining Omnibus projects for your software, as well as a command-line tool for generating installer artifacts from that definition.
Omnibus has minimal prerequisites. It requires Ruby 2.0.0+ and Bundler.

Getting Started


To get started install omnibus :
> gem install omnibus
You can now create an omnibus project inside your current directory using project generator feature
$ omnibus new demo-app
      create  omnibus-demo-app/Gemfile
      create  omnibus-demo-app/.gitignore
      create  omnibus-demo-app/README.md
      create  omnibus-demo-app/omnibus.rb
      create  omnibus-demo-app/config/projects/demo-app.rb
      create  omnibus-demo-app/config/software/demo-app-zlib.rb
      create  omnibus-demo-app/.kitchen.local.yml
      create  omnibus-demo-app/.kitchen.yml
      create  omnibus-demo-app/Berksfile
      create  omnibus-demo-app/package-scripts/demo-app/preinst
       chmod  omnibus-demo-app/package-scripts/demo-app/preinst
      create  omnibus-demo-app/package-scripts/demo-app/prerm
       chmod  omnibus-demo-app/package-scripts/demo-app/prerm
      create  omnibus-demo-app/package-scripts/demo-app/postinst
       chmod  omnibus-demo-app/package-scripts/demo-app/postinst
      create  omnibus-demo-app/package-scripts/demo-app/postrm
       chmod  omnibus-demo-app/package-scripts/demo-app/postrm

It creates the omnibus-demo directory inside your current directory and this directory has all omnibus package build related files. It is easy to build an empty project without doing any change run

$ bundle install --binstubs

bundle install installs all Omnibus dependencies

$ bin/omnibus build demo

The above command will create the installer inside pkg directory. Omnibus determines the platform for which to build an installer based on the platform it is currently running on. That is, you can only generate a .deb file on a Debian-based system. To alleviate this caveat, the generated project includes a Test Kitchen setup suitable for generating a series of Omnibus projects.
Back to the Omnibus DSL. Though bin/omnibus build demo will build the package for you, it will not do anything exciting. For that, you need to use the Omnibus DSL to define the specifics of your application.

1) Config

If present, Omnibus will use a top-level configuration file name omnibus.rb at the root of your repository. This file is loaded at runtime and includes number of configurations.  For e.g.-
Please see config doc for more information. You can use different configuration file by using –config option using command line

2) Project DSL

When you create an omnibus project, it creates a project DSL file inside config/project with the name which you used for creating project for above example it will create config/project/demo.rb. It provides means to define the dependencies of the project and metadata of the project.  We will look at some contents of project DSL file
‘install_dir’  option is the location where package will be installed. There are more DSL methods available which you can use in this file. Please see the Project Doc for more information.

3) Software DSL

Software DSL defines individual software components that go into making your overall package.  The Software DSL provides a way to define where to retrieve the software sources, how to build them, and what dependencies they have. Now let’s edit a config/software/demo.rb
In the above example, consider that we are building a package for Ruby on Rails application, hence we need to include ruby and rubygems dependency. The definition for ruby and rubygems dependency comes from theomnibus-software. Chef has introduced omnibus-software, it is a collection of software definitions used by chef while building their products. To use omnibus-software definitions you need to include the repo path in Gemfile. You can also write your own software definitions. Inside build block you can define how to build your installer. Omnibus provide Build DSL which you can use inside build block to define your build essentials. You can run ruby script and copy and delete files using Build DSL inside build block.
Apart from all these DSL file omnibus also created ‘package-script’ directory which consist of pre install and post install script files. You can write a script which you want to run before and after the installation of package and also before and after the removal of the package inside these files.
You can use the following references for more examples

No comments:

Post a Comment