diff --git a/CHANGELOG.md b/CHANGELOG.md index aac93f5..fa51ca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,12 @@ FEATURES: - - Enable Chef for Ubuntu Raring base box - New box format [#89](https://github.com/fgrehm/vagrant-lxc/issues/89) 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) - 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) diff --git a/Gemfile b/Gemfile index e33d5a4..4601dc1 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,10 @@ source 'https://rubygems.org' gemspec 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', git: 'https://github.com/mitchellh/vagrant.git' - gem 'vagrant-cachier' + gem 'vagrant', github: 'mitchellh/vagrant' + gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier' + gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine' + gem 'vagrant-omnibus' gem 'guard' gem 'guard-rspec' gem 'rb-inotify' @@ -14,7 +15,7 @@ end group :development, :test do gem 'rake' - gem 'rspec' + gem 'rspec', '~> 2.13.0' gem 'rspec-fire', require: 'rspec/fire' gem 'rspec-spies', require: false gem 'coveralls', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 3c3c263..0c16a12 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,23 @@ GIT - remote: https://github.com/mitchellh/vagrant.git - revision: ccfd321ef98dc5c12b180cc3a26f12d870c0eff5 + remote: git://github.com/fgrehm/vagrant-cachier.git + revision: ae6cb5bcfbdbb2157867d77ded8f2b6f430c0f6c 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) erubis (~> 2.7.0) i18n (~> 0.6.0) - json (>= 1.5.1, < 1.8.0) log4r (~> 1.1.9) net-scp (~> 1.1.0) net-ssh (~> 2.6.6) @@ -14,7 +25,7 @@ GIT PATH remote: . specs: - vagrant-lxc (0.4.0.dev) + vagrant-lxc (0.4.0) GEM remote: https://rubygems.org/ @@ -31,36 +42,35 @@ GEM thor diff-lcs (1.2.4) erubis (2.7.0) - ffi (1.8.1) + ffi (1.9.0) formatador (0.2.4) - guard (1.8.0) + guard (1.8.1) formatador (>= 0.2.4) listen (>= 1.0.0) lumberjack (>= 1.0.2) pry (>= 0.9.10) thor (>= 0.14.6) - guard-rspec (3.0.0) + guard-rspec (3.0.2) guard (>= 1.8) rspec (~> 2.13) i18n (0.6.4) - json (1.7.7) - listen (1.1.2) + listen (1.2.2) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) rb-kqueue (>= 0.2) log4r (1.1.10) - lumberjack (1.0.3) + lumberjack (1.0.4) method_source (0.8.1) mime-types (1.23) - multi_json (1.7.3) - net-scp (1.1.1) + multi_json (1.7.7) + net-scp (1.1.2) net-ssh (>= 2.6.5) - net-ssh (2.6.7) + net-ssh (2.6.8) pry (0.9.12.2) coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) - rake (10.0.4) + rake (10.1.0) rb-fsevent (0.9.3) rb-inotify (0.9.0) ffi (>= 0.5.0) @@ -75,7 +85,7 @@ GEM rspec-core (2.13.1) rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) - rspec-fire (1.1.3) + rspec-fire (1.2.0) rspec (~> 2.11) rspec-mocks (2.13.1) rspec-spies (2.1.4) @@ -86,7 +96,7 @@ GEM simplecov-html (0.7.1) slop (3.4.5) thor (0.18.1) - vagrant-cachier (0.0.6) + vagrant-omnibus (1.1.0) PLATFORMS ruby @@ -97,9 +107,11 @@ DEPENDENCIES guard-rspec rake rb-inotify - rspec + rspec (~> 2.13.0) rspec-fire rspec-spies vagrant! - vagrant-cachier + vagrant-cachier! vagrant-lxc! + vagrant-omnibus + vagrant-pristine! diff --git a/README.md b/README.md index 7d7c308..df881a1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ to see the plugin in action and find out more about it. ## Features -* Vagrant's `up`, `halt`, `reload`, `destroy`, `ssh`, `provision` and `package` commands +* Vagrant's `up`, `halt`, `reload`, `destroy`, `ssh`, `provision` and `package` * Shared folders * Provisioning with any built-in Vagrant provisioner * 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: ``` -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 @@ -99,9 +99,9 @@ For other configuration options, please check [lxc.conf manpages](http://manpage ### Base boxes - -Please check [the wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#v2-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). +Please check [the wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes) +for a list of [pre built](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#available-boxes) +base boxes and information on [how to build your own](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#building-your-own). ## Current limitations diff --git a/boxes/common/lxc-template b/boxes/common/lxc-template index cf44ee3..9e53be4 100755 --- a/boxes/common/lxc-template +++ b/boxes/common/lxc-template @@ -78,6 +78,8 @@ copy_configuration() rootfs=$2 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 # associated hwaddr. nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l` diff --git a/development/Vagrantfile b/development/Vagrantfile index 03ab7a1..b4df960 100644 --- a/development/Vagrantfile +++ b/development/Vagrantfile @@ -3,7 +3,7 @@ require 'pathname' 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 def lxc_box_url(release_name) file_name = "lxc-#{release_name}-amd64-#{LAST_RELEASE_DATE}.box" @@ -43,12 +43,14 @@ BOXES = { Vagrant.require_plugin 'vagrant-lxc' Vagrant.require_plugin 'vagrant-cachier' +Vagrant.require_plugin 'vagrant-pristine' Vagrant.configure("2") do |config| config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root', nfs: true config.cache.scope = :machine config.cache.auto_detect = true + config.cache.enable_nfs = true ip_suffix = 30 BOXES.each do |box_name, box_config| diff --git a/example/Vagrantfile b/example/Vagrantfile index faf8564..179bbed 100644 --- a/example/Vagrantfile +++ b/example/Vagrantfile @@ -3,6 +3,7 @@ # Not really needed, but useful while developing so that vagrant picks it up Vagrant.require_plugin 'vagrant-lxc' +Vagrant.require_plugin 'vagrant-omnibus' Vagrant.configure("2") do |config| 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" end - config.vm.provision :chef_solo do |chef| - chef.add_recipe "hello-world" - chef.log_level = :debug - end - port = 8080 releases = %w(precise quantal raring wheezy squeeze sid) releases.each do |release| config.vm.define(release) do |lxc_config| 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.network :forwarded_port, guest: 80, host: (port += 1) + lxc_config.vm.box_url = "http://dl.dropbox.com/u/13510779/lxc-#{release}-amd64-2013-07-12.box" # 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" + + 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 diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index c9f5388..0a46194 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -30,7 +30,7 @@ module Vagrant end def rootfs_path - Pathname.new(base_path.join('rootfs')) + Pathname.new(base_path.join('config').read.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1]) end def create(name, template_path, config_file, template_options = {}) @@ -65,7 +65,6 @@ module Vagrant extra = ['-o', ENV['LXC_START_LOG_FILE'], '-l', 'DEBUG'] end customizations = customizations + @customizations - customizations += [['rootfs', rootfs_path.to_s]] @cli.transition_to(:running) { |c| c.start(customizations, (extra || nil)) } end diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index 133a828..b7ed4fe 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -39,7 +39,7 @@ module Vagrant end 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 elsif @name :unknown diff --git a/lib/vagrant-lxc/version.rb b/lib/vagrant-lxc/version.rb index 7c00fe1..019be6a 100644 --- a/lib/vagrant-lxc/version.rb +++ b/lib/vagrant-lxc/version.rb @@ -1,5 +1,5 @@ module Vagrant module LXC - VERSION = "0.4.0.dev" + VERSION = "0.4.0" end end diff --git a/locales/en.yml b/locales/en.yml index 50edd3d..fcb8819 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -17,8 +17,12 @@ en: force_shutdown: |- Forcing shutdown of container... - # TODO: Review messages below vagrant: + commands: + status: + stopped: |- + The container is currently stopped. Run `vagrant up` to bring it up again. + actions: lxc: compressing_rootfs: Compressing container's rootfs... diff --git a/spec/acceptance/sanity_check_spec.rb b/spec/acceptance/sanity_check_spec.rb index b67987e..77b07b0 100644 --- a/spec/acceptance/sanity_check_spec.rb +++ b/spec/acceptance/sanity_check_spec.rb @@ -20,10 +20,7 @@ describe 'Sanity check' do end it "is able to be SSH'ed" do - expected = '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 + expect(vagrant_ssh('hostname')).to eq 'lxc-test-box' end it 'mounts shared folders with the right permissions' do diff --git a/spec/unit/action/clear_forwarded_ports_spec.rb b/spec/unit/action/clear_forwarded_ports_spec.rb index c111032..97a5f3a 100644 --- a/spec/unit/action/clear_forwarded_ports_spec.rb +++ b/spec/unit/action/clear_forwarded_ports_spec.rb @@ -1,11 +1,12 @@ require 'unit_helper' +require 'tmpdir' require 'vagrant-lxc/action/clear_forwarded_ports' describe Vagrant::LXC::Action::ClearForwardedPorts do - let(:app) { mock(:app, call: true) } - let(:env) { {machine: machine, ui: stub(info: true)} } - let(:machine) { mock(:machine, data_dir: data_dir) } + let(:app) { double(:app, call: true) } + let(:env) { {machine: machine, ui: double(info: true)} } + let(:machine) { double(:machine, data_dir: data_dir) } let!(:data_dir) { Pathname.new(Dir.mktmpdir) } let(:pids_dir) { data_dir.join('pids') } let(:pid) { 'a-pid' } diff --git a/spec/unit/action/compress_rootfs_spec.rb b/spec/unit/action/compress_rootfs_spec.rb index bedc9c5..2a70ba4 100644 --- a/spec/unit/action/compress_rootfs_spec.rb +++ b/spec/unit/action/compress_rootfs_spec.rb @@ -3,11 +3,11 @@ require 'unit_helper' require 'vagrant-lxc/action/compress_rootfs' describe Vagrant::LXC::Action::CompressRootFS do - let(:app) { mock(:app, call: true) } - let(:env) { {machine: machine, ui: stub(info: true)} } - let(:machine) { fire_double('Vagrant::Machine', provider: provider) } - let(:provider) { fire_double('Vagrant::LXC::Provider', driver: driver) } - let(:driver) { fire_double('Vagrant::LXC::Driver', compress_rootfs: compressed_rootfs_path) } + let(:app) { double(:app, call: true) } + let(:env) { {machine: machine, ui: double(info: true)} } + let(:machine) { instance_double('Vagrant::Machine', provider: provider) } + let(:provider) { instance_double('Vagrant::LXC::Provider', driver: driver) } + let(:driver) { instance_double('Vagrant::LXC::Driver', compress_rootfs: compressed_rootfs_path) } let(:compressed_rootfs_path) { '/path/to/rootfs.tar.gz' } subject { described_class.new(app, env) } diff --git a/spec/unit/action/forward_ports_spec.rb b/spec/unit/action/forward_ports_spec.rb index 4c31edc..c9c6c70 100644 --- a/spec/unit/action/forward_ports_spec.rb +++ b/spec/unit/action/forward_ports_spec.rb @@ -3,15 +3,15 @@ require 'unit_helper' require 'vagrant-lxc/action/forward_ports' describe Vagrant::LXC::Action::ForwardPorts do - let(:app) { mock(:app, call: true) } - let(:env) { {machine: machine, ui: stub(info: true)} } - let(:machine) { mock(:machine) } + let(:app) { double(:app, call: true) } + let(:env) { {machine: machine, ui: double(info: true)} } + let(:machine) { double(:machine) } let!(:data_dir) { Pathname.new(Dir.mktmpdir) } let(:networks) { [[:other_config, {}], [:forwarded_port, {guest: guest_port, host: host_port}]] } let(:host_port) { 8080 } let(:guest_port) { 80 } - let(:provider) { fire_double('Vagrant::LXC::Provider', driver: driver) } - let(:driver) { fire_double('Vagrant::LXC::Driver', assigned_ip: container_ip) } + let(:provider) { instance_double('Vagrant::LXC::Provider', driver: driver) } + let(:driver) { instance_double('Vagrant::LXC::Driver', assigned_ip: container_ip) } let(:container_ip) { '10.0.1.234' } let(:pid) { 'a-pid' } diff --git a/spec/unit/action/handle_box_metadata_spec.rb b/spec/unit/action/handle_box_metadata_spec.rb index 578fbf9..973948b 100644 --- a/spec/unit/action/handle_box_metadata_spec.rb +++ b/spec/unit/action/handle_box_metadata_spec.rb @@ -5,10 +5,10 @@ require 'vagrant-lxc/errors' require 'vagrant-lxc/action/handle_box_metadata' describe Vagrant::LXC::Action::HandleBoxMetadata do - let(:app) { mock(:app, call: true) } - let(:env) { {machine: machine, ui: stub(info: true)} } - let(:machine) { mock(:machine, box: box) } - let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: box_directory) } + let(:app) { double(:app, call: true) } + let(:env) { {machine: machine, ui: double(info: true)} } + let(:machine) { double(:machine, box: box) } + let(:box) { double(:box, name: 'box-name', metadata: metadata, directory: box_directory) } let(:box_directory) { Pathname.new('/path/to/box') } let(:version) { '2' } let(:metadata) { {'template-opts' => {'--foo' => 'bar'}, 'version' => version} } diff --git a/spec/unit/action/setup_package_files_spec.rb b/spec/unit/action/setup_package_files_spec.rb index c5a4c7b..6c1c042 100644 --- a/spec/unit/action/setup_package_files_spec.rb +++ b/spec/unit/action/setup_package_files_spec.rb @@ -3,11 +3,11 @@ require 'unit_helper' require 'vagrant-lxc/action/setup_package_files' describe Vagrant::LXC::Action::SetupPackageFiles do - let(:app) { mock(:app, call: true) } - let(:env) { {machine: machine, tmp_path: tmp_path, ui: stub(info: true), 'package.rootfs' => rootfs_path} } - let(:machine) { fire_double('Vagrant::Machine', box: box) } + let(:app) { double(:app, call: true) } + let(:env) { {machine: machine, tmp_path: tmp_path, ui: double(info: true), 'package.rootfs' => rootfs_path} } + let(:machine) { instance_double('Vagrant::Machine', box: box) } 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') } subject { described_class.new(app, env) } diff --git a/spec/unit/driver/cli_spec.rb b/spec/unit/driver/cli_spec.rb index 3498b6a..5080fb2 100644 --- a/spec/unit/driver/cli_spec.rb +++ b/spec/unit/driver/cli_spec.rb @@ -126,7 +126,7 @@ describe Vagrant::LXC::Driver::CLI do it 'calls lxc-info with the right arguments' do subject.state - subject.should have_received(:run).with(:info, '--name', name) + subject.should have_received(:run).with(:info, '--name', name, retryable: true) end it 'maps the output of lxc-info status out to a symbol' do diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index f657648..f13dd34 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -9,24 +9,24 @@ describe Vagrant::LXC::Driver do let(:unknown_container) { described_class.new('unknown', cli) } let(:valid_container) { described_class.new('valid', cli) } 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 expect { unknown_container.validate! - }.to raise_error(Vagrant::LXC::Driver::ContainerNotFound) + }.to raise_error end it 'does not raise a ContainerNotFound error if a valid container name gets provided' do expect { valid_container.validate! - }.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound) + }.not_to raise_error end it 'does not raise a ContainerNotFound error if nil is provider as name' do expect { new_container.validate! - }.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound) + }.not_to raise_error end end @@ -37,7 +37,7 @@ describe Vagrant::LXC::Driver do let(:template_opts) { {'--some' => 'random-option'} } let(:config_file) { '/path/to/lxc-config-from-box' } 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) } @@ -60,7 +60,7 @@ describe Vagrant::LXC::Driver do end 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) } @@ -74,8 +74,7 @@ describe Vagrant::LXC::Driver do describe 'start' do let(:customizations) { [['a', '1'], ['b', '2']] } let(:internal_customization) { ['internal', 'customization'] } - let(:rootfs) { ['rootfs', subject.rootfs_path.to_s] } - let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', start: true) } + let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', start: true) } subject { described_class.new('name', cli) } @@ -86,7 +85,7 @@ describe Vagrant::LXC::Driver do end 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 it 'expects a transition to running state to take place' do @@ -95,7 +94,7 @@ describe Vagrant::LXC::Driver do end 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) } @@ -123,7 +122,7 @@ describe Vagrant::LXC::Driver do describe 'state' do 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) } @@ -136,7 +135,7 @@ describe Vagrant::LXC::Driver do # This ip is set on the sample-ip-addr-output fixture let(:ip) { "10.0.254.137" } 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) } diff --git a/tasks/boxes.rake b/tasks/boxes.rake new file mode 100644 index 0000000..c760444 --- /dev/null +++ b/tasks/boxes.rake @@ -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 diff --git a/tasks/boxes.v2.rake b/tasks/boxes.v2.rake index 147161d..d2cf433 100644 --- a/tasks/boxes.v2.rake +++ b/tasks/boxes.v2.rake @@ -11,7 +11,7 @@ class BuildGenericBoxTaskV2 < ::Rake::TaskLib @distrib = distrib @release = release.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_babushka = opts.fetch(:babushka, true) @file = opts[:file] || default_box_file diff --git a/tasks/boxes.v3.rake b/tasks/boxes.v3.rake deleted file mode 100644 index bc094dc..0000000 --- a/tasks/boxes.v3.rake +++ /dev/null @@ -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