Skip to content

Instantly share code, notes, and snippets.

@ranjib
Last active December 22, 2015 20:59
Show Gist options
  • Save ranjib/6530138 to your computer and use it in GitHub Desktop.
Save ranjib/6530138 to your computer and use it in GitHub Desktop.
Create your omnibus installers using lxc & Chef
require 'lxc'
require 'lxc/extension'
# In this gist, we'll spawn an lxc container, use the lxc-chef/ssh extensions to install chef & omnibus
# then we'll drop our omnibus dummy definition , then build the omnibus installer
# then finally we'll copy over the resulting debian on the host box, and destroy the whole container
# you can create a rpm by spawning a centos/fedora container
LXC.use_sudo = true
vm = LXC::Container.new('omnibus-creator')
vm.ssh_user = 'ubuntu'
vm.ssh_password = 'ubuntu'
vm.create(:template => 'ubuntu')
vm.start
sleep 5 # wait till dnsmasq ip allocation finishes
vm.install_chef
vm.chef_resource(resource: 'link[/opt/chef/embedded/bin/ruby]',
action: :create,
to: '"/usr/bin/ruby"')
vm.chef_resource(resource: 'gem_package[bundler]',
action: :install,
gem_binary: '"/opt/chef/embedded/bin/gem"')
vm.chef_resource(resource: 'package[build-essential]', action: :install)
vm.chef_resource(resource: 'package[git]', action: :install)
vm.chef_resource(resource: 'package[libxml2-dev]', action: :install)
vm.chef_resource(resource: 'package[libxslt-dev]', action: :install)
vm.chef_resource(resource: 'gem_package[omnibus]',
action: :install,
gem_binary: '"/opt/chef/embedded/bin/gem"')
vm.chef_resource(resource: 'execute[/opt/chef/embedded/bin/omnibus project ruby2]',
action: :run, cwd: '"/opt"')
vm.chef_resource(resource: 'file[/opt/omnibus-ruby2/omnibus.rb]',
action: :create, content: "use_s3_caching false".dump)
# Definition for you custom omnibus project goes here
# read more about omnibus on the projects homepage,
# btw. its one of the very many awesome sub projects chef has whipped up :-)
omnibus_def =<<-EOF
name "ruby2"
maintainer "Ranjib Dey"
homepage "https://github.com/ranjib"
replaces "ruby2"
install_path "/opt/ruby2"
build_version Omnibus::BuildVersion.new.semver
build_iteration 1
# creates required build directories
dependency "preparation"
dependency "ruby"
# version manifest file
dependency "version-manifest"
EOF
vm.chef_resource(resource: 'file[/opt/omnibus-ruby2/config/projects/ruby2.rb]',
action: :create, content: omnibus_def.dump)
vm.chef_resource(resource: 'execute[/opt/chef/embedded/bin/bundle install --binstubs]',
action: :run, cwd: '"/opt/omnibus-ruby2"')
vm.chef_resource(resource: 'execute[/opt/chef/embedded/bin/bundle exec omnibus build project ruby2]',
action: :run, cwd: '"/opt/omnibus-ruby2"')
vm.ssh!(command: 'sudo mv /opt/omnibus-ruby2/pkg/ruby*.deb /home/ubuntu/ruby2.deb')
vm.ssh!(command: 'sudo chown ubuntu:ubuntu /home/ubuntu/ruby2.deb')
vm.download!(local_path: 'ruby2.deb', remote_path: '/home/ubuntu/ruby2.deb')
vm.stop
vm.destroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment