Merge pull request #108 from fgrehm/0.4.0

Release 0.4.0
This commit is contained in:
Fabio Rehm 2013-07-18 16:52:35 -07:00
commit 72555fdeb5
22 changed files with 214 additions and 195 deletions

View file

@ -2,11 +2,12 @@
FEATURES: FEATURES:
- Enable Chef for Ubuntu Raring base box
- New box format [#89](https://github.com/fgrehm/vagrant-lxc/issues/89) - New box format [#89](https://github.com/fgrehm/vagrant-lxc/issues/89)
BUG FIXES: BUG FIXES:
- Add translation for stopped status [#97](https://github.com/fgrehm/vagrant-lxc/issues/97)
- Enable retries when fetching container state [#74](https://github.com/fgrehm/vagrant-lxc/issues/74)
- Fix error when setting Debian boxes hostname from Vagrantfile [#91](https://github.com/fgrehm/vagrant-lxc/issues/91) - Fix error when setting Debian boxes hostname from Vagrantfile [#91](https://github.com/fgrehm/vagrant-lxc/issues/91)
- BTRFS-friendly base boxes [#81](https://github.com/fgrehm/vagrant-lxc/issues/81) - BTRFS-friendly base boxes [#81](https://github.com/fgrehm/vagrant-lxc/issues/81)
- Extended templates path lookup [#77](https://github.com/fgrehm/vagrant-lxc/issues/77) (tks to @aries1980) - Extended templates path lookup [#77](https://github.com/fgrehm/vagrant-lxc/issues/77) (tks to @aries1980)

View file

@ -3,9 +3,10 @@ source 'https://rubygems.org'
gemspec gemspec
group :development do group :development do
# TODO: Lock to 1.2.3 once it is out with this fix: https://github.com/mitchellh/vagrant/pull/1685 gem 'vagrant', github: 'mitchellh/vagrant'
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git' gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
gem 'vagrant-cachier' gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
gem 'vagrant-omnibus'
gem 'guard' gem 'guard'
gem 'guard-rspec' gem 'guard-rspec'
gem 'rb-inotify' gem 'rb-inotify'
@ -14,7 +15,7 @@ end
group :development, :test do group :development, :test do
gem 'rake' gem 'rake'
gem 'rspec' gem 'rspec', '~> 2.13.0'
gem 'rspec-fire', require: 'rspec/fire' gem 'rspec-fire', require: 'rspec/fire'
gem 'rspec-spies', require: false gem 'rspec-spies', require: false
gem 'coveralls', require: false gem 'coveralls', require: false

View file

@ -1,12 +1,23 @@
GIT GIT
remote: https://github.com/mitchellh/vagrant.git remote: git://github.com/fgrehm/vagrant-cachier.git
revision: ccfd321ef98dc5c12b180cc3a26f12d870c0eff5 revision: ae6cb5bcfbdbb2157867d77ded8f2b6f430c0f6c
specs: specs:
vagrant (1.2.3.dev) vagrant-cachier (0.2.0)
GIT
remote: git://github.com/fgrehm/vagrant-pristine.git
revision: 45a8d75f048bd611e337583496eb2b48b6998bbd
specs:
vagrant-pristine (0.1.0)
GIT
remote: git://github.com/mitchellh/vagrant.git
revision: 6d26c86c4c3f65e2e59f4dda6bca9cd9235de704
specs:
vagrant (1.2.4.dev)
childprocess (~> 0.3.7) childprocess (~> 0.3.7)
erubis (~> 2.7.0) erubis (~> 2.7.0)
i18n (~> 0.6.0) i18n (~> 0.6.0)
json (>= 1.5.1, < 1.8.0)
log4r (~> 1.1.9) log4r (~> 1.1.9)
net-scp (~> 1.1.0) net-scp (~> 1.1.0)
net-ssh (~> 2.6.6) net-ssh (~> 2.6.6)
@ -14,7 +25,7 @@ GIT
PATH PATH
remote: . remote: .
specs: specs:
vagrant-lxc (0.4.0.dev) vagrant-lxc (0.4.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
@ -31,36 +42,35 @@ GEM
thor thor
diff-lcs (1.2.4) diff-lcs (1.2.4)
erubis (2.7.0) erubis (2.7.0)
ffi (1.8.1) ffi (1.9.0)
formatador (0.2.4) formatador (0.2.4)
guard (1.8.0) guard (1.8.1)
formatador (>= 0.2.4) formatador (>= 0.2.4)
listen (>= 1.0.0) listen (>= 1.0.0)
lumberjack (>= 1.0.2) lumberjack (>= 1.0.2)
pry (>= 0.9.10) pry (>= 0.9.10)
thor (>= 0.14.6) thor (>= 0.14.6)
guard-rspec (3.0.0) guard-rspec (3.0.2)
guard (>= 1.8) guard (>= 1.8)
rspec (~> 2.13) rspec (~> 2.13)
i18n (0.6.4) i18n (0.6.4)
json (1.7.7) listen (1.2.2)
listen (1.1.2)
rb-fsevent (>= 0.9.3) rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9) rb-inotify (>= 0.9)
rb-kqueue (>= 0.2) rb-kqueue (>= 0.2)
log4r (1.1.10) log4r (1.1.10)
lumberjack (1.0.3) lumberjack (1.0.4)
method_source (0.8.1) method_source (0.8.1)
mime-types (1.23) mime-types (1.23)
multi_json (1.7.3) multi_json (1.7.7)
net-scp (1.1.1) net-scp (1.1.2)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (2.6.7) net-ssh (2.6.8)
pry (0.9.12.2) pry (0.9.12.2)
coderay (~> 1.0.5) coderay (~> 1.0.5)
method_source (~> 0.8) method_source (~> 0.8)
slop (~> 3.4) slop (~> 3.4)
rake (10.0.4) rake (10.1.0)
rb-fsevent (0.9.3) rb-fsevent (0.9.3)
rb-inotify (0.9.0) rb-inotify (0.9.0)
ffi (>= 0.5.0) ffi (>= 0.5.0)
@ -75,7 +85,7 @@ GEM
rspec-core (2.13.1) rspec-core (2.13.1)
rspec-expectations (2.13.0) rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
rspec-fire (1.1.3) rspec-fire (1.2.0)
rspec (~> 2.11) rspec (~> 2.11)
rspec-mocks (2.13.1) rspec-mocks (2.13.1)
rspec-spies (2.1.4) rspec-spies (2.1.4)
@ -86,7 +96,7 @@ GEM
simplecov-html (0.7.1) simplecov-html (0.7.1)
slop (3.4.5) slop (3.4.5)
thor (0.18.1) thor (0.18.1)
vagrant-cachier (0.0.6) vagrant-omnibus (1.1.0)
PLATFORMS PLATFORMS
ruby ruby
@ -97,9 +107,11 @@ DEPENDENCIES
guard-rspec guard-rspec
rake rake
rb-inotify rb-inotify
rspec rspec (~> 2.13.0)
rspec-fire rspec-fire
rspec-spies rspec-spies
vagrant! vagrant!
vagrant-cachier vagrant-cachier!
vagrant-lxc! vagrant-lxc!
vagrant-omnibus
vagrant-pristine!

View file

@ -12,7 +12,7 @@ to see the plugin in action and find out more about it.
## Features ## Features
* Vagrant's `up`, `halt`, `reload`, `destroy`, `ssh`, `provision` and `package` commands * Vagrant's `up`, `halt`, `reload`, `destroy`, `ssh`, `provision` and `package`
* Shared folders * Shared folders
* Provisioning with any built-in Vagrant provisioner * Provisioning with any built-in Vagrant provisioner
* Port forwarding * Port forwarding
@ -55,7 +55,7 @@ vagrant plugin install vagrant-lxc
After installing, add a [base box](#base-boxes) using any name you want, for example: After installing, add a [base box](#base-boxes) using any name you want, for example:
``` ```
vagrant box add quantal64 http://dl.dropbox.com/u/13510779/lxc-quantal-amd64-2013-05-08.box vagrant box add quantal64 http://dl.dropbox.com/u/13510779/lxc-quantal-amd64-2013-07-12.box
``` ```
Then create a Vagrantfile that looks like the following, changing the box name Then create a Vagrantfile that looks like the following, changing the box name
@ -99,9 +99,9 @@ For other configuration options, please check [lxc.conf manpages](http://manpage
### Base boxes ### Base boxes
Please check [the wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes)
Please check [the wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#v2-boxes) for a list of [pre built](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#available-boxes)
for a list of pre built base boxes and information on [how to build your own](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#building-your-own). base boxes and information on [how to build your own](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#building-your-own).
## Current limitations ## Current limitations

View file

@ -78,6 +78,8 @@ copy_configuration()
rootfs=$2 rootfs=$2
name=$3 name=$3
grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
# if there is exactly one veth network entry, make sure it has an # if there is exactly one veth network entry, make sure it has an
# associated hwaddr. # associated hwaddr.
nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l` nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`

View file

@ -3,7 +3,7 @@
require 'pathname' require 'pathname'
BASE_URL = 'http://dl.dropbox.com/u/13510779' BASE_URL = 'http://dl.dropbox.com/u/13510779'
LAST_RELEASE_DATE = '2013-05-08' LAST_RELEASE_DATE = '2013-07-12'
LOCAL_BOXES_PATH = Pathname('../boxes/output').expand_path LOCAL_BOXES_PATH = Pathname('../boxes/output').expand_path
def lxc_box_url(release_name) def lxc_box_url(release_name)
file_name = "lxc-#{release_name}-amd64-#{LAST_RELEASE_DATE}.box" file_name = "lxc-#{release_name}-amd64-#{LAST_RELEASE_DATE}.box"
@ -43,12 +43,14 @@ BOXES = {
Vagrant.require_plugin 'vagrant-lxc' Vagrant.require_plugin 'vagrant-lxc'
Vagrant.require_plugin 'vagrant-cachier' Vagrant.require_plugin 'vagrant-cachier'
Vagrant.require_plugin 'vagrant-pristine'
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root', nfs: true config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root', nfs: true
config.cache.scope = :machine config.cache.scope = :machine
config.cache.auto_detect = true config.cache.auto_detect = true
config.cache.enable_nfs = true
ip_suffix = 30 ip_suffix = 30
BOXES.each do |box_name, box_config| BOXES.each do |box_name, box_config|

21
example/Vagrantfile vendored
View file

@ -3,6 +3,7 @@
# Not really needed, but useful while developing so that vagrant picks it up # Not really needed, but useful while developing so that vagrant picks it up
Vagrant.require_plugin 'vagrant-lxc' Vagrant.require_plugin 'vagrant-lxc'
Vagrant.require_plugin 'vagrant-omnibus'
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.synced_folder "/tmp", "/vagrant_data" config.vm.synced_folder "/tmp", "/vagrant_data"
@ -22,21 +23,25 @@ echo "Hi there I'm a shell script used for provisioning"
puppet.manifest_file = "site.pp" puppet.manifest_file = "site.pp"
end end
config.vm.provision :chef_solo do |chef|
chef.add_recipe "hello-world"
chef.log_level = :debug
end
port = 8080 port = 8080
releases = %w(precise quantal raring wheezy squeeze sid) releases = %w(precise quantal raring wheezy squeeze sid)
releases.each do |release| releases.each do |release|
config.vm.define(release) do |lxc_config| config.vm.define(release) do |lxc_config|
lxc_config.vm.box = "#{release}64" lxc_config.vm.box = "#{release}64"
lxc_config.vm.box_url = "http://dl.dropbox.com/u/13510779/lxc-#{release}-amd64-2013-05-08.box" lxc_config.vm.box_url = "http://dl.dropbox.com/u/13510779/lxc-#{release}-amd64-2013-07-12.box"
lxc_config.vm.network :forwarded_port, guest: 80, host: (port += 1)
# Uncomment if you want to try out a box built locally # Uncomment if you want to try out a box built locally
# lxc_config.vm.box_url = "../boxes/output/lxc-#{release}64.box" # lxc_config.vm.box_url = "../boxes/output/lxc-#{release}-amd64-2013-07-12.box"
lxc_config.vm.network :forwarded_port, guest: 80, host: (port += 1)
lxc_config.vm.hostname = "lxc-#{release}64-example" lxc_config.vm.hostname = "lxc-#{release}64-example"
if %w(precise quantal raring squeeze).include? release
lxc_config.omnibus.chef_version = :latest
lxc_config.vm.provision :chef_solo do |chef|
chef.add_recipe "hello-world"
chef.log_level = :debug
end
end
end end
end end
end end

View file

@ -30,7 +30,7 @@ module Vagrant
end end
def rootfs_path def rootfs_path
Pathname.new(base_path.join('rootfs')) Pathname.new(base_path.join('config').read.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1])
end end
def create(name, template_path, config_file, template_options = {}) def create(name, template_path, config_file, template_options = {})
@ -65,7 +65,6 @@ module Vagrant
extra = ['-o', ENV['LXC_START_LOG_FILE'], '-l', 'DEBUG'] extra = ['-o', ENV['LXC_START_LOG_FILE'], '-l', 'DEBUG']
end end
customizations = customizations + @customizations customizations = customizations + @customizations
customizations += [['rootfs', rootfs_path.to_s]]
@cli.transition_to(:running) { |c| c.start(customizations, (extra || nil)) } @cli.transition_to(:running) { |c| c.start(customizations, (extra || nil)) }
end end

View file

@ -39,7 +39,7 @@ module Vagrant
end end
def state def state
if @name && run(:info, '--name', @name) =~ /^state:[^A-Z]+([A-Z]+)$/ if @name && run(:info, '--name', @name, retryable: true) =~ /^state:[^A-Z]+([A-Z]+)$/
$1.downcase.to_sym $1.downcase.to_sym
elsif @name elsif @name
:unknown :unknown

View file

@ -1,5 +1,5 @@
module Vagrant module Vagrant
module LXC module LXC
VERSION = "0.4.0.dev" VERSION = "0.4.0"
end end
end end

View file

@ -17,8 +17,12 @@ en:
force_shutdown: |- force_shutdown: |-
Forcing shutdown of container... Forcing shutdown of container...
# TODO: Review messages below
vagrant: vagrant:
commands:
status:
stopped: |-
The container is currently stopped. Run `vagrant up` to bring it up again.
actions: actions:
lxc: lxc:
compressing_rootfs: Compressing container's rootfs... compressing_rootfs: Compressing container's rootfs...

View file

@ -20,10 +20,7 @@ describe 'Sanity check' do
end end
it "is able to be SSH'ed" do it "is able to be SSH'ed" do
expected = 'lxc-test-box' expect(vagrant_ssh('hostname')).to eq 'lxc-test-box'
# HACK:
expected = ENV['BOX_NAME'].gsub(/64$/, '') if %w( squeeze64 wheezy64 sid64 ).include? ENV['BOX_NAME']
expect(vagrant_ssh('hostname')).to eq expected
end end
it 'mounts shared folders with the right permissions' do it 'mounts shared folders with the right permissions' do

View file

@ -1,11 +1,12 @@
require 'unit_helper' require 'unit_helper'
require 'tmpdir'
require 'vagrant-lxc/action/clear_forwarded_ports' require 'vagrant-lxc/action/clear_forwarded_ports'
describe Vagrant::LXC::Action::ClearForwardedPorts do describe Vagrant::LXC::Action::ClearForwardedPorts do
let(:app) { mock(:app, call: true) } let(:app) { double(:app, call: true) }
let(:env) { {machine: machine, ui: stub(info: true)} } let(:env) { {machine: machine, ui: double(info: true)} }
let(:machine) { mock(:machine, data_dir: data_dir) } let(:machine) { double(:machine, data_dir: data_dir) }
let!(:data_dir) { Pathname.new(Dir.mktmpdir) } let!(:data_dir) { Pathname.new(Dir.mktmpdir) }
let(:pids_dir) { data_dir.join('pids') } let(:pids_dir) { data_dir.join('pids') }
let(:pid) { 'a-pid' } let(:pid) { 'a-pid' }

View file

@ -3,11 +3,11 @@ require 'unit_helper'
require 'vagrant-lxc/action/compress_rootfs' require 'vagrant-lxc/action/compress_rootfs'
describe Vagrant::LXC::Action::CompressRootFS do describe Vagrant::LXC::Action::CompressRootFS do
let(:app) { mock(:app, call: true) } let(:app) { double(:app, call: true) }
let(:env) { {machine: machine, ui: stub(info: true)} } let(:env) { {machine: machine, ui: double(info: true)} }
let(:machine) { fire_double('Vagrant::Machine', provider: provider) } let(:machine) { instance_double('Vagrant::Machine', provider: provider) }
let(:provider) { fire_double('Vagrant::LXC::Provider', driver: driver) } let(:provider) { instance_double('Vagrant::LXC::Provider', driver: driver) }
let(:driver) { fire_double('Vagrant::LXC::Driver', compress_rootfs: compressed_rootfs_path) } let(:driver) { instance_double('Vagrant::LXC::Driver', compress_rootfs: compressed_rootfs_path) }
let(:compressed_rootfs_path) { '/path/to/rootfs.tar.gz' } let(:compressed_rootfs_path) { '/path/to/rootfs.tar.gz' }
subject { described_class.new(app, env) } subject { described_class.new(app, env) }

View file

@ -3,15 +3,15 @@ require 'unit_helper'
require 'vagrant-lxc/action/forward_ports' require 'vagrant-lxc/action/forward_ports'
describe Vagrant::LXC::Action::ForwardPorts do describe Vagrant::LXC::Action::ForwardPorts do
let(:app) { mock(:app, call: true) } let(:app) { double(:app, call: true) }
let(:env) { {machine: machine, ui: stub(info: true)} } let(:env) { {machine: machine, ui: double(info: true)} }
let(:machine) { mock(:machine) } let(:machine) { double(:machine) }
let!(:data_dir) { Pathname.new(Dir.mktmpdir) } let!(:data_dir) { Pathname.new(Dir.mktmpdir) }
let(:networks) { [[:other_config, {}], [:forwarded_port, {guest: guest_port, host: host_port}]] } let(:networks) { [[:other_config, {}], [:forwarded_port, {guest: guest_port, host: host_port}]] }
let(:host_port) { 8080 } let(:host_port) { 8080 }
let(:guest_port) { 80 } let(:guest_port) { 80 }
let(:provider) { fire_double('Vagrant::LXC::Provider', driver: driver) } let(:provider) { instance_double('Vagrant::LXC::Provider', driver: driver) }
let(:driver) { fire_double('Vagrant::LXC::Driver', assigned_ip: container_ip) } let(:driver) { instance_double('Vagrant::LXC::Driver', assigned_ip: container_ip) }
let(:container_ip) { '10.0.1.234' } let(:container_ip) { '10.0.1.234' }
let(:pid) { 'a-pid' } let(:pid) { 'a-pid' }

View file

@ -5,10 +5,10 @@ require 'vagrant-lxc/errors'
require 'vagrant-lxc/action/handle_box_metadata' require 'vagrant-lxc/action/handle_box_metadata'
describe Vagrant::LXC::Action::HandleBoxMetadata do describe Vagrant::LXC::Action::HandleBoxMetadata do
let(:app) { mock(:app, call: true) } let(:app) { double(:app, call: true) }
let(:env) { {machine: machine, ui: stub(info: true)} } let(:env) { {machine: machine, ui: double(info: true)} }
let(:machine) { mock(:machine, box: box) } let(:machine) { double(:machine, box: box) }
let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: box_directory) } let(:box) { double(:box, name: 'box-name', metadata: metadata, directory: box_directory) }
let(:box_directory) { Pathname.new('/path/to/box') } let(:box_directory) { Pathname.new('/path/to/box') }
let(:version) { '2' } let(:version) { '2' }
let(:metadata) { {'template-opts' => {'--foo' => 'bar'}, 'version' => version} } let(:metadata) { {'template-opts' => {'--foo' => 'bar'}, 'version' => version} }

View file

@ -3,11 +3,11 @@ require 'unit_helper'
require 'vagrant-lxc/action/setup_package_files' require 'vagrant-lxc/action/setup_package_files'
describe Vagrant::LXC::Action::SetupPackageFiles do describe Vagrant::LXC::Action::SetupPackageFiles do
let(:app) { mock(:app, call: true) } let(:app) { double(:app, call: true) }
let(:env) { {machine: machine, tmp_path: tmp_path, ui: stub(info: true), 'package.rootfs' => rootfs_path} } let(:env) { {machine: machine, tmp_path: tmp_path, ui: double(info: true), 'package.rootfs' => rootfs_path} }
let(:machine) { fire_double('Vagrant::Machine', box: box) } let(:machine) { instance_double('Vagrant::Machine', box: box) }
let!(:tmp_path) { Pathname.new(Dir.mktmpdir) } let!(:tmp_path) { Pathname.new(Dir.mktmpdir) }
let(:box) { fire_double('Vagrant::Box', directory: tmp_path.join('box')) } let(:box) { instance_double('Vagrant::Box', directory: tmp_path.join('box')) }
let(:rootfs_path) { tmp_path.join('rootfs-amd64.tar.gz') } let(:rootfs_path) { tmp_path.join('rootfs-amd64.tar.gz') }
subject { described_class.new(app, env) } subject { described_class.new(app, env) }

View file

@ -126,7 +126,7 @@ describe Vagrant::LXC::Driver::CLI do
it 'calls lxc-info with the right arguments' do it 'calls lxc-info with the right arguments' do
subject.state subject.state
subject.should have_received(:run).with(:info, '--name', name) subject.should have_received(:run).with(:info, '--name', name, retryable: true)
end end
it 'maps the output of lxc-info status out to a symbol' do it 'maps the output of lxc-info status out to a symbol' do

View file

@ -9,24 +9,24 @@ describe Vagrant::LXC::Driver do
let(:unknown_container) { described_class.new('unknown', cli) } let(:unknown_container) { described_class.new('unknown', cli) }
let(:valid_container) { described_class.new('valid', cli) } let(:valid_container) { described_class.new('valid', cli) }
let(:new_container) { described_class.new(nil) } let(:new_container) { described_class.new(nil) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', list: ['valid']) } let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', list: ['valid']) }
it 'raises a ContainerNotFound error if an unknown container name gets provided' do it 'raises a ContainerNotFound error if an unknown container name gets provided' do
expect { expect {
unknown_container.validate! unknown_container.validate!
}.to raise_error(Vagrant::LXC::Driver::ContainerNotFound) }.to raise_error
end end
it 'does not raise a ContainerNotFound error if a valid container name gets provided' do it 'does not raise a ContainerNotFound error if a valid container name gets provided' do
expect { expect {
valid_container.validate! valid_container.validate!
}.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound) }.not_to raise_error
end end
it 'does not raise a ContainerNotFound error if nil is provider as name' do it 'does not raise a ContainerNotFound error if nil is provider as name' do
expect { expect {
new_container.validate! new_container.validate!
}.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound) }.not_to raise_error
end end
end end
@ -37,7 +37,7 @@ describe Vagrant::LXC::Driver do
let(:template_opts) { {'--some' => 'random-option'} } let(:template_opts) { {'--some' => 'random-option'} }
let(:config_file) { '/path/to/lxc-config-from-box' } let(:config_file) { '/path/to/lxc-config-from-box' }
let(:rootfs_tarball) { '/path/to/cache/rootfs.tar.gz' } let(:rootfs_tarball) { '/path/to/cache/rootfs.tar.gz' }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', :create => true, :name= => true) } let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', :create => true, :name= => true) }
subject { described_class.new(nil, cli) } subject { described_class.new(nil, cli) }
@ -60,7 +60,7 @@ describe Vagrant::LXC::Driver do
end end
describe 'destruction' do describe 'destruction' do
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', destroy: true) } let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', destroy: true) }
subject { described_class.new('name', cli) } subject { described_class.new('name', cli) }
@ -74,8 +74,7 @@ describe Vagrant::LXC::Driver do
describe 'start' do describe 'start' do
let(:customizations) { [['a', '1'], ['b', '2']] } let(:customizations) { [['a', '1'], ['b', '2']] }
let(:internal_customization) { ['internal', 'customization'] } let(:internal_customization) { ['internal', 'customization'] }
let(:rootfs) { ['rootfs', subject.rootfs_path.to_s] } let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', start: true) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', start: true) }
subject { described_class.new('name', cli) } subject { described_class.new('name', cli) }
@ -86,7 +85,7 @@ describe Vagrant::LXC::Driver do
end end
it 'starts container with configured customizations' do it 'starts container with configured customizations' do
cli.should have_received(:start).with(customizations + [internal_customization, rootfs], nil) cli.should have_received(:start).with(customizations + [internal_customization], nil)
end end
it 'expects a transition to running state to take place' do it 'expects a transition to running state to take place' do
@ -95,7 +94,7 @@ describe Vagrant::LXC::Driver do
end end
describe 'halt' do describe 'halt' do
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', shutdown: true) } let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', shutdown: true) }
subject { described_class.new('name', cli) } subject { described_class.new('name', cli) }
@ -123,7 +122,7 @@ describe Vagrant::LXC::Driver do
describe 'state' do describe 'state' do
let(:cli_state) { :something } let(:cli_state) { :something }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', state: cli_state) } let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', state: cli_state) }
subject { described_class.new('name', cli) } subject { described_class.new('name', cli) }
@ -136,7 +135,7 @@ describe Vagrant::LXC::Driver do
# This ip is set on the sample-ip-addr-output fixture # This ip is set on the sample-ip-addr-output fixture
let(:ip) { "10.0.254.137" } let(:ip) { "10.0.254.137" }
let(:ifconfig_output) { File.read('spec/fixtures/sample-ip-addr-output') } let(:ifconfig_output) { File.read('spec/fixtures/sample-ip-addr-output') }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', :attach => ifconfig_output) } let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', :attach => ifconfig_output) }
subject { described_class.new('name', cli) } subject { described_class.new('name', cli) }

109
tasks/boxes.rake Normal file
View file

@ -0,0 +1,109 @@
require 'pathname'
require 'rake/tasklib'
load 'tasks/boxes.v2.rake'
class BuildGenericBoxTaskV3 < BuildGenericBoxTaskV2
def build
require 'vagrant'
check_if_box_has_been_built!
FileUtils.mkdir_p 'boxes/temp' unless File.exist? 'base/temp'
check_for_partially_built_box!
pwd = Dir.pwd
sh 'mkdir -p boxes/temp/'
Dir.chdir 'boxes/temp' do
download
install_cfg_engines
finalize
prepare_package_contents pwd
sh 'sudo rm -rf rootfs'
sh "tar -czf tmp-package.box ./*"
end
sh 'mkdir -p boxes/output'
sh "cp boxes/temp/tmp-package.box boxes/output/#{@file}"
sh "rm -rf boxes/temp"
end
def finalize
auth_key = Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s
run 'finalize', @arch, @release, auth_key
end
def prepare_package_contents(pwd)
run 'cleanup'
sh 'sudo rm -f rootfs.tar.gz'
sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
sh "sudo chown #{ENV['USER']}:#{`id -gn`.strip} rootfs.tar.gz"
sh "cp #{pwd}/boxes/common/lxc-template ."
sh "cp #{pwd}/boxes/common/lxc.conf ."
sh "cp #{pwd}/boxes/common/metadata.json ."
end
end
class BuildDebianBoxTaskV3 < BuildGenericBoxTaskV3
def initialize(name, release, arch, opts = {})
super(name, 'debian', release, arch, opts)
end
end
class BuildUbuntuBoxTaskV3 < BuildGenericBoxTaskV3
def initialize(name, release, arch, opts = {})
super(name, 'ubuntu', release, arch, opts)
end
end
puppet = ENV['PUPPET'] == '1'
babushka = ENV['BABUSHKA'] == '1'
namespace :boxes do
namespace :ubuntu do
namespace :build do
desc 'Build an Ubuntu Precise 64 bits box'
BuildUbuntuBoxTaskV3.
new(:precise64,
:precise, 'amd64', puppet: puppet, babushka: babushka)
desc 'Build an Ubuntu Quantal 64 bits box'
BuildUbuntuBoxTaskV3.
new(:quantal64,
:quantal, 'amd64', puppet: puppet, babushka: babushka)
desc 'Build an Ubuntu Raring 64 bits box'
BuildUbuntuBoxTaskV3.
new(:raring64,
:raring, 'amd64', puppet: puppet, babushka: babushka)
desc 'Build all Ubuntu boxes'
task :all => %w( precise64 quantal64 raring64 )
end
end
namespace :debian do
namespace :build do
desc 'Build an Debian Squeeze 64 bits box'
BuildDebianBoxTaskV3.
new(:squeeze64,
:squeeze, 'amd64', puppet: puppet, babushka: babushka)
desc 'Build an Debian Wheezy 64 bits box'
BuildDebianBoxTaskV3.
new(:wheezy64,
:wheezy, 'amd64', puppet: puppet, babushka: babushka)
desc 'Build an Debian Sid/unstable 64 bits box'
BuildDebianBoxTaskV3.
new(:sid64,
:sid, 'amd64', puppet: puppet, babushka: babushka)
desc 'Build all Debian boxes'
task :all => %w( squeeze64 wheezy64 sid64 )
end
end
desc 'Build all base boxes for release'
task :build_all => %w( ubuntu:build:all debian:build:all )
end

View file

@ -11,7 +11,7 @@ class BuildGenericBoxTaskV2 < ::Rake::TaskLib
@distrib = distrib @distrib = distrib
@release = release.to_s @release = release.to_s
@arch = arch.to_s @arch = arch.to_s
@install_chef = opts.fetch(:chef, true) @install_chef = opts.fetch(:chef, false)
@install_puppet = opts.fetch(:puppet, true) @install_puppet = opts.fetch(:puppet, true)
@install_babushka = opts.fetch(:babushka, true) @install_babushka = opts.fetch(:babushka, true)
@file = opts[:file] || default_box_file @file = opts[:file] || default_box_file

View file

@ -1,113 +0,0 @@
require 'pathname'
require 'rake/tasklib'
load 'tasks/boxes.v2.rake'
class BuildGenericBoxTaskV3 < BuildGenericBoxTaskV2
def build
check_if_box_has_been_built!
FileUtils.mkdir_p 'boxes/temp' unless File.exist? 'base/temp'
check_for_partially_built_box!
pwd = Dir.pwd
sh 'mkdir -p boxes/temp/'
Dir.chdir 'boxes/temp' do
download
install_cfg_engines
finalize
prepare_package_contents pwd
sh 'sudo rm -rf rootfs'
sh "tar -czf tmp-package.box ./*"
end
sh 'mkdir -p boxes/output'
sh "cp boxes/temp/tmp-package.box boxes/output/#{@file}"
sh "rm -rf boxes/temp"
end
def finalize
require 'vagrant'
auth_key = Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s
run 'finalize', @arch, @release, auth_key
end
def prepare_package_contents(pwd)
run 'cleanup'
sh 'sudo rm -f rootfs.tar.gz'
sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
sh "sudo chown #{ENV['USER']}:#{`id -gn`.strip} rootfs.tar.gz"
sh "cp #{pwd}/boxes/common/lxc-template ."
sh "cp #{pwd}/boxes/common/lxc.conf ."
sh "cp #{pwd}/boxes/common/metadata.json ."
end
end
class BuildDebianBoxTaskV3 < BuildGenericBoxTaskV3
def initialize(name, release, arch, opts = {})
super(name, 'debian', release, arch, opts)
end
end
class BuildUbuntuBoxTaskV3 < BuildGenericBoxTaskV3
def initialize(name, release, arch, opts = {})
super(name, 'ubuntu', release, arch, opts)
end
end
chef = ENV['CHEF'] == '1'
puppet = ENV['PUPPET'] == '1'
babushka = ENV['BABUSHKA'] == '1'
namespace :boxes do
namespace :v3 do
namespace :ubuntu do
namespace :build do
desc 'Build an Ubuntu Precise 64 bits box'
BuildUbuntuBoxTaskV3.
new(:precise64,
:precise, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
desc 'Build an Ubuntu Quantal 64 bits box'
BuildUbuntuBoxTaskV3.
new(:quantal64,
:quantal, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
# FIXME: Find out how to install chef on raring
desc 'Build an Ubuntu Raring 64 bits box'
BuildUbuntuBoxTaskV3.
new(:raring64,
:raring, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
desc 'Build all Ubuntu boxes'
task :all => %w( precise64 quantal64 raring64 )
end
end
# FIXME: Find out how to install chef on debian boxes
namespace :debian do
namespace :build do
desc 'Build an Debian Squeeze 64 bits box'
BuildDebianBoxTaskV3.
new(:squeeze64,
:squeeze, 'amd64', chef: false, puppet: puppet, babushka: babushka)
desc 'Build an Debian Wheezy 64 bits box'
BuildDebianBoxTaskV3.
new(:wheezy64,
:wheezy, 'amd64', chef: false, puppet: puppet, babushka: babushka)
desc 'Build an Debian Sid/unstable 64 bits box'
BuildDebianBoxTaskV3.
new(:sid64,
:sid, 'amd64', chef: false, puppet: puppet, babushka: babushka)
desc 'Build all Debian boxes'
task :all => %w( squeeze64 wheezy64 sid64 )
end
end
desc 'Build all base boxes for release'
task :build_all => %w( ubuntu:build:all debian:build:all )
end
end