Project

pack_rb

0.0
No commit activity in last 3 years
No release in over 3 years
A gem for driving the Packer command line tool from within your Ruby project.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.13
~> 10.0
~> 3.0
 Project Readme

PackRb

Circle CI

A gem for driving the Packer command line tool from within your Ruby project.

This gem was built against version 0.9.0 of Packer

Pre-Requisites

You must have a version of Packer installed.

Go download a copy for your OS.

Installation

Add this line to your application's Gemfile:

gem 'pack_rb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pack_rb

Usage

With In Memory Template

require 'pack_rb'
require 'json'

template = {
  variables: { foo: 'bar'},
  builders:   [
    {
      type:         'null',
      ssh_host:     '127.0.0.1',
      ssh_username: 'foo',
      ssh_password: 'bar'
    }
  ]
}.to_json

packer = PackRb::Packer.new(tpl: template, machine_readable: true)
packer.build(debug: true)

Note: A plain old ruby hash can be used for template also. Just leave off the JSON bits.

With Template File

require 'pack_rb'

packer = PackRb::Packer.new(tpl: 'config/template.json', machine_readable: true)
packer.build(debug: true)

Output

The Packer methods will return a 2-item array:

  • String, combined STDOUT and STDERR of the packer process
  • Fixnum, packer process exit code

Streaming Output

If you wish to have STDOUT and STDERR from the Packer command stream to the console as it runs, you will need to enable streaming by setting stream_output: true:

PackRb::Packer.new(tpl: 'config/template.json', machine_readable: true, stream_output: true)
packer.build(debug :true)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment. Run bundle exec pack_rb to use the gem in this directory, ignoring other installed copies of this gem.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/manheim/pack_rb.

License

The gem is available as open source under the terms of the MIT License.